summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2016-04-28 18:01:40 +0200
committerOndrej Zajicek (work) <santiago@crfreenet.org>2016-04-28 18:01:40 +0200
commit937e75d8f1d203b637ba0ea050026f9af92485f3 (patch)
tree2737eba68e77ac4030d24e42506db0947196f775 /lib
parenta7baa09862e6b4856cd66197c6bd74c7df336b8f (diff)
Add the Babel routing protocol (RFC 6126)
This patch implements the IPv6 subset of the Babel routing protocol. Based on the patch from Toke Hoiland-Jorgensen, with some heavy modifications and bugfixes. Thanks to Toke Hoiland-Jorgensen for the original patch.
Diffstat (limited to 'lib')
-rw-r--r--lib/birdlib.h1
-rw-r--r--lib/bitops.h3
-rw-r--r--lib/ip.h1
-rw-r--r--lib/printf.c31
-rw-r--r--lib/string.h2
5 files changed, 30 insertions, 8 deletions
diff --git a/lib/birdlib.h b/lib/birdlib.h
index 16f437ef..904544cb 100644
--- a/lib/birdlib.h
+++ b/lib/birdlib.h
@@ -60,6 +60,7 @@
#define NORET __attribute__((noreturn))
#define UNUSED __attribute__((unused))
+#define PACKED __attribute__((packed))
/* Microsecond time */
diff --git a/lib/bitops.h b/lib/bitops.h
index c0ad1a70..ce13732a 100644
--- a/lib/bitops.h
+++ b/lib/bitops.h
@@ -25,5 +25,6 @@ u32 u32_log2(u32 v);
static inline u32 u32_hash(u32 v) { return v * 2902958171u; }
-#endif
+static inline u8 u32_popcount(u32 v) { return __builtin_popcount(v); }
+#endif
diff --git a/lib/ip.h b/lib/ip.h
index 5389c44a..298b72a7 100644
--- a/lib/ip.h
+++ b/lib/ip.h
@@ -26,6 +26,7 @@
#define IP6_OSPF_ALL_ROUTERS ipa_build6(0xFF020000, 0, 0, 5)
#define IP6_OSPF_DES_ROUTERS ipa_build6(0xFF020000, 0, 0, 6)
#define IP6_RIP_ROUTERS ipa_build6(0xFF020000, 0, 0, 9)
+#define IP6_BABEL_ROUTERS ipa_build6(0xFF020000, 0, 0, 0x00010006)
#define IP4_NONE _MI4(0)
#define IP6_NONE _MI6(0,0,0,0)
diff --git a/lib/printf.c b/lib/printf.c
index e4cc3006..a067fe98 100644
--- a/lib/printf.c
+++ b/lib/printf.c
@@ -124,6 +124,7 @@ static char * number(char * str, long num, int base, int size, int precision,
* width is automatically replaced by standard IP address width which
* depends on whether we use IPv4 or IPv6; |%#I| gives hexadecimal format),
* |%R| for Router / Network ID (u32 value printed as IPv4 address)
+ * |%lR| for 64bit Router / Network ID (u64 value printed as eight :-separated octets)
* and |%m| resp. |%M| for error messages (uses strerror() to translate @errno code to
* message text). On the other hand, it doesn't support floating
* point numbers.
@@ -137,9 +138,10 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
unsigned long num;
int i, base;
u32 x;
+ u64 X;
char *str, *start;
const char *s;
- char ipbuf[STD_ADDRESS_P_LENGTH+1];
+ char ipbuf[MAX(STD_ADDRESS_P_LENGTH,ROUTER_ID_64_LENGTH)+1];
struct iface *iface;
int flags; /* flags to number() */
@@ -309,12 +311,27 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
/* Router/Network ID - essentially IPv4 address in u32 value */
case 'R':
- x = va_arg(args, u32);
- bsprintf(ipbuf, "%d.%d.%d.%d",
- ((x >> 24) & 0xff),
- ((x >> 16) & 0xff),
- ((x >> 8) & 0xff),
- (x & 0xff));
+ if(qualifier == 'l') {
+ X = va_arg(args, u64);
+ bsprintf(ipbuf, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
+ ((X >> 56) & 0xff),
+ ((X >> 48) & 0xff),
+ ((X >> 40) & 0xff),
+ ((X >> 32) & 0xff),
+ ((X >> 24) & 0xff),
+ ((X >> 16) & 0xff),
+ ((X >> 8) & 0xff),
+ (X & 0xff));
+ }
+ else
+ {
+ x = va_arg(args, u32);
+ bsprintf(ipbuf, "%d.%d.%d.%d",
+ ((x >> 24) & 0xff),
+ ((x >> 16) & 0xff),
+ ((x >> 8) & 0xff),
+ (x & 0xff));
+ }
s = ipbuf;
goto str;
diff --git a/lib/string.h b/lib/string.h
index 0f249d37..9af49b9e 100644
--- a/lib/string.h
+++ b/lib/string.h
@@ -30,4 +30,6 @@ static inline char *xbasename(const char *str)
return s ? s+1 : (char *) str;
}
+#define ROUTER_ID_64_LENGTH 23
+
#endif