diff options
author | Hannes Frederic Sowa <hannes@stressinduktion.org> | 2014-02-18 15:38:08 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-02-19 16:28:42 -0500 |
commit | c8e6ad0829a723a74cd2fea9996a3392d2579a18 (patch) | |
tree | 370dd2b5d5ad64cabef6fa837aac4ca8a1b9a958 /net/ipv4 | |
parent | 21f374c6cfbf98c1efceee0b528ce784d215935c (diff) |
ipv6: honor IPV6_PKTINFO with v4 mapped addresses on sendmsg
In case we decide in udp6_sendmsg to send the packet down the ipv4
udp_sendmsg path because the destination is either of family AF_INET or
the destination is an ipv4 mapped ipv6 address, we don't honor the
maybe specified ipv4 mapped ipv6 address in IPV6_PKTINFO.
We simply can check for this option in ip_cmsg_send because no calls to
ipv6 module functions are needed to do so.
Reported-by: Gert Doering <gert@space.net>
Cc: Tore Anderson <tore@fud.no>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r-- | net/ipv4/ip_sockglue.c | 19 | ||||
-rw-r--r-- | net/ipv4/ping.c | 2 | ||||
-rw-r--r-- | net/ipv4/raw.c | 2 | ||||
-rw-r--r-- | net/ipv4/udp.c | 3 |
4 files changed, 22 insertions, 4 deletions
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c index 580dd96666e0..0968b28c4cf3 100644 --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c | |||
@@ -186,7 +186,8 @@ void ip_cmsg_recv(struct msghdr *msg, struct sk_buff *skb) | |||
186 | } | 186 | } |
187 | EXPORT_SYMBOL(ip_cmsg_recv); | 187 | EXPORT_SYMBOL(ip_cmsg_recv); |
188 | 188 | ||
189 | int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc) | 189 | int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc, |
190 | bool allow_ipv6) | ||
190 | { | 191 | { |
191 | int err, val; | 192 | int err, val; |
192 | struct cmsghdr *cmsg; | 193 | struct cmsghdr *cmsg; |
@@ -194,6 +195,22 @@ int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc) | |||
194 | for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) { | 195 | for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) { |
195 | if (!CMSG_OK(msg, cmsg)) | 196 | if (!CMSG_OK(msg, cmsg)) |
196 | return -EINVAL; | 197 | return -EINVAL; |
198 | #if defined(CONFIG_IPV6) | ||
199 | if (allow_ipv6 && | ||
200 | cmsg->cmsg_level == SOL_IPV6 && | ||
201 | cmsg->cmsg_type == IPV6_PKTINFO) { | ||
202 | struct in6_pktinfo *src_info; | ||
203 | |||
204 | if (cmsg->cmsg_len < CMSG_LEN(sizeof(*src_info))) | ||
205 | return -EINVAL; | ||
206 | src_info = (struct in6_pktinfo *)CMSG_DATA(cmsg); | ||
207 | if (!ipv6_addr_v4mapped(&src_info->ipi6_addr)) | ||
208 | return -EINVAL; | ||
209 | ipc->oif = src_info->ipi6_ifindex; | ||
210 | ipc->addr = src_info->ipi6_addr.s6_addr32[3]; | ||
211 | continue; | ||
212 | } | ||
213 | #endif | ||
197 | if (cmsg->cmsg_level != SOL_IP) | 214 | if (cmsg->cmsg_level != SOL_IP) |
198 | continue; | 215 | continue; |
199 | switch (cmsg->cmsg_type) { | 216 | switch (cmsg->cmsg_type) { |
diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c index 2d11c094296e..f4b19e5dde54 100644 --- a/net/ipv4/ping.c +++ b/net/ipv4/ping.c | |||
@@ -727,7 +727,7 @@ static int ping_v4_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m | |||
727 | sock_tx_timestamp(sk, &ipc.tx_flags); | 727 | sock_tx_timestamp(sk, &ipc.tx_flags); |
728 | 728 | ||
729 | if (msg->msg_controllen) { | 729 | if (msg->msg_controllen) { |
730 | err = ip_cmsg_send(sock_net(sk), msg, &ipc); | 730 | err = ip_cmsg_send(sock_net(sk), msg, &ipc, false); |
731 | if (err) | 731 | if (err) |
732 | return err; | 732 | return err; |
733 | if (ipc.opt) | 733 | if (ipc.opt) |
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index c04518f4850a..a9dbe58bdfe7 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c | |||
@@ -524,7 +524,7 @@ static int raw_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, | |||
524 | ipc.oif = sk->sk_bound_dev_if; | 524 | ipc.oif = sk->sk_bound_dev_if; |
525 | 525 | ||
526 | if (msg->msg_controllen) { | 526 | if (msg->msg_controllen) { |
527 | err = ip_cmsg_send(sock_net(sk), msg, &ipc); | 527 | err = ip_cmsg_send(sock_net(sk), msg, &ipc, false); |
528 | if (err) | 528 | if (err) |
529 | goto out; | 529 | goto out; |
530 | if (ipc.opt) | 530 | if (ipc.opt) |
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 77bd16fa9f34..4468e1adc094 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c | |||
@@ -931,7 +931,8 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, | |||
931 | sock_tx_timestamp(sk, &ipc.tx_flags); | 931 | sock_tx_timestamp(sk, &ipc.tx_flags); |
932 | 932 | ||
933 | if (msg->msg_controllen) { | 933 | if (msg->msg_controllen) { |
934 | err = ip_cmsg_send(sock_net(sk), msg, &ipc); | 934 | err = ip_cmsg_send(sock_net(sk), msg, &ipc, |
935 | sk->sk_family == AF_INET6); | ||
935 | if (err) | 936 | if (err) |
936 | return err; | 937 | return err; |
937 | if (ipc.opt) | 938 | if (ipc.opt) |