mirror of https://gitee.com/openkylin/linux.git
net: mpls: Fix multipath selection for LSR use case
MPLS multipath for LSR is broken -- always selecting the first nexthop
in the one label case. For example:
$ ip -f mpls ro ls
100
nexthop as to 200 via inet 172.16.2.2 dev virt12
nexthop as to 300 via inet 172.16.3.2 dev virt13
101
nexthop as to 201 via inet6 2000:2::2 dev virt12
nexthop as to 301 via inet6 2000:3::2 dev virt13
In this example incoming packets have a single MPLS labels which means
BOS bit is set. The BOS bit is passed from mpls_forward down to
mpls_multipath_hash which never processes the hash loop because BOS is 1.
Update mpls_multipath_hash to process the entire label stack. mpls_hdr_len
tracks the total mpls header length on each pass (on pass N mpls_hdr_len
is N * sizeof(mpls_shim_hdr)). When the label is found with the BOS set
it verifies the skb has sufficient header for ipv4 or ipv6, and find the
IPv4 and IPv6 header by using the last mpls_hdr pointer and adding 1 to
advance past it.
With these changes I have verified the code correctly sees the label,
BOS, IPv4 and IPv6 addresses in the network header and icmp/tcp/udp
traffic for ipv4 and ipv6 are distributed across the nexthops.
Fixes: 1c78efa831
("mpls: flow-based multipath selection")
Acked-by: Robert Shearman <rshearma@brocade.com>
Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
a5b9b5a2d3
commit
9f427a0e47
|
@ -98,18 +98,19 @@ bool mpls_pkt_too_big(const struct sk_buff *skb, unsigned int mtu)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(mpls_pkt_too_big);
|
EXPORT_SYMBOL_GPL(mpls_pkt_too_big);
|
||||||
|
|
||||||
static u32 mpls_multipath_hash(struct mpls_route *rt,
|
static u32 mpls_multipath_hash(struct mpls_route *rt, struct sk_buff *skb)
|
||||||
struct sk_buff *skb, bool bos)
|
|
||||||
{
|
{
|
||||||
struct mpls_entry_decoded dec;
|
struct mpls_entry_decoded dec;
|
||||||
|
unsigned int mpls_hdr_len = 0;
|
||||||
struct mpls_shim_hdr *hdr;
|
struct mpls_shim_hdr *hdr;
|
||||||
bool eli_seen = false;
|
bool eli_seen = false;
|
||||||
int label_index;
|
int label_index;
|
||||||
u32 hash = 0;
|
u32 hash = 0;
|
||||||
|
|
||||||
for (label_index = 0; label_index < MAX_MP_SELECT_LABELS && !bos;
|
for (label_index = 0; label_index < MAX_MP_SELECT_LABELS;
|
||||||
label_index++) {
|
label_index++) {
|
||||||
if (!pskb_may_pull(skb, sizeof(*hdr) * label_index))
|
mpls_hdr_len += sizeof(*hdr);
|
||||||
|
if (!pskb_may_pull(skb, mpls_hdr_len))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Read and decode the current label */
|
/* Read and decode the current label */
|
||||||
|
@ -134,37 +135,38 @@ static u32 mpls_multipath_hash(struct mpls_route *rt,
|
||||||
eli_seen = true;
|
eli_seen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bos = dec.bos;
|
if (!dec.bos)
|
||||||
if (bos && pskb_may_pull(skb, sizeof(*hdr) * label_index +
|
continue;
|
||||||
sizeof(struct iphdr))) {
|
|
||||||
|
/* found bottom label; does skb have room for a header? */
|
||||||
|
if (pskb_may_pull(skb, mpls_hdr_len + sizeof(struct iphdr))) {
|
||||||
const struct iphdr *v4hdr;
|
const struct iphdr *v4hdr;
|
||||||
|
|
||||||
v4hdr = (const struct iphdr *)(mpls_hdr(skb) +
|
v4hdr = (const struct iphdr *)(hdr + 1);
|
||||||
label_index);
|
|
||||||
if (v4hdr->version == 4) {
|
if (v4hdr->version == 4) {
|
||||||
hash = jhash_3words(ntohl(v4hdr->saddr),
|
hash = jhash_3words(ntohl(v4hdr->saddr),
|
||||||
ntohl(v4hdr->daddr),
|
ntohl(v4hdr->daddr),
|
||||||
v4hdr->protocol, hash);
|
v4hdr->protocol, hash);
|
||||||
} else if (v4hdr->version == 6 &&
|
} else if (v4hdr->version == 6 &&
|
||||||
pskb_may_pull(skb, sizeof(*hdr) * label_index +
|
pskb_may_pull(skb, mpls_hdr_len +
|
||||||
sizeof(struct ipv6hdr))) {
|
sizeof(struct ipv6hdr))) {
|
||||||
const struct ipv6hdr *v6hdr;
|
const struct ipv6hdr *v6hdr;
|
||||||
|
|
||||||
v6hdr = (const struct ipv6hdr *)(mpls_hdr(skb) +
|
v6hdr = (const struct ipv6hdr *)(hdr + 1);
|
||||||
label_index);
|
|
||||||
|
|
||||||
hash = __ipv6_addr_jhash(&v6hdr->saddr, hash);
|
hash = __ipv6_addr_jhash(&v6hdr->saddr, hash);
|
||||||
hash = __ipv6_addr_jhash(&v6hdr->daddr, hash);
|
hash = __ipv6_addr_jhash(&v6hdr->daddr, hash);
|
||||||
hash = jhash_1word(v6hdr->nexthdr, hash);
|
hash = jhash_1word(v6hdr->nexthdr, hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct mpls_nh *mpls_select_multipath(struct mpls_route *rt,
|
static struct mpls_nh *mpls_select_multipath(struct mpls_route *rt,
|
||||||
struct sk_buff *skb, bool bos)
|
struct sk_buff *skb)
|
||||||
{
|
{
|
||||||
int alive = ACCESS_ONCE(rt->rt_nhn_alive);
|
int alive = ACCESS_ONCE(rt->rt_nhn_alive);
|
||||||
u32 hash = 0;
|
u32 hash = 0;
|
||||||
|
@ -180,7 +182,7 @@ static struct mpls_nh *mpls_select_multipath(struct mpls_route *rt,
|
||||||
if (alive <= 0)
|
if (alive <= 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
hash = mpls_multipath_hash(rt, skb, bos);
|
hash = mpls_multipath_hash(rt, skb);
|
||||||
nh_index = hash % alive;
|
nh_index = hash % alive;
|
||||||
if (alive == rt->rt_nhn)
|
if (alive == rt->rt_nhn)
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -278,17 +280,11 @@ static int mpls_forward(struct sk_buff *skb, struct net_device *dev,
|
||||||
hdr = mpls_hdr(skb);
|
hdr = mpls_hdr(skb);
|
||||||
dec = mpls_entry_decode(hdr);
|
dec = mpls_entry_decode(hdr);
|
||||||
|
|
||||||
/* Pop the label */
|
|
||||||
skb_pull(skb, sizeof(*hdr));
|
|
||||||
skb_reset_network_header(skb);
|
|
||||||
|
|
||||||
skb_orphan(skb);
|
|
||||||
|
|
||||||
rt = mpls_route_input_rcu(net, dec.label);
|
rt = mpls_route_input_rcu(net, dec.label);
|
||||||
if (!rt)
|
if (!rt)
|
||||||
goto drop;
|
goto drop;
|
||||||
|
|
||||||
nh = mpls_select_multipath(rt, skb, dec.bos);
|
nh = mpls_select_multipath(rt, skb);
|
||||||
if (!nh)
|
if (!nh)
|
||||||
goto drop;
|
goto drop;
|
||||||
|
|
||||||
|
@ -297,6 +293,12 @@ static int mpls_forward(struct sk_buff *skb, struct net_device *dev,
|
||||||
if (!mpls_output_possible(out_dev))
|
if (!mpls_output_possible(out_dev))
|
||||||
goto drop;
|
goto drop;
|
||||||
|
|
||||||
|
/* Pop the label */
|
||||||
|
skb_pull(skb, sizeof(*hdr));
|
||||||
|
skb_reset_network_header(skb);
|
||||||
|
|
||||||
|
skb_orphan(skb);
|
||||||
|
|
||||||
if (skb_warn_if_lro(skb))
|
if (skb_warn_if_lro(skb))
|
||||||
goto drop;
|
goto drop;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue