Statistics
| Branch: | Revision:

iof-bird-daemon / lib / ipv6.h @ 294c182e

History | View | Annotate | Download (1.66 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_IPV6_H_
10
#define _BIRD_IPV6_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
#define STD_ADDRESS_P_LENGTH 39
27

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

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

    
52
ip_addr ipv6_mkmask(unsigned);
53
unsigned ipv6_mklen(ip_addr *);
54
int ipv6_classify(ip_addr *);
55
void ipv6_hton(ip_addr *);
56
void ipv6_ntoh(ip_addr *);
57

    
58
/* FIXME: Is this hash function uniformly distributed over standard routing tables? */
59
static inline unsigned ipv6_hash(ip_addr *a)
60
{
61
  u32 x = _I0(*a) ^ _I1(*a) ^ _I2(*a) ^ _I3(*a);
62
  return (x ^ (x >> 16) ^ (x >> 8)) & 0xffff;
63
}
64

    
65
#endif