netdev
[Top] [All Lists]

Don't allow mapped address after binding to ipv4.

To: netdev@xxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxxx
Subject: Don't allow mapped address after binding to ipv4.
From: Hideaki YOSHIFUJI <yoshfuji@xxxxxxxxxxxxxx>
Date: Fri, 04 Aug 2000 12:22:57 +0900
Cc: linux-ipv6-jp@xxxxxxxxxxx
Sender: owner-netdev@xxxxxxxxxxx
Hi forks,

linux-2.2.16 and linux-2.4.0-test5 allow to let an application bind an 
inet6 socket sd6 to an address / a port that is already bound to inet 
socket sd4.  For example, the 2nd step below should fail.

 1. bind sd4 to 127.0.0.1
 2. bind sd6 to ::ffff:127.0.0.1

Here a patch to fix this problem (for 2.2.16; maybe for 2.4.0-test5).
Thanks in advance.

diff -u linux-2.2.16/net/ipv6/tcp_ipv6.c linux-2.2.16-fix/net/ipv6/tcp_ipv6.c
--- linux-2.2.16/net/ipv6/tcp_ipv6.c    Thu May  4 09:16:53 2000
+++ linux-2.2.16-fix/net/ipv6/tcp_ipv6.c        Fri Aug  4 01:08:18 2000
@@ -140,7 +140,12 @@
                                                    
!ipv6_addr_cmp(&sk->net_pinfo.af_inet6.rcv_saddr,
                                                                   sk2->state 
!= TCP_TIME_WAIT ?
                                                                   
&sk2->net_pinfo.af_inet6.rcv_saddr :
-                                                                  &((struct 
tcp_tw_bucket*)sk)->v6_rcv_saddr))
+                                                                  &((struct 
tcp_tw_bucket*)sk)->v6_rcv_saddr) ||
+                                                   (addr_type == 
IPV6_ADDR_MAPPED && sk2->family == AF_INET &&
+                                                    sk->rcv_saddr == 
(sk2->state != TCP_TIME_WAIT ?
+                                                       sk2->rcv_saddr : 
((struct tcp_tw_bucket*)sk)->rcv_saddr)
+                                                    )
+                                                   )
                                                        break;
                                        }
                                }
diff -u linux-2.2.16/net/ipv6/udp.c linux-2.2.16-fix/net/ipv6/udp.c
--- linux-2.2.16/net/ipv6/udp.c Tue Aug 10 04:04:41 1999
+++ linux-2.2.16-fix/net/ipv6/udp.c     Fri Aug  4 11:29:24 2000
@@ -105,7 +105,9 @@
                            (!sk2->rcv_saddr ||
                             addr_type == IPV6_ADDR_ANY ||
                             !ipv6_addr_cmp(&sk->net_pinfo.af_inet6.rcv_saddr,
-                                           
&sk2->net_pinfo.af_inet6.rcv_saddr)) &&
+                                           &sk2->net_pinfo.af_inet6.rcv_saddr) 
||
+                            (addr_type == IPV6_ADDR_MAPPED && sk2->family == 
AF_INET &&
+                             sk->rcv_saddr == sk2->rcv_saddr)) &&
                            (!sk2->reuse || !sk->reuse))
                                goto fail;
                }

-- 
Hideaki YOSHIFUJI @ USAGI Project  <yoshfuji@xxxxxxxxxxxxxx>
Web Page: http://www.ecei.tohoku.ac.jp/%7Eyoshfuji/
PGP5i FP: F731 6599 5EB2 BBA7 1515  1323 1806 A96F 5700 6B25 

<Prev in Thread] Current Thread [Next in Thread>