[PATCH] ipv6: Use inbound ifaddr as source addresses for ICMPv6 errors

Subsystems: networking [general], networking [ipv4/ipv6], the rest

STALE3682d

2 messages, 2 authors, 2016-08-27 · open the first message on its own page

[PATCH] ipv6: Use inbound ifaddr as source addresses for ICMPv6 errors

From: Eli Cooper <hidden>
Date: 2016-08-27 13:05:50

According to RFC 1885 2.2(c), the source address of ICMPv6
errors in response to forwarded packets should be set to the
unicast address of the forwarding interface in order to be helpful
in diagnosis. Currently the selection of source address is based
on the default route, without respect to the inbound interface.

This patch sets the source address of ICMPv6 error messages to
the address of inbound interface, with the exception of
'time exceeded' and 'packet to big' messages sent in ip6_forward(),
where the address of OUTPUT device is forced as source address
(however, it is NOT enforced as claimed without this patch).

Signed-off-by: Eli Cooper <redacted>
---
 net/ipv6/icmp.c | 7 +++++++
 1 file changed, 7 insertions(+)
diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
index bd59c34..0e52f3b 100644
--- a/net/ipv6/icmp.c
+++ b/net/ipv6/icmp.c
@@ -397,6 +397,7 @@ static void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
 	struct sock *sk;
 	struct ipv6_pinfo *np;
 	const struct in6_addr *saddr = NULL;
+	struct in6_addr tmp_saddr;
 	struct dst_entry *dst;
 	struct icmp6hdr tmp_hdr;
 	struct flowi6 fl6;
@@ -421,6 +422,12 @@ static void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
 	 */
 	addr_type = ipv6_addr_type(&hdr->daddr);
 
+	if (type == ICMPV6_DEST_UNREACH || type == ICMPV6_PKT_TOOBIG ||
+	    type == ICMPV6_TIME_EXCEED || type == ICMPV6_PARAMPROB)
+		if (!ipv6_dev_get_saddr(net, skb->dev, &hdr->saddr, 0,
+					&tmp_saddr))
+			saddr = &tmp_saddr;
+
 	if (ipv6_chk_addr(net, &hdr->daddr, skb->dev, 0) ||
 	    ipv6_chk_acast_addr_src(net, skb->dev, &hdr->daddr))
 		saddr = &hdr->daddr;
-- 
2.9.3

Re: [PATCH] ipv6: Use inbound ifaddr as source addresses for ICMPv6 errors

From: Sergei Shtylyov <hidden>
Date: 2016-08-27 15:17:52

Hello.

On 8/27/2016 4:05 PM, Eli Cooper wrote:
quoted hunk
According to RFC 1885 2.2(c), the source address of ICMPv6
errors in response to forwarded packets should be set to the
unicast address of the forwarding interface in order to be helpful
in diagnosis. Currently the selection of source address is based
on the default route, without respect to the inbound interface.

This patch sets the source address of ICMPv6 error messages to
the address of inbound interface, with the exception of
'time exceeded' and 'packet to big' messages sent in ip6_forward(),
where the address of OUTPUT device is forced as source address
(however, it is NOT enforced as claimed without this patch).

Signed-off-by: Eli Cooper <redacted>
---
 net/ipv6/icmp.c | 7 +++++++
 1 file changed, 7 insertions(+)
diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
index bd59c34..0e52f3b 100644
--- a/net/ipv6/icmp.c
+++ b/net/ipv6/icmp.c
[...]
quoted hunk
@@ -421,6 +422,12 @@ static void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
 	 */
 	addr_type = ipv6_addr_type(&hdr->daddr);

+	if (type == ICMPV6_DEST_UNREACH || type == ICMPV6_PKT_TOOBIG ||
+	    type == ICMPV6_TIME_EXCEED || type == ICMPV6_PARAMPROB)
    This is asking to be a *switch* statement instead.
+		if (!ipv6_dev_get_saddr(net, skb->dev, &hdr->saddr, 0,
+					&tmp_saddr))
+			saddr = &tmp_saddr;
+
 	if (ipv6_chk_addr(net, &hdr->daddr, skb->dev, 0) ||
 	    ipv6_chk_acast_addr_src(net, skb->dev, &hdr->daddr))
 		saddr = &hdr->daddr;
MBR, Sergei
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help