diff options
-rw-r--r-- | include/net/addrconf.h | 4 | ||||
-rw-r--r-- | include/net/udp.h | 2 | ||||
-rw-r--r-- | net/ipv4/udp.c | 3 | ||||
-rw-r--r-- | net/ipv6/addrconf.c | 34 | ||||
-rw-r--r-- | net/ipv6/udp.c | 28 |
5 files changed, 34 insertions, 37 deletions
diff --git a/include/net/addrconf.h b/include/net/addrconf.h index c216de528b08..7b55ab215a64 100644 --- a/include/net/addrconf.h +++ b/include/net/addrconf.h | |||
@@ -88,8 +88,8 @@ extern int ipv6_dev_get_saddr(struct net *net, | |||
88 | extern int ipv6_get_lladdr(struct net_device *dev, | 88 | extern int ipv6_get_lladdr(struct net_device *dev, |
89 | struct in6_addr *addr, | 89 | struct in6_addr *addr, |
90 | unsigned char banned_flags); | 90 | unsigned char banned_flags); |
91 | extern int ipv6_rcv_saddr_equal(const struct sock *sk, | 91 | extern int ipv6_rcv_saddr_equal(const struct sock *sk, |
92 | const struct sock *sk2); | 92 | const struct sock *sk2); |
93 | extern void addrconf_join_solict(struct net_device *dev, | 93 | extern void addrconf_join_solict(struct net_device *dev, |
94 | struct in6_addr *addr); | 94 | struct in6_addr *addr); |
95 | extern void addrconf_leave_solict(struct inet6_dev *idev, | 95 | extern void addrconf_leave_solict(struct inet6_dev *idev, |
diff --git a/include/net/udp.h b/include/net/udp.h index 90e6ce56be65..93dbe294d459 100644 --- a/include/net/udp.h +++ b/include/net/udp.h | |||
@@ -124,6 +124,8 @@ static inline void udp_lib_close(struct sock *sk, long timeout) | |||
124 | sk_common_release(sk); | 124 | sk_common_release(sk); |
125 | } | 125 | } |
126 | 126 | ||
127 | extern int ipv4_rcv_saddr_equal(const struct sock *sk1, | ||
128 | const struct sock *sk2); | ||
127 | extern int udp_lib_get_port(struct sock *sk, unsigned short snum, | 129 | extern int udp_lib_get_port(struct sock *sk, unsigned short snum, |
128 | int (*)(const struct sock*,const struct sock*)); | 130 | int (*)(const struct sock*,const struct sock*)); |
129 | 131 | ||
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 05b7abb99f69..ace2ac8a42f7 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c | |||
@@ -222,7 +222,7 @@ fail: | |||
222 | return error; | 222 | return error; |
223 | } | 223 | } |
224 | 224 | ||
225 | static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2) | 225 | int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2) |
226 | { | 226 | { |
227 | struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2); | 227 | struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2); |
228 | 228 | ||
@@ -1819,6 +1819,7 @@ EXPORT_SYMBOL(udp_lib_getsockopt); | |||
1819 | EXPORT_SYMBOL(udp_lib_setsockopt); | 1819 | EXPORT_SYMBOL(udp_lib_setsockopt); |
1820 | EXPORT_SYMBOL(udp_poll); | 1820 | EXPORT_SYMBOL(udp_poll); |
1821 | EXPORT_SYMBOL(udp_lib_get_port); | 1821 | EXPORT_SYMBOL(udp_lib_get_port); |
1822 | EXPORT_SYMBOL(ipv4_rcv_saddr_equal); | ||
1822 | 1823 | ||
1823 | #ifdef CONFIG_PROC_FS | 1824 | #ifdef CONFIG_PROC_FS |
1824 | EXPORT_SYMBOL(udp_proc_register); | 1825 | EXPORT_SYMBOL(udp_proc_register); |
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 8499da9e76a2..a8218bc1806a 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c | |||
@@ -1370,40 +1370,6 @@ struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, const struct in6_addr *add | |||
1370 | return ifp; | 1370 | return ifp; |
1371 | } | 1371 | } |
1372 | 1372 | ||
1373 | int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2) | ||
1374 | { | ||
1375 | const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr; | ||
1376 | const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2); | ||
1377 | __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr; | ||
1378 | __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2); | ||
1379 | int sk_ipv6only = ipv6_only_sock(sk); | ||
1380 | int sk2_ipv6only = inet_v6_ipv6only(sk2); | ||
1381 | int addr_type = ipv6_addr_type(sk_rcv_saddr6); | ||
1382 | int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED; | ||
1383 | |||
1384 | if (!sk2_rcv_saddr && !sk_ipv6only) | ||
1385 | return 1; | ||
1386 | |||
1387 | if (addr_type2 == IPV6_ADDR_ANY && | ||
1388 | !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED)) | ||
1389 | return 1; | ||
1390 | |||
1391 | if (addr_type == IPV6_ADDR_ANY && | ||
1392 | !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED)) | ||
1393 | return 1; | ||
1394 | |||
1395 | if (sk2_rcv_saddr6 && | ||
1396 | ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6)) | ||
1397 | return 1; | ||
1398 | |||
1399 | if (addr_type == IPV6_ADDR_MAPPED && | ||
1400 | !sk2_ipv6only && | ||
1401 | (!sk2_rcv_saddr || !sk_rcv_saddr || sk_rcv_saddr == sk2_rcv_saddr)) | ||
1402 | return 1; | ||
1403 | |||
1404 | return 0; | ||
1405 | } | ||
1406 | |||
1407 | /* Gets referenced address, destroys ifaddr */ | 1373 | /* Gets referenced address, destroys ifaddr */ |
1408 | 1374 | ||
1409 | static void addrconf_dad_stop(struct inet6_ifaddr *ifp) | 1375 | static void addrconf_dad_stop(struct inet6_ifaddr *ifp) |
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index 84b1a296eecb..6842dd2edd5b 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c | |||
@@ -49,6 +49,34 @@ | |||
49 | #include <linux/seq_file.h> | 49 | #include <linux/seq_file.h> |
50 | #include "udp_impl.h" | 50 | #include "udp_impl.h" |
51 | 51 | ||
52 | int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2) | ||
53 | { | ||
54 | const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr; | ||
55 | const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2); | ||
56 | int sk_ipv6only = ipv6_only_sock(sk); | ||
57 | int sk2_ipv6only = inet_v6_ipv6only(sk2); | ||
58 | int addr_type = ipv6_addr_type(sk_rcv_saddr6); | ||
59 | int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED; | ||
60 | |||
61 | /* if both are mapped, treat as IPv4 */ | ||
62 | if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) | ||
63 | return ipv4_rcv_saddr_equal(sk, sk2); | ||
64 | |||
65 | if (addr_type2 == IPV6_ADDR_ANY && | ||
66 | !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED)) | ||
67 | return 1; | ||
68 | |||
69 | if (addr_type == IPV6_ADDR_ANY && | ||
70 | !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED)) | ||
71 | return 1; | ||
72 | |||
73 | if (sk2_rcv_saddr6 && | ||
74 | ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6)) | ||
75 | return 1; | ||
76 | |||
77 | return 0; | ||
78 | } | ||
79 | |||
52 | int udp_v6_get_port(struct sock *sk, unsigned short snum) | 80 | int udp_v6_get_port(struct sock *sk, unsigned short snum) |
53 | { | 81 | { |
54 | return udp_lib_get_port(sk, snum, ipv6_rcv_saddr_equal); | 82 | return udp_lib_get_port(sk, snum, ipv6_rcv_saddr_equal); |