Skip to content

Commit b513bd0

Browse files
dsaherndavem330
authored andcommitted
nexthop: Add support for lwt encaps
Add support for NHA_ENCAP and NHA_ENCAP_TYPE. Leverages the existing code for lwtunnel within fib_nh_common, so the only change needed is handling the attributes in the nexthop code. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 53010f9 commit b513bd0

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

include/net/nexthop.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ struct nh_config {
3535
struct in6_addr ipv6;
3636
} gw;
3737

38+
struct nlattr *nh_encap;
39+
u16 nh_encap_type;
40+
3841
u32 nlflags;
3942
struct nl_info nlinfo;
4043
};

net/ipv4/nexthop.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/rtnetlink.h>
1010
#include <linux/slab.h>
1111
#include <net/ipv6_stubs.h>
12+
#include <net/lwtunnel.h>
1213
#include <net/nexthop.h>
1314
#include <net/route.h>
1415
#include <net/sock.h>
@@ -182,6 +183,11 @@ static int nh_fill_node(struct sk_buff *skb, struct nexthop *nh,
182183
break;
183184
}
184185

186+
if (nhi->fib_nhc.nhc_lwtstate &&
187+
lwtunnel_fill_encap(skb, nhi->fib_nhc.nhc_lwtstate,
188+
NHA_ENCAP, NHA_ENCAP_TYPE) < 0)
189+
goto nla_put_failure;
190+
185191
out:
186192
nlmsg_end(skb, nlh);
187193
return 0;
@@ -213,6 +219,11 @@ static size_t nh_nlmsg_size(struct nexthop *nh)
213219
break;
214220
}
215221

222+
if (nhi->fib_nhc.nhc_lwtstate) {
223+
sz += lwtunnel_get_encap_size(nhi->fib_nhc.nhc_lwtstate);
224+
sz += nla_total_size(2); /* NHA_ENCAP_TYPE */
225+
}
226+
216227
return sz;
217228
}
218229

@@ -370,6 +381,8 @@ static int nh_create_ipv4(struct net *net, struct nexthop *nh,
370381
.fc_gw4 = cfg->gw.ipv4,
371382
.fc_gw_family = cfg->gw.ipv4 ? AF_INET : 0,
372383
.fc_flags = cfg->nh_flags,
384+
.fc_encap = cfg->nh_encap,
385+
.fc_encap_type = cfg->nh_encap_type,
373386
};
374387
u32 tb_id = l3mdev_fib_table(cfg->dev);
375388
int err = -EINVAL;
@@ -402,6 +415,8 @@ static int nh_create_ipv6(struct net *net, struct nexthop *nh,
402415
.fc_ifindex = cfg->nh_ifindex,
403416
.fc_gateway = cfg->gw.ipv6,
404417
.fc_flags = cfg->nh_flags,
418+
.fc_encap = cfg->nh_encap,
419+
.fc_encap_type = cfg->nh_encap_type,
405420
};
406421
int err = -EINVAL;
407422

@@ -561,7 +576,8 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb,
561576
cfg->nh_id = nla_get_u32(tb[NHA_ID]);
562577

563578
if (tb[NHA_BLACKHOLE]) {
564-
if (tb[NHA_GATEWAY] || tb[NHA_OIF]) {
579+
if (tb[NHA_GATEWAY] || tb[NHA_OIF] ||
580+
tb[NHA_ENCAP] || tb[NHA_ENCAP_TYPE]) {
565581
NL_SET_ERR_MSG(extack, "Blackhole attribute can not be used with gateway or oif");
566582
goto out;
567583
}
@@ -626,6 +642,25 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb,
626642
}
627643
}
628644

645+
if (tb[NHA_ENCAP]) {
646+
cfg->nh_encap = tb[NHA_ENCAP];
647+
648+
if (!tb[NHA_ENCAP_TYPE]) {
649+
NL_SET_ERR_MSG(extack, "LWT encapsulation type is missing");
650+
goto out;
651+
}
652+
653+
cfg->nh_encap_type = nla_get_u16(tb[NHA_ENCAP_TYPE]);
654+
err = lwtunnel_valid_encap_type(cfg->nh_encap_type, extack);
655+
if (err < 0)
656+
goto out;
657+
658+
} else if (tb[NHA_ENCAP_TYPE]) {
659+
NL_SET_ERR_MSG(extack, "LWT encapsulation attribute is missing");
660+
goto out;
661+
}
662+
663+
629664
err = 0;
630665
out:
631666
return err;

0 commit comments

Comments
 (0)