Skip to content

Commit 0a611be

Browse files
cpaasch-oaithom311
authored andcommitted
ip6_tnl: Add API to mark tunnels to "collect metadata"
To set the flag IFLA_IPTUN_COLLECT_METADATA on the tunnel. Signed-off-by: Christoph Paasch <[email protected]> #432
1 parent 0554543 commit 0a611be

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

include/netlink/route/link/ip6tnl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ extern "C" {
4848
extern int rtnl_link_ip6_tnl_set_fwmark(struct rtnl_link *link, uint32_t fwmark);
4949
extern int rtnl_link_ip6_tnl_get_fwmark(struct rtnl_link *link, uint32_t *fwmark);
5050

51+
extern int rtnl_link_ip6_tnl_set_collect_metadata(struct rtnl_link *link, int enable);
52+
extern int rtnl_link_ip6_tnl_get_collect_metadata(struct rtnl_link *link, int *enable);
53+
5154
#ifdef __cplusplus
5255
}
5356
#endif

lib/route/link/ip6tnl.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#define IP6_TNL_ATTR_PROTO (1 << 7)
4141
#define IP6_TNL_ATTR_FLOWINFO (1 << 8)
4242
#define IP6_TNL_ATTR_FWMARK (1 << 9)
43+
#define IP6_TNL_ATTR_CMTD (1 << 10)
4344

4445
struct ip6_tnl_info
4546
{
@@ -67,6 +68,7 @@ static struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
6768
[IFLA_IPTUN_FLAGS] = { .type = NLA_U32 },
6869
[IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
6970
[IFLA_IPTUN_FWMARK] = { .type = NLA_U32 },
71+
[IFLA_IPTUN_COLLECT_METADATA] = { .type = NLA_FLAG },
7072
};
7173

7274
static int ip6_tnl_alloc(struct rtnl_link *link)
@@ -155,6 +157,9 @@ static int ip6_tnl_parse(struct rtnl_link *link, struct nlattr *data,
155157
ip6_tnl->ip6_tnl_mask |= IP6_TNL_ATTR_FWMARK;
156158
}
157159

160+
if (tb[IFLA_IPTUN_COLLECT_METADATA])
161+
ip6_tnl->ip6_tnl_mask |= IP6_TNL_ATTR_CMTD;
162+
158163
err = 0;
159164

160165
errout:
@@ -203,6 +208,9 @@ static int ip6_tnl_put_attrs(struct nl_msg *msg, struct rtnl_link *link)
203208
if (ip6_tnl->ip6_tnl_mask & IP6_TNL_ATTR_FWMARK)
204209
NLA_PUT_U32(msg, IFLA_IPTUN_FWMARK, ip6_tnl->fwmark);
205210

211+
if (ip6_tnl->ip6_tnl_mask & IP6_TNL_ATTR_CMTD)
212+
NLA_PUT_FLAG(msg, IFLA_IPTUN_COLLECT_METADATA);
213+
206214
nla_nest_end(msg, data);
207215

208216
nla_put_failure:
@@ -288,6 +296,10 @@ static void ip6_tnl_dump_details(struct rtnl_link *link, struct nl_dump_params *
288296
nl_dump(p, " fwmark ");
289297
nl_dump_line(p, "%x\n", ip6_tnl->fwmark);
290298
}
299+
300+
if (ip6_tnl->ip6_tnl_mask & IP6_TNL_ATTR_CMTD) {
301+
nl_dump(p, " collect-metadata\n");
302+
}
291303
}
292304

293305
static int ip6_tnl_clone(struct rtnl_link *dst, struct rtnl_link *src)
@@ -661,6 +673,51 @@ uint32_t rtnl_link_ip6_tnl_get_flags(struct rtnl_link *link)
661673
return ip6_tnl->flags;
662674
}
663675

676+
/**
677+
* Set IP6_TNL collect-metadata flag
678+
* @arg link Link object
679+
* @arg enable 0 to disable, non-zero to enable
680+
*
681+
* Enable or disable the collect-metadata mode on the ip6tnl link.
682+
*
683+
* @return 0 on success or a negative error code
684+
*/
685+
int rtnl_link_ip6_tnl_set_collect_metadata(struct rtnl_link *link, int enable)
686+
{
687+
struct ip6_tnl_info *ip6_tnl = link->l_info;
688+
689+
IS_IP6_TNL_LINK_ASSERT(link);
690+
691+
if (enable)
692+
ip6_tnl->ip6_tnl_mask |= IP6_TNL_ATTR_CMTD;
693+
else
694+
ip6_tnl->ip6_tnl_mask &= ~IP6_TNL_ATTR_CMTD;
695+
696+
return 0;
697+
}
698+
699+
/**
700+
* Get IP6_TNL collect-metadata flag
701+
* @arg link Link object
702+
* @arg enable Pointer to int which will be set to the current state
703+
* (0 if disabled, non-zero if enabled)
704+
*
705+
* @return 0 on success or a negative error code
706+
*/
707+
int rtnl_link_ip6_tnl_get_collect_metadata(struct rtnl_link *link, int *enable)
708+
{
709+
struct ip6_tnl_info *ip6_tnl = link->l_info;
710+
711+
IS_IP6_TNL_LINK_ASSERT(link);
712+
713+
if (!enable)
714+
return -NLE_INVAL;
715+
716+
*enable = !!(ip6_tnl->ip6_tnl_mask & IP6_TNL_ATTR_CMTD);
717+
718+
return 0;
719+
}
720+
664721
/**
665722
* Set IP6_TNL tunnel proto
666723
* @arg link Link object

libnl-route-3.sym

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,8 @@ global:
13671367

13681368
libnl_3_12 {
13691369
global:
1370+
rtnl_link_ip6_tnl_get_collect_metadata;
1371+
rtnl_link_ip6_tnl_set_collect_metadata;
13701372
rtnl_link_is_bond;
13711373
rtnl_nh_get_oif;
13721374
} libnl_3_11;

0 commit comments

Comments
 (0)