Skip to content

Commit 23aebda

Browse files
Jakub Sitnickidavem330
authored andcommitted
ipv6: Compute multipath hash for ICMP errors from offending packet
When forwarding or sending out an ICMPv6 error, look at the embedded packet that triggered the error and compute a flow hash over its headers. This let's us route the ICMP error together with the flow it belongs to when multipath (ECMP) routing is in use, which in turn makes Path MTU Discovery work in ECMP load-balanced or anycast setups (RFC 7690). Granted, end-hosts behind the ECMP router (aka servers) need to reflect the IPv6 Flow Label for PMTUD to work. The code is organized to be in parallel with ipv4 stack: ip_multipath_l3_keys -> ip6_multipath_l3_keys fib_multipath_hash -> rt6_multipath_hash Signed-off-by: Jakub Sitnicki <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2982571 commit 23aebda

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

include/net/ip6_route.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ static inline int ip6_route_get_saddr(struct net *net, struct rt6_info *rt,
115115

116116
struct rt6_info *rt6_lookup(struct net *net, const struct in6_addr *daddr,
117117
const struct in6_addr *saddr, int oif, int flags);
118+
u32 rt6_multipath_hash(const struct flowi6 *fl6, const struct sk_buff *skb);
118119

119120
struct dst_entry *icmp6_dst_alloc(struct net_device *dev, struct flowi6 *fl6);
120121

net/ipv6/icmp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ static void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
519519
fl6.fl6_icmp_type = type;
520520
fl6.fl6_icmp_code = code;
521521
fl6.flowi6_uid = sock_net_uid(net, NULL);
522+
fl6.mp_hash = rt6_multipath_hash(&fl6, skb);
522523
security_skb_classify_flow(skb, flowi6_to_flowi(&fl6));
523524

524525
sk = icmpv6_xmit_lock(net);

net/ipv6/route.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,54 @@ struct dst_entry *ip6_route_input_lookup(struct net *net,
12141214
}
12151215
EXPORT_SYMBOL_GPL(ip6_route_input_lookup);
12161216

1217+
static void ip6_multipath_l3_keys(const struct sk_buff *skb,
1218+
struct flow_keys *keys)
1219+
{
1220+
const struct ipv6hdr *outer_iph = ipv6_hdr(skb);
1221+
const struct ipv6hdr *key_iph = outer_iph;
1222+
const struct ipv6hdr *inner_iph;
1223+
const struct icmp6hdr *icmph;
1224+
struct ipv6hdr _inner_iph;
1225+
1226+
if (likely(outer_iph->nexthdr != IPPROTO_ICMPV6))
1227+
goto out;
1228+
1229+
icmph = icmp6_hdr(skb);
1230+
if (icmph->icmp6_type != ICMPV6_DEST_UNREACH &&
1231+
icmph->icmp6_type != ICMPV6_PKT_TOOBIG &&
1232+
icmph->icmp6_type != ICMPV6_TIME_EXCEED &&
1233+
icmph->icmp6_type != ICMPV6_PARAMPROB)
1234+
goto out;
1235+
1236+
inner_iph = skb_header_pointer(skb,
1237+
skb_transport_offset(skb) + sizeof(*icmph),
1238+
sizeof(_inner_iph), &_inner_iph);
1239+
if (!inner_iph)
1240+
goto out;
1241+
1242+
key_iph = inner_iph;
1243+
out:
1244+
memset(keys, 0, sizeof(*keys));
1245+
keys->control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
1246+
keys->addrs.v6addrs.src = key_iph->saddr;
1247+
keys->addrs.v6addrs.dst = key_iph->daddr;
1248+
keys->tags.flow_label = ip6_flowinfo(key_iph);
1249+
keys->basic.ip_proto = key_iph->nexthdr;
1250+
}
1251+
1252+
/* if skb is set it will be used and fl6 can be NULL */
1253+
u32 rt6_multipath_hash(const struct flowi6 *fl6, const struct sk_buff *skb)
1254+
{
1255+
struct flow_keys hash_keys;
1256+
1257+
if (skb) {
1258+
ip6_multipath_l3_keys(skb, &hash_keys);
1259+
return flow_hash_from_keys(&hash_keys);
1260+
}
1261+
1262+
return get_hash_from_flowi6(fl6);
1263+
}
1264+
12171265
void ip6_route_input(struct sk_buff *skb)
12181266
{
12191267
const struct ipv6hdr *iph = ipv6_hdr(skb);
@@ -1232,6 +1280,8 @@ void ip6_route_input(struct sk_buff *skb)
12321280
tun_info = skb_tunnel_info(skb);
12331281
if (tun_info && !(tun_info->mode & IP_TUNNEL_INFO_TX))
12341282
fl6.flowi6_tun_key.tun_id = tun_info->key.tun_id;
1283+
if (unlikely(fl6.flowi6_proto == IPPROTO_ICMPV6))
1284+
fl6.mp_hash = rt6_multipath_hash(&fl6, skb);
12351285
skb_dst_drop(skb);
12361286
skb_dst_set(skb, ip6_route_input_lookup(net, skb->dev, &fl6, flags));
12371287
}

0 commit comments

Comments
 (0)