/* * BIRD Internet Routing Daemon -- MPLS manipulation * * (c) 2016 Jan Matejka * (c) 2016 CZ.NIC z.s.p.o. * * Can be freely distributed and used under the terms of the GNU GPL. */ #ifndef _BIRD_MPLS_H_ #define _BIRD_MPLS_H_ #define MPLS_STACK_LENGTH 8 /* Adjust this if you need deeper MPLS stack */ #define MPLS_PXLEN 20 /* Length of the label in bits. Constant. */ #define MPLS_LABEL_MAX ((1<> 12; buf[i*4 + 1] = s.label[i] >> 4; buf[i*4 + 2] = (s.label[i] << 4) | (i == s.len - 1 ? 0x1 : 0); buf[i*4 + 3] = 0; } return buf; } static inline int mpls_buflen(const char *buf) { // Looking for the Bottom of Stack set to 4. int i; for (i = 0; !(buf[i++*4 + 2] & 0x1); ); return i*4; } static inline mpls_stack mpls_ntoh(const char *buf) { mpls_stack s = { .len = mpls_buflen(buf) }; int i; for (i = 0; i < s.len; i++) s.label[i] = (buf[i*4 + 0] << 12) | (buf[i*4 + 1] << 4) | (buf[i*4 + 2] >> 4); return s; } #endif