Revision 18c8241a lib/ipv4.h
lib/ipv4.h | ||
---|---|---|
11 | 11 |
|
12 | 12 |
#include <netinet/in.h> |
13 | 13 |
|
14 |
#include "lib/bitops.h" |
|
15 |
|
|
16 |
#ifdef DEBUG |
|
17 |
|
|
18 |
/* |
|
19 |
* Use the structural representation when you want to make sure |
|
20 |
* nobody unauthorized attempts to handle ip_addr as number. |
|
21 |
*/ |
|
22 |
|
|
14 | 23 |
typedef struct ipv4_addr { |
15 | 24 |
u32 addr; |
16 | 25 |
} ip_addr; |
... | ... | |
18 | 27 |
#define _I(x) (x).addr |
19 | 28 |
#define _MI(x) ((struct ip_addr) { x }) |
20 | 29 |
|
30 |
#else |
|
31 |
|
|
32 |
typedef u32 ip_addr; |
|
33 |
|
|
34 |
#define _I(x) (x) |
|
35 |
#define _MI(x) (x) |
|
36 |
|
|
37 |
#endif |
|
38 |
|
|
21 | 39 |
#define IPA_NONE (_MI(0)) |
22 | 40 |
|
23 | 41 |
#define ipa_equal(x,y) (_I(x) == _I(y)) |
42 |
#define ipa_nonzero(x) _I(x) |
|
24 | 43 |
#define ipa_and(x,y) _MI(_I(x) & _I(y)) |
25 | 44 |
#define ipa_or(x,y) _MI(_I(x) | _I(y)) |
26 | 45 |
#define ipa_not(x) _MI(~_I(x)) |
27 |
#define ipa_mkmask(x) _MI(ipv4_mkmask(x)) |
|
28 |
#define ipa_mklen(x) ipv4_mklen(_I(x)) |
|
46 |
#define ipa_mkmask(x) _MI(u32_mkmask(x)) |
|
47 |
#define ipa_mklen(x) u32_masklen(_I(x)) |
|
48 |
#define ipa_hash(x) ipv4_hash(_I(x)) |
|
49 |
#define ipa_hton(x) x = _MI(htonl(_I(x))) |
|
50 |
#define ipa_ntoh(x) x = _MI(ntohl(_I(x))) |
|
51 |
#define ipa_classify(x) ipv4_classify(_I(x)) |
|
29 | 52 |
|
30 | 53 |
unsigned ipv4_mklen(u32); |
31 | 54 |
u32 ipv4_mkmask(unsigned); |
55 |
int ipv4_classify(u32); |
|
32 | 56 |
|
33 |
/* ??? htonl and ntohl ??? */ |
|
57 |
/* FIXME: Is this hash function uniformly distributed over standard routing tables? */ |
|
58 |
static inline unsigned ipv4_hash(u32 a) |
|
59 |
{ |
|
60 |
return a ^ (a >> 16) ^ (a >> 24); |
|
61 |
} |
|
34 | 62 |
|
35 | 63 |
#endif |
Also available in: Unified diff