Statistics
| Branch: | Revision:

iof-bird-daemon / lib / ipv6.h @ 25697773

History | View | Annotate | Download (1.51 KB)

1
/*
2
 *        BIRD -- IP Addresses et Cetera for IPv6
3
 *
4
 *        (c) 1998 Martin Mares <mj@ucw.cz>
5
 *
6
 *        Can be freely distributed and used under the terms of the GNU GPL.
7
 */
8

    
9
#ifndef _BIRD_IPV4_H_
10
#define _BIRD_IPV4_H_
11

    
12
#include <netinet/in.h>
13
#include <string.h>
14

    
15
typedef struct ipv4_addr {
16
  u32 addr[4];
17
} ip_addr;
18

    
19
#define _MI(a,b,c,d) ((struct ip_addr) { a, b, c, d })
20
#define _I0(a) ((a).addr[0])
21
#define _I1(a) ((a).addr[1])
22
#define _I2(a) ((a).addr[2])
23
#define _I3(a) ((a).addr[3])
24

    
25
#define BITS_PER_IP_ADDRESS 128
26

    
27
#define IPA_NONE _MI(0,0,0,0)
28

    
29
#define ipa_equal(x,y) (!memcmp(&(x),&(y),sizeof(ip_addr)))
30
#define ipa_nonzero(x) (_I0(a) || _I1(a) || _I2(a) || _I3(a))
31
#define ipa_and(a,b) _MI(_I0(a) & _I0(b), \
32
                         _I1(a) & _I1(b), \
33
                         _I2(a) & _I2(b), \
34
                         _I3(a) & _I3(b))
35
#define ipa_or(a,b) _MI(_I0(a) | _I0(b), \
36
                        _I1(a) | _I1(b), \
37
                        _I2(a) | _I2(b), \
38
                        _I3(a) | _I3(b))
39
#define ipa_not(a) _MI(~_I0(a),~_I1(a),~_I2(a),~_I3(a))
40
#define ipa_mkmask(x) ipv6_mkmask(x)
41
#define ipa_mklen(x) ipv6_mklen(&(x))
42
#define ipa_hash(x) ipv6_hash(&(x))
43
#define ipa_hton(x) ipv6_hton(&(x))
44
#define ipa_ntoh(x) ipv6_ntoh(&(x))
45
#define ipa_classify(x) ipv6_classify(&(x))
46

    
47
ip_addr ipv6_mkmask(unsigned);
48
unsigned ipv6_mklen(ip_addr *);
49
int ipv6_classify(ip_addr *);
50
void ipv6_hton(ip_addr *);
51
void ipv6_ntoh(ip_addr *);
52

    
53
/* FIXME: Is this hash function uniformly distributed over standard routing tables? */
54
static inline unsigned ipv6_hash(ip_addr *a)
55
{
56
  u32 x = _I0(*a) ^ _I1(*a) ^ _I2(*a) ^ _I3(*a);
57
  return x ^ (x >> 16) ^ (x >> 8);
58
}
59

    
60
#endif