summaryrefslogtreecommitdiffstats
path: root/lib/ipv4.h
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>1998-05-03 18:43:39 +0200
committerMartin Mares <mj@ucw.cz>1998-05-03 18:43:39 +0200
commit18c8241a91bd9208879666f1a1a13f454e66d75b (patch)
tree8bdc5f3e384b6b9198d5ab834d869c8d1fb261a7 /lib/ipv4.h
parenta8b6038225d18155883e330c96b2bc2e44153e1e (diff)
downloadbird-18c8241a91bd9208879666f1a1a13f454e66d75b.tar
bird-18c8241a91bd9208879666f1a1a13f454e66d75b.zip
BIRD library: The story continues.
Complete resource manages and IP address handling.
Diffstat (limited to 'lib/ipv4.h')
-rw-r--r--lib/ipv4.h34
1 files changed, 31 insertions, 3 deletions
diff --git a/lib/ipv4.h b/lib/ipv4.h
index 4b8c44c..fa8a27b 100644
--- a/lib/ipv4.h
+++ b/lib/ipv4.h
@@ -11,6 +11,15 @@
#include <netinet/in.h>
+#include "lib/bitops.h"
+
+#ifdef DEBUG
+
+/*
+ * Use the structural representation when you want to make sure
+ * nobody unauthorized attempts to handle ip_addr as number.
+ */
+
typedef struct ipv4_addr {
u32 addr;
} ip_addr;
@@ -18,18 +27,37 @@ typedef struct ipv4_addr {
#define _I(x) (x).addr
#define _MI(x) ((struct ip_addr) { x })
+#else
+
+typedef u32 ip_addr;
+
+#define _I(x) (x)
+#define _MI(x) (x)
+
+#endif
+
#define IPA_NONE (_MI(0))
#define ipa_equal(x,y) (_I(x) == _I(y))
+#define ipa_nonzero(x) _I(x)
#define ipa_and(x,y) _MI(_I(x) & _I(y))
#define ipa_or(x,y) _MI(_I(x) | _I(y))
#define ipa_not(x) _MI(~_I(x))
-#define ipa_mkmask(x) _MI(ipv4_mkmask(x))
-#define ipa_mklen(x) ipv4_mklen(_I(x))
+#define ipa_mkmask(x) _MI(u32_mkmask(x))
+#define ipa_mklen(x) u32_masklen(_I(x))
+#define ipa_hash(x) ipv4_hash(_I(x))
+#define ipa_hton(x) x = _MI(htonl(_I(x)))
+#define ipa_ntoh(x) x = _MI(ntohl(_I(x)))
+#define ipa_classify(x) ipv4_classify(_I(x))
unsigned ipv4_mklen(u32);
u32 ipv4_mkmask(unsigned);
+int ipv4_classify(u32);
-/* ??? htonl and ntohl ??? */
+/* FIXME: Is this hash function uniformly distributed over standard routing tables? */
+static inline unsigned ipv4_hash(u32 a)
+{
+ return a ^ (a >> 16) ^ (a >> 24);
+}
#endif