Skip to content

Commit 509aba3

Browse files
fxlbdavem330
authored andcommitted
IPv6: add the option to use anycast addresses as source addresses in echo reply
This change allows to follow a recommandation of RFC4942. - Add "anycast_src_echo_reply" sysctl to control the use of anycast addresses as source addresses for ICMPv6 echo reply. This sysctl is false by default to preserve existing behavior. - Add inline check ipv6_anycast_destination(). - Use them in icmpv6_echo_reply(). Reference: RFC4942 - IPv6 Transition/Coexistence Security Considerations (http://tools.ietf.org/html/rfc4942#section-2.1.6) 2.1.6. Anycast Traffic Identification and Security [...] To avoid exposing knowledge about the internal structure of the network, it is recommended that anycast servers now take advantage of the ability to return responses with the anycast address as the source address if possible. Signed-off-by: Francois-Xavier Le Bail <fx.lebail@yahoo.com> Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9ba75fb commit 509aba3

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

Documentation/networking/ip-sysctl.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,13 @@ bindv6only - BOOLEAN
10941094

10951095
Default: FALSE (as specified in RFC3493)
10961096

1097+
anycast_src_echo_reply - BOOLEAN
1098+
Controls the use of anycast addresses as source addresses for ICMPv6
1099+
echo reply
1100+
TRUE: enabled
1101+
FALSE: disabled
1102+
Default: FALSE
1103+
10971104
IPv6 Fragmentation:
10981105

10991106
ip6frag_high_thresh - INTEGER

include/net/ip6_route.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ static inline bool ipv6_unicast_destination(const struct sk_buff *skb)
152152
return rt->rt6i_flags & RTF_LOCAL;
153153
}
154154

155+
static inline bool ipv6_anycast_destination(const struct sk_buff *skb)
156+
{
157+
struct rt6_info *rt = (struct rt6_info *) skb_dst(skb);
158+
159+
return rt->rt6i_flags & RTF_ANYCAST;
160+
}
161+
155162
int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *));
156163

157164
static inline int ip6_skb_dst_mtu(struct sk_buff *skb)

include/net/netns/ipv6.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ struct netns_ipv6 {
7373
#endif
7474
atomic_t dev_addr_genid;
7575
atomic_t rt_genid;
76+
int anycast_src_echo_reply;
7677
};
7778

7879
#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)

net/ipv6/icmp.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,9 @@ static void icmpv6_echo_reply(struct sk_buff *skb)
556556

557557
saddr = &ipv6_hdr(skb)->daddr;
558558

559-
if (!ipv6_unicast_destination(skb))
559+
if (!ipv6_unicast_destination(skb) &&
560+
!(net->ipv6.anycast_src_echo_reply &&
561+
ipv6_anycast_destination(skb)))
560562
saddr = NULL;
561563

562564
memcpy(&tmp_hdr, icmph, sizeof(tmp_hdr));

net/ipv6/sysctl_net_ipv6.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ static struct ctl_table ipv6_table_template[] = {
2424
.mode = 0644,
2525
.proc_handler = proc_dointvec
2626
},
27+
{
28+
.procname = "anycast_src_echo_reply",
29+
.data = &init_net.ipv6.anycast_src_echo_reply,
30+
.maxlen = sizeof(int),
31+
.mode = 0644,
32+
.proc_handler = proc_dointvec
33+
},
2734
{ }
2835
};
2936

@@ -51,6 +58,7 @@ static int __net_init ipv6_sysctl_net_init(struct net *net)
5158
if (!ipv6_table)
5259
goto out;
5360
ipv6_table[0].data = &net->ipv6.sysctl.bindv6only;
61+
ipv6_table[1].data = &net->ipv6.anycast_src_echo_reply;
5462

5563
ipv6_route_table = ipv6_route_sysctl_init(net);
5664
if (!ipv6_route_table)

0 commit comments

Comments
 (0)