2 #include <netlink-private/netlink.h> 3 #include <netlink-private/types.h> 4 #include <netlink-private/route/nexthop-encap.h> 5 #include <netlink/route/nexthop.h> 6 #include <linux/mpls_iptunnel.h> 7 #include <linux/lwtunnel.h> 22 nl_dump(dp,
"ttl %u ", encap_info->ttl);
25 static int mpls_encap_build_msg(
struct nl_msg *msg,
void *priv)
31 NLA_PUT_U8(msg, MPLS_IPTUNNEL_TTL, encap_info->ttl);
39 static void mpls_encap_destructor(
void *priv)
46 static struct nla_policy mpls_encap_policy[MPLS_IPTUNNEL_MAX + 1] = {
48 [MPLS_IPTUNNEL_TTL] = { .type =
NLA_U8 },
51 static int mpls_encap_parse_msg(
struct nlattr *nla,
struct rtnl_nexthop *nh)
53 struct nlattr *tb[MPLS_IPTUNNEL_MAX + 1];
54 struct nl_addr *labels;
63 if (!tb[MPLS_IPTUNNEL_DST])
70 if (tb[MPLS_IPTUNNEL_TTL])
73 err = rtnl_route_nh_encap_mpls(nh, labels, ttl);
80 static int mpls_encap_compare(
void *_a,
void *_b)
86 diff |= (a->ttl != b->ttl);
92 struct nh_encap_ops mpls_encap_ops = {
93 .encap_type = LWTUNNEL_ENCAP_MPLS,
94 .build_msg = mpls_encap_build_msg,
95 .parse_msg = mpls_encap_parse_msg,
96 .compare = mpls_encap_compare,
97 .dump = mpls_encap_dump,
98 .destructor = mpls_encap_destructor,
101 int rtnl_route_nh_encap_mpls(
struct rtnl_nexthop *nh,
102 struct nl_addr *addr,
106 struct rtnl_nh_encap *rtnh_encap;
115 rtnh_encap = calloc(1,
sizeof(*rtnh_encap));
119 mpls_encap = calloc(1,
sizeof(*mpls_encap));
126 mpls_encap->ttl = ttl;
128 rtnh_encap->priv = mpls_encap;
129 rtnh_encap->ops = &mpls_encap_ops;
131 nh_set_encap(nh, rtnh_encap);
int nl_addr_cmp(const struct nl_addr *a, const struct nl_addr *b)
Compare abstract addresses.
#define NLA_PUT_ADDR(msg, attrtype, addr)
Add address attribute to netlink message.
Attribute validation policy.
uint8_t nla_get_u8(const struct nlattr *nla)
Return value of 8 bit integer attribute.
struct nl_addr * nl_addr_get(struct nl_addr *addr)
Increase the reference counter of an abstract address.
struct nl_addr * nl_addr_alloc_attr(const struct nlattr *nla, int family)
Allocate abstract address based on Netlink attribute.
#define NLA_PUT_U8(msg, attrtype, value)
Add 8 bit integer attribute to netlink message.
int nla_parse_nested(struct nlattr *tb[], int maxtype, struct nlattr *nla, struct nla_policy *policy)
Create attribute index based on nested attribute.
void nl_addr_put(struct nl_addr *addr)
Decrease the reference counter of an abstract address.
uint16_t type
Type of attribute or NLA_UNSPEC.
int nl_addr_valid(const char *addr, int family)
Check if address string is parseable for a specific address family.
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
unsigned int nl_addr_get_len(const struct nl_addr *addr)
Get length of binary address of abstract address object.
void * nl_addr_get_binary_addr(const struct nl_addr *addr)
Get binary address of abstract address object.
char * nl_addr2str(const struct nl_addr *addr, char *buf, size_t size)
Convert abstract address object to character string.