summaryrefslogtreecommitdiffstats
path: root/lib/ipv6.h
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>1999-08-03 21:36:06 +0200
committerMartin Mares <mj@ucw.cz>1999-08-03 21:36:06 +0200
commitdce267832a0468ed5e596f0b0733b926af7ead3a (patch)
tree76de529a85a81b12bd04ed150db208b76b0b17b1 /lib/ipv6.h
parent707ef833783ef731c56baae1c0dc7b7a9e7321ff (diff)
downloadbird-dce267832a0468ed5e596f0b0733b926af7ead3a.tar
bird-dce267832a0468ed5e596f0b0733b926af7ead3a.zip
Basic support for IPv6. The system-dependent part doesn't work yet,
but the core routines are there and seem to be working. o lib/ipv6.[ch] written o Lexical analyser recognizes IPv6 addresses and when in IPv6 mode, treats pure IPv4 addresses as router IDs. o Router ID must be configured manually on IPv6 systems. o Added SCOPE_ORGANIZATION for org-scoped IPv6 multicasts. o Fixed few places where ipa_(hton|ntoh) was called as a function returning converted address.
Diffstat (limited to 'lib/ipv6.h')
-rw-r--r--lib/ipv6.h46
1 files changed, 29 insertions, 17 deletions
diff --git a/lib/ipv6.h b/lib/ipv6.h
index 35d8e29..59005f9 100644
--- a/lib/ipv6.h
+++ b/lib/ipv6.h
@@ -1,7 +1,7 @@
/*
* BIRD -- IP Addresses et Cetera for IPv6
*
- * (c) 1998 Martin Mares <mj@ucw.cz>
+ * (c) 1999 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
@@ -12,11 +12,11 @@
#include <netinet/in.h>
#include <string.h>
-typedef struct ipv4_addr {
+typedef struct ipv6_addr {
u32 addr[4];
} ip_addr;
-#define _MI(a,b,c,d) ((struct ip_addr) { a, b, c, d })
+#define _MI(a,b,c,d) ((struct ipv6_addr) {{ a, b, c, d }})
#define _I0(a) ((a).addr[0])
#define _I1(a) ((a).addr[1])
#define _I2(a) ((a).addr[2])
@@ -28,38 +28,50 @@ typedef struct ipv4_addr {
#define IPA_NONE _MI(0,0,0,0)
#define ipa_equal(x,y) (!memcmp(&(x),&(y),sizeof(ip_addr)))
-#define ipa_nonzero(x) (_I0(a) || _I1(a) || _I2(a) || _I3(a))
-#define ipa_and(a,b) _MI(_I0(a) & _I0(b), \
- _I1(a) & _I1(b), \
- _I2(a) & _I2(b), \
- _I3(a) & _I3(b))
-#define ipa_or(a,b) _MI(_I0(a) | _I0(b), \
- _I1(a) | _I1(b), \
- _I2(a) | _I2(b), \
- _I3(a) | _I3(b))
-#define ipa_xor(a,b) _MI(_I0(a) ^ _I0(b), \
- _I1(a) ^ _I1(b), \
- _I2(a) ^ _I2(b), \
- _I3(a) ^ _I3(b))
-#define ipa_not(a) _MI(~_I0(a),~_I1(a),~_I2(a),~_I3(a))
+#define ipa_nonzero(x) ({ ip_addr _a=(x); (_I0(_a) || _I1(_a) || _I2(_a) || _I3(_a)); })
+#define ipa_and(x,y) ({ ip_addr _a=(x), _b=(y); \
+ _MI(_I0(_a) & _I0(_b), \
+ _I1(_a) & _I1(_b), \
+ _I2(_a) & _I2(_b), \
+ _I3(_a) & _I3(_b)); })
+#define ipa_or(x,y) ({ ip_addr _a=(x), _b=(y); \
+ _MI(_I0(_a) | _I0(_b), \
+ _I1(_a) | _I1(_b), \
+ _I2(_a) | _I2(_b), \
+ _I3(_a) | _I3(_b)); })
+#define ipa_xor(x,y) ({ ip_addr _a=(x), _b=(y); \
+ _MI(_I0(_a) ^ _I0(_b), \
+ _I1(_a) ^ _I1(_b), \
+ _I2(_a) ^ _I2(_b), \
+ _I3(_a) ^ _I3(_b)); })
+#define ipa_not(x) ({ ip_addr _a=(x); _MI(~_I0(_a),~_I1(_a),~_I2(_a),~_I3(_a)); })
#define ipa_mkmask(x) ipv6_mkmask(x)
#define ipa_mklen(x) ipv6_mklen(&(x))
#define ipa_hash(x) ipv6_hash(&(x))
#define ipa_hton(x) ipv6_hton(&(x))
#define ipa_ntoh(x) ipv6_ntoh(&(x))
#define ipa_classify(x) ipv6_classify(&(x))
+/* ipa_opposite and ipa_class_mask don't make sense with IPv6 */
+/* ipa_from_u32 and ipa_to_u32 replaced by ipa_build */
+#define ipa_build(a,b,c,d) _MI(a,b,c,d)
+#define ipa_compare(x,y) ipv6_compare(&x,&y)
ip_addr ipv6_mkmask(unsigned);
unsigned ipv6_mklen(ip_addr *);
int ipv6_classify(ip_addr *);
void ipv6_hton(ip_addr *);
void ipv6_ntoh(ip_addr *);
+int ipv6_compare(ip_addr *, ip_addr *);
+int ipv4_pton_u32(char *, u32 *);
/* FIXME: Is this hash function uniformly distributed over standard routing tables? */
static inline unsigned ipv6_hash(ip_addr *a)
{
+ /* Returns a 16-bit hash key */
u32 x = _I0(*a) ^ _I1(*a) ^ _I2(*a) ^ _I3(*a);
return (x ^ (x >> 16) ^ (x >> 8)) & 0xffff;
}
+#define IP_PREC_INTERNET_CONTROL 0 /* FIXME: What's the right value? */
+
#endif