Revision d14f8c3c lib/ip.h

View differences:

lib/ip.h
325 325
static inline ip6_addr ip6_ntoh(ip6_addr a)
326 326
{ return _MI6(ntohl(_I0(a)), ntohl(_I1(a)), ntohl(_I2(a)), ntohl(_I3(a))); }
327 327

  
328
#define MPLS_MAX_LABEL_STACK 8
329
static inline int
330
mpls_get(const char *buf, int buflen, u32 *stack)
331
{
332
  for (int i=0; (i<MPLS_MAX_LABEL_STACK) && (i*4+3 < buflen); i++)
333
  {
334
    u32 s = get_u32(buf + i*4);
335
    stack[i] = s >> 12;
336
    if (s & 0x100)
337
      return i+1;
338
  }
339
  return -1;
340
}
341

  
342
static inline int
343
mpls_put(char *buf, int len, u32 *stack)
344
{
345
  for (int i=0; i<len; i++)
346
    put_u32(buf + i*4, stack[i] << 12 | (i+1 == len ? 0x100 : 0));
347

  
348
  return len*4;
349
}
328 350

  
329 351
/*
330 352
 *	Unaligned data access (in network order)

Also available in: Unified diff