6#include <linux/lwtunnel.h>
8#include <netlink/route/nexthop.h>
10#include "nexthop-encap.h"
11#include "nl-aux-route/nl-route.h"
19 bool has_csum_mode : 1;
20 bool has_ident_type : 1;
21 bool has_hook_type : 1;
28 nl_dump(dp,
" locator 0x%llx ", (
unsigned long long)ila_encap->locator);
30 if (ila_encap->has_csum_mode)
31 nl_dump(dp,
" csum-mode %u ", ila_encap->csum_mode);
33 if (ila_encap->has_ident_type)
34 nl_dump(dp,
" ident-type %u ", ila_encap->ident_type);
36 if (ila_encap->has_hook_type)
37 nl_dump(dp,
" hook-type %u ", ila_encap->hook_type);
40static int ila_encap_build_msg(
struct nl_msg *msg,
void *priv)
44 NLA_PUT_U64(msg, ILA_ATTR_LOCATOR, ila_encap->locator);
46 if (ila_encap->has_csum_mode)
47 NLA_PUT_U8(msg, ILA_ATTR_CSUM_MODE, ila_encap->csum_mode);
49 if (ila_encap->has_ident_type)
50 NLA_PUT_U8(msg, ILA_ATTR_IDENT_TYPE, ila_encap->ident_type);
52 if (ila_encap->has_hook_type)
53 NLA_PUT_U8(msg, ILA_ATTR_HOOK_TYPE, ila_encap->hook_type);
61static void *ila_encap_clone(
void *priv)
66static int ila_encap_compare(
void *_a,
void *_b)
74 if (a->locator != b->locator)
77 if (a->has_csum_mode != b->has_csum_mode)
80 if (a->has_csum_mode && a->csum_mode != b->csum_mode)
83 if (a->has_ident_type != b->has_ident_type)
86 if (a->has_ident_type && a->ident_type != b->ident_type)
89 if (a->has_hook_type != b->has_hook_type)
92 if (a->has_hook_type && a->hook_type != b->hook_type)
98static struct nla_policy ila_encap_policy[ILA_ATTR_MAX + 1] = {
99 [ILA_ATTR_LOCATOR] = { .type =
NLA_U64 },
100 [ILA_ATTR_CSUM_MODE] = { .type =
NLA_U8 },
101 [ILA_ATTR_IDENT_TYPE] = { .type =
NLA_U8 },
102 [ILA_ATTR_HOOK_TYPE] = { .type =
NLA_U8 },
105static int ila_encap_parse_msg(
struct nlattr *nla,
108 _nl_auto_rtnl_nh_encap
struct rtnl_nh_encap *nh_encap = NULL;
109 struct nlattr *tb[ILA_ATTR_MAX + 1];
117 if (!tb[ILA_ATTR_LOCATOR])
122 nh_encap = rtnl_nh_encap_alloc();
126 err = rtnl_nh_encap_ila(nh_encap, locator);
130 if (tb[ILA_ATTR_CSUM_MODE]) {
131 err = rtnl_nh_set_encap_ila_csum_mode(
132 nh_encap,
nla_get_u8(tb[ILA_ATTR_CSUM_MODE]));
137 if (tb[ILA_ATTR_IDENT_TYPE]) {
138 err = rtnl_nh_set_encap_ila_ident_type(
139 nh_encap,
nla_get_u8(tb[ILA_ATTR_IDENT_TYPE]));
144 if (tb[ILA_ATTR_HOOK_TYPE]) {
145 err = rtnl_nh_set_encap_ila_hook_type(
146 nh_encap,
nla_get_u8(tb[ILA_ATTR_HOOK_TYPE]));
151 *encap_out = _nl_steal_pointer(&nh_encap);
157 .encap_type = LWTUNNEL_ENCAP_ILA,
158 .build_msg = ila_encap_build_msg,
159 .parse_msg = ila_encap_parse_msg,
160 .compare = ila_encap_compare,
161 .clone = ila_encap_clone,
162 .dump = ila_encap_dump,
167 return nh_encap_check_and_get_priv(nh_encap, LWTUNNEL_ENCAP_ILA);
170int rtnl_nh_encap_ila(
struct rtnl_nh_encap *nh_encap, uint64_t locator)
177 ila_encap = calloc(1,
sizeof(*ila_encap));
181 ila_encap->locator = locator;
183 nh_encap->priv = ila_encap;
184 nh_encap->ops = &ila_encap_ops;
189int rtnl_nh_get_encap_ila_locator(
struct rtnl_nh_encap *nh_encap,
197 ila_encap = nh_encap_get_ila(nh_encap);
201 *locator = ila_encap->locator;
206int rtnl_nh_set_encap_ila_csum_mode(
struct rtnl_nh_encap *nh_encap,
211 ila_encap = nh_encap_get_ila(nh_encap);
215 ila_encap->csum_mode = csum_mode;
216 ila_encap->has_csum_mode =
true;
221int rtnl_nh_clear_encap_ila_csum_mode(
struct rtnl_nh_encap *nh_encap)
225 ila_encap = nh_encap_get_ila(nh_encap);
229 ila_encap->has_csum_mode =
false;
230 ila_encap->csum_mode = 0;
235int rtnl_nh_get_encap_ila_csum_mode(
struct rtnl_nh_encap *nh_encap)
239 ila_encap = nh_encap_get_ila(nh_encap);
243 if (!ila_encap->has_csum_mode)
244 return -NLE_MISSING_ATTR;
246 return ila_encap->csum_mode;
249int rtnl_nh_set_encap_ila_ident_type(
struct rtnl_nh_encap *nh_encap,
254 ila_encap = nh_encap_get_ila(nh_encap);
258 ila_encap->ident_type = ident_type;
259 ila_encap->has_ident_type =
true;
264int rtnl_nh_clear_encap_ila_ident_type(
struct rtnl_nh_encap *nh_encap)
268 ila_encap = nh_encap_get_ila(nh_encap);
272 ila_encap->has_ident_type =
false;
273 ila_encap->ident_type = 0;
278int rtnl_nh_get_encap_ila_ident_type(
struct rtnl_nh_encap *nh_encap)
282 ila_encap = nh_encap_get_ila(nh_encap);
286 if (!ila_encap->has_ident_type)
287 return -NLE_MISSING_ATTR;
289 return ila_encap->ident_type;
292int rtnl_nh_set_encap_ila_hook_type(
struct rtnl_nh_encap *nh_encap,
297 ila_encap = nh_encap_get_ila(nh_encap);
301 ila_encap->hook_type = hook_type;
302 ila_encap->has_hook_type =
true;
307int rtnl_nh_clear_encap_ila_hook_type(
struct rtnl_nh_encap *nh_encap)
311 ila_encap = nh_encap_get_ila(nh_encap);
315 ila_encap->has_hook_type =
false;
316 ila_encap->hook_type = 0;
321int rtnl_nh_get_encap_ila_hook_type(
struct rtnl_nh_encap *nh_encap)
325 ila_encap = nh_encap_get_ila(nh_encap);
329 if (!ila_encap->has_hook_type)
330 return -NLE_MISSING_ATTR;
332 return ila_encap->hook_type;
#define NLA_PUT_U8(msg, attrtype, value)
Add 8 bit integer attribute to netlink message.
uint64_t nla_get_u64(const struct nlattr *nla)
Return payload of u64 attribute.
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.
#define NLA_PUT_U64(msg, attrtype, value)
Add 64 bit integer attribute to netlink message.
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
Attribute validation policy.