mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-06 05:06:29 +00:00
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 <dsahern@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
53010f991a
commit
b513bd035f
@ -35,6 +35,9 @@ struct nh_config {
|
||||
struct in6_addr ipv6;
|
||||
} gw;
|
||||
|
||||
struct nlattr *nh_encap;
|
||||
u16 nh_encap_type;
|
||||
|
||||
u32 nlflags;
|
||||
struct nl_info nlinfo;
|
||||
};
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <linux/slab.h>
|
||||
#include <net/ipv6_stubs.h>
|
||||
#include <net/lwtunnel.h>
|
||||
#include <net/nexthop.h>
|
||||
#include <net/route.h>
|
||||
#include <net/sock.h>
|
||||
@ -182,6 +183,11 @@ static int nh_fill_node(struct sk_buff *skb, struct nexthop *nh,
|
||||
break;
|
||||
}
|
||||
|
||||
if (nhi->fib_nhc.nhc_lwtstate &&
|
||||
lwtunnel_fill_encap(skb, nhi->fib_nhc.nhc_lwtstate,
|
||||
NHA_ENCAP, NHA_ENCAP_TYPE) < 0)
|
||||
goto nla_put_failure;
|
||||
|
||||
out:
|
||||
nlmsg_end(skb, nlh);
|
||||
return 0;
|
||||
@ -213,6 +219,11 @@ static size_t nh_nlmsg_size(struct nexthop *nh)
|
||||
break;
|
||||
}
|
||||
|
||||
if (nhi->fib_nhc.nhc_lwtstate) {
|
||||
sz += lwtunnel_get_encap_size(nhi->fib_nhc.nhc_lwtstate);
|
||||
sz += nla_total_size(2); /* NHA_ENCAP_TYPE */
|
||||
}
|
||||
|
||||
return sz;
|
||||
}
|
||||
|
||||
@ -370,6 +381,8 @@ static int nh_create_ipv4(struct net *net, struct nexthop *nh,
|
||||
.fc_gw4 = cfg->gw.ipv4,
|
||||
.fc_gw_family = cfg->gw.ipv4 ? AF_INET : 0,
|
||||
.fc_flags = cfg->nh_flags,
|
||||
.fc_encap = cfg->nh_encap,
|
||||
.fc_encap_type = cfg->nh_encap_type,
|
||||
};
|
||||
u32 tb_id = l3mdev_fib_table(cfg->dev);
|
||||
int err = -EINVAL;
|
||||
@ -402,6 +415,8 @@ static int nh_create_ipv6(struct net *net, struct nexthop *nh,
|
||||
.fc_ifindex = cfg->nh_ifindex,
|
||||
.fc_gateway = cfg->gw.ipv6,
|
||||
.fc_flags = cfg->nh_flags,
|
||||
.fc_encap = cfg->nh_encap,
|
||||
.fc_encap_type = cfg->nh_encap_type,
|
||||
};
|
||||
int err = -EINVAL;
|
||||
|
||||
@ -561,7 +576,8 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb,
|
||||
cfg->nh_id = nla_get_u32(tb[NHA_ID]);
|
||||
|
||||
if (tb[NHA_BLACKHOLE]) {
|
||||
if (tb[NHA_GATEWAY] || tb[NHA_OIF]) {
|
||||
if (tb[NHA_GATEWAY] || tb[NHA_OIF] ||
|
||||
tb[NHA_ENCAP] || tb[NHA_ENCAP_TYPE]) {
|
||||
NL_SET_ERR_MSG(extack, "Blackhole attribute can not be used with gateway or oif");
|
||||
goto out;
|
||||
}
|
||||
@ -626,6 +642,25 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb,
|
||||
}
|
||||
}
|
||||
|
||||
if (tb[NHA_ENCAP]) {
|
||||
cfg->nh_encap = tb[NHA_ENCAP];
|
||||
|
||||
if (!tb[NHA_ENCAP_TYPE]) {
|
||||
NL_SET_ERR_MSG(extack, "LWT encapsulation type is missing");
|
||||
goto out;
|
||||
}
|
||||
|
||||
cfg->nh_encap_type = nla_get_u16(tb[NHA_ENCAP_TYPE]);
|
||||
err = lwtunnel_valid_encap_type(cfg->nh_encap_type, extack);
|
||||
if (err < 0)
|
||||
goto out;
|
||||
|
||||
} else if (tb[NHA_ENCAP_TYPE]) {
|
||||
NL_SET_ERR_MSG(extack, "LWT encapsulation attribute is missing");
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
||||
err = 0;
|
||||
out:
|
||||
return err;
|
||||
|
Loading…
Reference in New Issue
Block a user