summaryrefslogtreecommitdiff
path: root/lib/ip.h
diff options
context:
space:
mode:
authorJan Moskyto Matejka <mq@ucw.cz>2016-03-04 12:55:50 +0100
committerJan Moskyto Matejka <mq@ucw.cz>2016-12-22 21:38:33 +0100
commitd14f8c3c45f7e33a7e54ebc0d45bdb0295d70301 (patch)
treee7dadc1408d852a36075efc64a9bdb15630efdd4 /lib/ip.h
parentf2010f9c65ca69584c34c762fb3e5e957958478e (diff)
Netlink: MPLS routes in kernel
Anyway, Bird is now capable to insert both MPLS routes and MPLS encap routes into kernel. It was (among others) needed to define platform-specific AF_MPLS to 28 as this constant has been assigned in the linux kernel. No support for BSD now, it may be added in the future.
Diffstat (limited to 'lib/ip.h')
-rw-r--r--lib/ip.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/ip.h b/lib/ip.h
index 86750675..ab90bee7 100644
--- a/lib/ip.h
+++ b/lib/ip.h
@@ -325,6 +325,28 @@ static inline ip6_addr ip6_hton(ip6_addr a)
static inline ip6_addr ip6_ntoh(ip6_addr a)
{ return _MI6(ntohl(_I0(a)), ntohl(_I1(a)), ntohl(_I2(a)), ntohl(_I3(a))); }
+#define MPLS_MAX_LABEL_STACK 8
+static inline int
+mpls_get(const char *buf, int buflen, u32 *stack)
+{
+ for (int i=0; (i<MPLS_MAX_LABEL_STACK) && (i*4+3 < buflen); i++)
+ {
+ u32 s = get_u32(buf + i*4);
+ stack[i] = s >> 12;
+ if (s & 0x100)
+ return i+1;
+ }
+ return -1;
+}
+
+static inline int
+mpls_put(char *buf, int len, u32 *stack)
+{
+ for (int i=0; i<len; i++)
+ put_u32(buf + i*4, stack[i] << 12 | (i+1 == len ? 0x100 : 0));
+
+ return len*4;
+}
/*
* Unaligned data access (in network order)