10#include <netlink/netlink-compat.h>
11#include <netlink-private/route/mpls.h>
12#include <linux-private/linux/mpls.h>
14static const char *mpls_ntop1(
const struct mpls_label *addr,
15 char *buf,
size_t buflen)
17 size_t destlen = buflen;
22 uint32_t entry = ntohl(addr[count++].entry);
23 uint32_t label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT;
24 int len = snprintf(dest, destlen,
"%u", label);
30 if (entry & MPLS_LS_S_MASK)
46const char *mpls_ntop(
int af,
const void *addr,
char *buf,
size_t buflen)
51 return mpls_ntop1((
struct mpls_label *)addr, buf, buflen);
58static int mpls_pton1(
const char *name,
struct mpls_label *addr,
59 unsigned int maxlabels)
64 for (count = 0; count < maxlabels; count++) {
67 label = strtoul(name, &endp, 0);
69 if (label >= (1 << 20))
75 addr->entry = htonl(label << MPLS_LS_LABEL_SHIFT);
77 addr->entry |= htonl(1 << MPLS_LS_S_SHIFT);
78 return (count + 1) *
sizeof(
struct mpls_label);
93int mpls_pton(
int af,
const char *src,
void *addr,
size_t alen)
95 unsigned int maxlabels = alen /
sizeof(
struct mpls_label);
101 err = mpls_pton1(src, (
struct mpls_label *)addr, maxlabels);
104 errno = EAFNOSUPPORT;