Skip to contentSkip to conversation

net: ping6: Fix ping -6 with interface name

PATCH Superseded Tariq Toukan 2 participants 2 messages May 29, 2022 – May 30, 2022

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: ping6: Fix ping -6 with interface name

From: Aya Levin <[email protected]>

When passing interface parameter to ping -6:

$ ping -6 ::11:141:84:9 -I eth2
Results in:
PING ::11:141:84:10(::11:141:84:10) from ::11:141:84:9 eth2: 56 data bytes
ping: sendmsg: Invalid argument
ping: sendmsg: Invalid argument

Initialize the fl6's outgoing interface (OIF) before triggering ip6_datagram_send_ctl. Don't wipe fl6 after ip6_datagram_send_ctl() as changes in fl6 that may happen in the function are overwritten explicitly. Update comment accordingly.

Fixes 13651224c00b ("net: ping6: support setting basic SOL_IPV6 options via cmsg")
---
 net/ipv6/ping.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

V2:
Per David Ahern's comment, moved memset before if (msg->msg_controllen), and updated the code comment accordingly.

net/ipv6/ping.c +4 -3
index ff033d16549e..2a5f3337d488 100644
@@ -101,24 +101,25 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	ipc6.sockc.tsflags = sk->sk_tsflags;
 	ipc6.sockc.mark = sk->sk_mark;
 
+	memset(&fl6, 0, sizeof(fl6));
+
 	if (msg->msg_controllen) {
 		struct ipv6_txoptions opt = {};
 
 		opt.tot_len = sizeof(opt);
 		ipc6.opt = &opt;
+		fl6.flowi6_oif = oif;
 
 		err = ip6_datagram_send_ctl(sock_net(sk), sk, msg, &fl6, &ipc6);
 		if (err < 0)
 			return err;
 
 		/* Changes to txoptions and flow info are not implemented, yet.
-		 * Drop the options, fl6 is wiped below.
+		 * Drop the options.
 		 */
 		ipc6.opt = NULL;
 	}
 
-	memset(&fl6, 0, sizeof(fl6));
-
 	fl6.flowi6_proto = IPPROTO_ICMPV6;
 	fl6.saddr = np->saddr;
 	fl6.daddr = *daddr;
Signature · 1 line
2.21.0
#1 lore raw
Quoted 33 lines · Tariq Toukan

From: Aya Levin <[email protected]>

When passing interface parameter to ping -6:

$ ping -6 ::11:141:84:9 -I eth2
Results in:
PING ::11:141:84:10(::11:141:84:10) from ::11:141:84:9 eth2: 56 data bytes
ping: sendmsg: Invalid argument
ping: sendmsg: Invalid argument

Initialize the fl6's outgoing interface (OIF) before triggering ip6_datagram_send_ctl. Don't wipe fl6 after ip6_datagram_send_ctl() as changes in fl6 that may happen in the function are overwritten explicitly. Update comment accordingly.

Fixes 13651224c00b ("net: ping6: support setting basic SOL_IPV6 options via cmsg")
---
 net/ipv6/ping.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

V2:
Per David Ahern's comment, moved memset before if (msg->msg_controllen), and updated the code comment accordingly.

net/ipv6/ping.c +0 -0
index ff033d16549e..2a5f3337d488 100644
@@ -101,24 +101,25 @@ static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	ipc6.sockc.tsflags = sk->sk_tsflags;

net/ipv6/ping.c static int ping_v6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) · line 111

Quoted 10 lines
net/ipv6/ping.c +3 -0
 	ipc6.sockc.mark = sk->sk_mark;
 
+	memset(&fl6, 0, sizeof(fl6));
+
 	if (msg->msg_controllen) {
 		struct ipv6_txoptions opt = {};
 
 		opt.tot_len = sizeof(opt);
 		ipc6.opt = &opt;
+		fl6.flowi6_oif = oif;

This should be moved up to after the memset since it is currently done after "fl6.daddr = *daddr;" below (remove that one). That's how it is done in rawv6_sendmsg and udpv6_sendmsg.

Quoted 17 lines
net/ipv6/ping.c +1 -3
 		err = ip6_datagram_send_ctl(sock_net(sk), sk, msg, &fl6, &ipc6);
 		if (err < 0)
 			return err;
 
 		/* Changes to txoptions and flow info are not implemented, yet.
-		 * Drop the options, fl6 is wiped below.
+		 * Drop the options.
 		 */
 		ipc6.opt = NULL;
 	}
 
-	memset(&fl6, 0, sizeof(fl6));
-
 	fl6.flowi6_proto = IPPROTO_ICMPV6;
 	fl6.saddr = np->saddr;
 	fl6.daddr = *daddr;