summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ip.h22
-rw-r--r--lib/net.c3
-rw-r--r--lib/net.h8
3 files changed, 32 insertions, 1 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)
diff --git a/lib/net.c b/lib/net.c
index 91a4474a..5a7e6fec 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -225,7 +225,8 @@ net_classify(const net_addr *N)
case NET_FLOW6:
return ip6_zero(n->ip6.prefix) ? (IADDR_HOST | SCOPE_UNIVERSE) : ip6_classify(&n->ip6.prefix);
- /* classify probably not needed for NET_MPLS */
+ case NET_MPLS:
+ return IADDR_HOST | SCOPE_UNIVERSE;
}
return IADDR_INVALID;
diff --git a/lib/net.h b/lib/net.h
index 5fc4dab7..7c124fc0 100644
--- a/lib/net.h
+++ b/lib/net.h
@@ -259,6 +259,14 @@ static inline ip_addr net_prefix(const net_addr *a)
}
}
+static inline u32 net_mpls(const net_addr *a)
+{
+ if (a->type == NET_MPLS)
+ return ((net_addr_mpls *) a)->label;
+
+ bug("Can't call net_mpls on non-mpls net_addr");
+}
+
static inline uint net4_pxlen(const net_addr *a)
{ return a->pxlen; }