5#include <linux/mpls_iptunnel.h>
6#include <linux/lwtunnel.h>
8#include <netlink/route/nexthop.h>
11#include "nexthop-encap.h"
26 nl_dump(dp,
"ttl %u ", encap_info->ttl);
29static int mpls_encap_build_msg(
struct nl_msg *msg,
void *priv)
35 NLA_PUT_U8(msg, MPLS_IPTUNNEL_TTL, encap_info->ttl);
43static void mpls_encap_destructor(
void *priv)
50static struct nla_policy mpls_encap_policy[MPLS_IPTUNNEL_MAX + 1] = {
52 [MPLS_IPTUNNEL_TTL] = { .type =
NLA_U8 },
55static int mpls_encap_parse_msg(
struct nlattr *nla,
struct rtnl_nexthop *nh)
57 struct nlattr *tb[MPLS_IPTUNNEL_MAX + 1];
58 struct nl_addr *labels;
66 if (!tb[MPLS_IPTUNNEL_DST])
73 if (tb[MPLS_IPTUNNEL_TTL])
76 err = rtnl_route_nh_encap_mpls(nh, labels, ttl);
83static int mpls_encap_compare(
void *_a,
void *_b)
89 diff |= (a->ttl != b->ttl);
96 .encap_type = LWTUNNEL_ENCAP_MPLS,
97 .build_msg = mpls_encap_build_msg,
98 .parse_msg = mpls_encap_parse_msg,
99 .compare = mpls_encap_compare,
100 .dump = mpls_encap_dump,
101 .destructor = mpls_encap_destructor,
105 struct nl_addr *addr,
114 rtnh_encap = calloc(1,
sizeof(*rtnh_encap));
118 mpls_encap = calloc(1,
sizeof(*mpls_encap));
125 mpls_encap->ttl = ttl;
127 rtnh_encap->priv = mpls_encap;
128 rtnh_encap->ops = &mpls_encap_ops;
130 nh_set_encap(nh, rtnh_encap);
135struct nl_addr *rtnl_route_nh_get_encap_mpls_dst(
struct rtnl_nexthop *nh)
139 if (!nh->rtnh_encap || nh->rtnh_encap->ops->encap_type != LWTUNNEL_ENCAP_MPLS)
146 return mpls_encap->dst;
149uint8_t rtnl_route_nh_get_encap_mpls_ttl(
struct rtnl_nexthop *nh)
153 if (!nh->rtnh_encap || nh->rtnh_encap->ops->encap_type != LWTUNNEL_ENCAP_MPLS)
160 return mpls_encap->ttl;
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.
int nl_addr_cmp(const struct nl_addr *a, const struct nl_addr *b)
Compare abstract addresses.
char * nl_addr2str(const struct nl_addr *addr, char *buf, size_t size)
Convert abstract address object to character string.
void nl_addr_put(struct nl_addr *addr)
Decrease the reference counter of an abstract address.
#define NLA_PUT_U8(msg, attrtype, value)
Add 8 bit integer attribute to netlink message.
#define NLA_PUT_ADDR(msg, attrtype, addr)
Add address attribute to netlink message.
uint8_t nla_get_u8(const struct nlattr *nla)
Return value of 8 bit integer attribute.
int nla_parse_nested(struct nlattr *tb[], int maxtype, struct nlattr *nla, const struct nla_policy *policy)
Create attribute index based on nested attribute.
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
Attribute validation policy.
uint16_t type
Type of attribute or NLA_UNSPEC.