diff options
author | Pavel Emelyanov <xemul@openvz.org> | 2008-03-22 19:51:21 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-03-22 19:51:21 -0400 |
commit | 6ba5a3c52da00015e739469e3b00cd6d0d4c5c67 (patch) | |
tree | 0cbccb2dac9307cec25176eb94ff4f406a2061f7 | |
parent | 39d8cda76cfb1178455f9d196b39e773878e6c05 (diff) |
[UDP]: Make full use of proto.h.udp_hash innovation.
After this we have only udp_lib_get_port to get the port and two
stubs for ipv4 and ipv6. No difference in udp and udplite except
for initialized h.udp_hash member.
I tried to find a graceful way to drop the only difference between
udp_v4_get_port and udp_v6_get_port (i.e. the rcv_saddr comparison
routine), but adding one more callback on the struct proto didn't
appear such :( Maybe later.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/net/udp.h | 2 | ||||
-rw-r--r-- | net/ipv4/udp.c | 22 | ||||
-rw-r--r-- | net/ipv4/udp_impl.h | 6 | ||||
-rw-r--r-- | net/ipv4/udplite.c | 15 | ||||
-rw-r--r-- | net/ipv6/udp.c | 5 | ||||
-rw-r--r-- | net/ipv6/udp_impl.h | 2 | ||||
-rw-r--r-- | net/ipv6/udplite.c | 8 |
7 files changed, 20 insertions, 40 deletions
diff --git a/include/net/udp.h b/include/net/udp.h index b4cbdce883d1..635940d374ab 100644 --- a/include/net/udp.h +++ b/include/net/udp.h | |||
@@ -125,6 +125,8 @@ static inline void udp_lib_close(struct sock *sk, long timeout) | |||
125 | sk_common_release(sk); | 125 | sk_common_release(sk); |
126 | } | 126 | } |
127 | 127 | ||
128 | extern int udp_lib_get_port(struct sock *sk, unsigned short snum, | ||
129 | int (*)(const struct sock*,const struct sock*)); | ||
128 | 130 | ||
129 | /* net/ipv4/udp.c */ | 131 | /* net/ipv4/udp.c */ |
130 | extern int udp_get_port(struct sock *sk, unsigned short snum, | 132 | extern int udp_get_port(struct sock *sk, unsigned short snum, |
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index fa946829d1e8..8c1f5eaafcd2 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c | |||
@@ -143,18 +143,17 @@ static inline int __udp_lib_lport_inuse(struct net *net, __u16 num, | |||
143 | } | 143 | } |
144 | 144 | ||
145 | /** | 145 | /** |
146 | * __udp_lib_get_port - UDP/-Lite port lookup for IPv4 and IPv6 | 146 | * udp_lib_get_port - UDP/-Lite port lookup for IPv4 and IPv6 |
147 | * | 147 | * |
148 | * @sk: socket struct in question | 148 | * @sk: socket struct in question |
149 | * @snum: port number to look up | 149 | * @snum: port number to look up |
150 | * @udptable: hash list table, must be of UDP_HTABLE_SIZE | ||
151 | * @saddr_comp: AF-dependent comparison of bound local IP addresses | 150 | * @saddr_comp: AF-dependent comparison of bound local IP addresses |
152 | */ | 151 | */ |
153 | int __udp_lib_get_port(struct sock *sk, unsigned short snum, | 152 | int udp_lib_get_port(struct sock *sk, unsigned short snum, |
154 | struct hlist_head udptable[], | ||
155 | int (*saddr_comp)(const struct sock *sk1, | 153 | int (*saddr_comp)(const struct sock *sk1, |
156 | const struct sock *sk2 ) ) | 154 | const struct sock *sk2 ) ) |
157 | { | 155 | { |
156 | struct hlist_head *udptable = sk->sk_prot->h.udp_hash; | ||
158 | struct hlist_node *node; | 157 | struct hlist_node *node; |
159 | struct hlist_head *head; | 158 | struct hlist_head *head; |
160 | struct sock *sk2; | 159 | struct sock *sk2; |
@@ -240,13 +239,7 @@ fail: | |||
240 | return error; | 239 | return error; |
241 | } | 240 | } |
242 | 241 | ||
243 | int udp_get_port(struct sock *sk, unsigned short snum, | 242 | static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2) |
244 | int (*scmp)(const struct sock *, const struct sock *)) | ||
245 | { | ||
246 | return __udp_lib_get_port(sk, snum, udp_hash, scmp); | ||
247 | } | ||
248 | |||
249 | int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2) | ||
250 | { | 243 | { |
251 | struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2); | 244 | struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2); |
252 | 245 | ||
@@ -255,9 +248,9 @@ int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2) | |||
255 | inet1->rcv_saddr == inet2->rcv_saddr )); | 248 | inet1->rcv_saddr == inet2->rcv_saddr )); |
256 | } | 249 | } |
257 | 250 | ||
258 | static inline int udp_v4_get_port(struct sock *sk, unsigned short snum) | 251 | int udp_v4_get_port(struct sock *sk, unsigned short snum) |
259 | { | 252 | { |
260 | return udp_get_port(sk, snum, ipv4_rcv_saddr_equal); | 253 | return udp_lib_get_port(sk, snum, ipv4_rcv_saddr_equal); |
261 | } | 254 | } |
262 | 255 | ||
263 | /* UDP is nearly always wildcards out the wazoo, it makes no sense to try | 256 | /* UDP is nearly always wildcards out the wazoo, it makes no sense to try |
@@ -1498,6 +1491,7 @@ struct proto udp_prot = { | |||
1498 | .sysctl_wmem = &sysctl_udp_wmem_min, | 1491 | .sysctl_wmem = &sysctl_udp_wmem_min, |
1499 | .sysctl_rmem = &sysctl_udp_rmem_min, | 1492 | .sysctl_rmem = &sysctl_udp_rmem_min, |
1500 | .obj_size = sizeof(struct udp_sock), | 1493 | .obj_size = sizeof(struct udp_sock), |
1494 | .h.udp_hash = udp_hash, | ||
1501 | #ifdef CONFIG_COMPAT | 1495 | #ifdef CONFIG_COMPAT |
1502 | .compat_setsockopt = compat_udp_setsockopt, | 1496 | .compat_setsockopt = compat_udp_setsockopt, |
1503 | .compat_getsockopt = compat_udp_getsockopt, | 1497 | .compat_getsockopt = compat_udp_getsockopt, |
@@ -1741,12 +1735,12 @@ EXPORT_SYMBOL(udp_disconnect); | |||
1741 | EXPORT_SYMBOL(udp_hash); | 1735 | EXPORT_SYMBOL(udp_hash); |
1742 | EXPORT_SYMBOL(udp_hash_lock); | 1736 | EXPORT_SYMBOL(udp_hash_lock); |
1743 | EXPORT_SYMBOL(udp_ioctl); | 1737 | EXPORT_SYMBOL(udp_ioctl); |
1744 | EXPORT_SYMBOL(udp_get_port); | ||
1745 | EXPORT_SYMBOL(udp_prot); | 1738 | EXPORT_SYMBOL(udp_prot); |
1746 | EXPORT_SYMBOL(udp_sendmsg); | 1739 | EXPORT_SYMBOL(udp_sendmsg); |
1747 | EXPORT_SYMBOL(udp_lib_getsockopt); | 1740 | EXPORT_SYMBOL(udp_lib_getsockopt); |
1748 | EXPORT_SYMBOL(udp_lib_setsockopt); | 1741 | EXPORT_SYMBOL(udp_lib_setsockopt); |
1749 | EXPORT_SYMBOL(udp_poll); | 1742 | EXPORT_SYMBOL(udp_poll); |
1743 | EXPORT_SYMBOL(udp_lib_get_port); | ||
1750 | 1744 | ||
1751 | #ifdef CONFIG_PROC_FS | 1745 | #ifdef CONFIG_PROC_FS |
1752 | EXPORT_SYMBOL(udp_proc_register); | 1746 | EXPORT_SYMBOL(udp_proc_register); |
diff --git a/net/ipv4/udp_impl.h b/net/ipv4/udp_impl.h index 6c55828e41ba..7288bf7977fb 100644 --- a/net/ipv4/udp_impl.h +++ b/net/ipv4/udp_impl.h | |||
@@ -8,11 +8,7 @@ | |||
8 | extern int __udp4_lib_rcv(struct sk_buff *, struct hlist_head [], int ); | 8 | extern int __udp4_lib_rcv(struct sk_buff *, struct hlist_head [], int ); |
9 | extern void __udp4_lib_err(struct sk_buff *, u32, struct hlist_head []); | 9 | extern void __udp4_lib_err(struct sk_buff *, u32, struct hlist_head []); |
10 | 10 | ||
11 | extern int __udp_lib_get_port(struct sock *sk, unsigned short snum, | 11 | extern int udp_v4_get_port(struct sock *sk, unsigned short snum); |
12 | struct hlist_head udptable[], | ||
13 | int (*)(const struct sock*,const struct sock*)); | ||
14 | extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *); | ||
15 | |||
16 | 12 | ||
17 | extern int udp_setsockopt(struct sock *sk, int level, int optname, | 13 | extern int udp_setsockopt(struct sock *sk, int level, int optname, |
18 | char __user *optval, int optlen); | 14 | char __user *optval, int optlen); |
diff --git a/net/ipv4/udplite.c b/net/ipv4/udplite.c index 2469b5104587..8d42e344b043 100644 --- a/net/ipv4/udplite.c +++ b/net/ipv4/udplite.c | |||
@@ -17,17 +17,6 @@ DEFINE_SNMP_STAT(struct udp_mib, udplite_statistics) __read_mostly; | |||
17 | 17 | ||
18 | struct hlist_head udplite_hash[UDP_HTABLE_SIZE]; | 18 | struct hlist_head udplite_hash[UDP_HTABLE_SIZE]; |
19 | 19 | ||
20 | int udplite_get_port(struct sock *sk, unsigned short p, | ||
21 | int (*c)(const struct sock *, const struct sock *)) | ||
22 | { | ||
23 | return __udp_lib_get_port(sk, p, udplite_hash, c); | ||
24 | } | ||
25 | |||
26 | static int udplite_v4_get_port(struct sock *sk, unsigned short snum) | ||
27 | { | ||
28 | return udplite_get_port(sk, snum, ipv4_rcv_saddr_equal); | ||
29 | } | ||
30 | |||
31 | static int udplite_rcv(struct sk_buff *skb) | 20 | static int udplite_rcv(struct sk_buff *skb) |
32 | { | 21 | { |
33 | return __udp4_lib_rcv(skb, udplite_hash, IPPROTO_UDPLITE); | 22 | return __udp4_lib_rcv(skb, udplite_hash, IPPROTO_UDPLITE); |
@@ -63,8 +52,9 @@ struct proto udplite_prot = { | |||
63 | .backlog_rcv = udp_queue_rcv_skb, | 52 | .backlog_rcv = udp_queue_rcv_skb, |
64 | .hash = udp_lib_hash, | 53 | .hash = udp_lib_hash, |
65 | .unhash = udp_lib_unhash, | 54 | .unhash = udp_lib_unhash, |
66 | .get_port = udplite_v4_get_port, | 55 | .get_port = udp_v4_get_port, |
67 | .obj_size = sizeof(struct udp_sock), | 56 | .obj_size = sizeof(struct udp_sock), |
57 | .h.udp_hash = udplite_hash, | ||
68 | #ifdef CONFIG_COMPAT | 58 | #ifdef CONFIG_COMPAT |
69 | .compat_setsockopt = compat_udp_setsockopt, | 59 | .compat_setsockopt = compat_udp_setsockopt, |
70 | .compat_getsockopt = compat_udp_getsockopt, | 60 | .compat_getsockopt = compat_udp_getsockopt, |
@@ -118,4 +108,3 @@ out_register_err: | |||
118 | 108 | ||
119 | EXPORT_SYMBOL(udplite_hash); | 109 | EXPORT_SYMBOL(udplite_hash); |
120 | EXPORT_SYMBOL(udplite_prot); | 110 | EXPORT_SYMBOL(udplite_prot); |
121 | EXPORT_SYMBOL(udplite_get_port); | ||
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c index af619d48ba80..5f5d1218c34e 100644 --- a/net/ipv6/udp.c +++ b/net/ipv6/udp.c | |||
@@ -51,9 +51,9 @@ | |||
51 | #include <linux/seq_file.h> | 51 | #include <linux/seq_file.h> |
52 | #include "udp_impl.h" | 52 | #include "udp_impl.h" |
53 | 53 | ||
54 | static inline int udp_v6_get_port(struct sock *sk, unsigned short snum) | 54 | int udp_v6_get_port(struct sock *sk, unsigned short snum) |
55 | { | 55 | { |
56 | return udp_get_port(sk, snum, ipv6_rcv_saddr_equal); | 56 | return udp_lib_get_port(sk, snum, ipv6_rcv_saddr_equal); |
57 | } | 57 | } |
58 | 58 | ||
59 | static struct sock *__udp6_lib_lookup(struct net *net, | 59 | static struct sock *__udp6_lib_lookup(struct net *net, |
@@ -1024,6 +1024,7 @@ struct proto udpv6_prot = { | |||
1024 | .sysctl_wmem = &sysctl_udp_wmem_min, | 1024 | .sysctl_wmem = &sysctl_udp_wmem_min, |
1025 | .sysctl_rmem = &sysctl_udp_rmem_min, | 1025 | .sysctl_rmem = &sysctl_udp_rmem_min, |
1026 | .obj_size = sizeof(struct udp6_sock), | 1026 | .obj_size = sizeof(struct udp6_sock), |
1027 | .h.udp_hash = udp_hash, | ||
1027 | #ifdef CONFIG_COMPAT | 1028 | #ifdef CONFIG_COMPAT |
1028 | .compat_setsockopt = compat_udpv6_setsockopt, | 1029 | .compat_setsockopt = compat_udpv6_setsockopt, |
1029 | .compat_getsockopt = compat_udpv6_getsockopt, | 1030 | .compat_getsockopt = compat_udpv6_getsockopt, |
diff --git a/net/ipv6/udp_impl.h b/net/ipv6/udp_impl.h index 21be3a83e7bc..321b81a4d418 100644 --- a/net/ipv6/udp_impl.h +++ b/net/ipv6/udp_impl.h | |||
@@ -11,6 +11,8 @@ extern int __udp6_lib_rcv(struct sk_buff *, struct hlist_head [], int ); | |||
11 | extern void __udp6_lib_err(struct sk_buff *, struct inet6_skb_parm *, | 11 | extern void __udp6_lib_err(struct sk_buff *, struct inet6_skb_parm *, |
12 | int , int , int , __be32 , struct hlist_head []); | 12 | int , int , int , __be32 , struct hlist_head []); |
13 | 13 | ||
14 | extern int udp_v6_get_port(struct sock *sk, unsigned short snum); | ||
15 | |||
14 | extern int udpv6_getsockopt(struct sock *sk, int level, int optname, | 16 | extern int udpv6_getsockopt(struct sock *sk, int level, int optname, |
15 | char __user *optval, int __user *optlen); | 17 | char __user *optval, int __user *optlen); |
16 | extern int udpv6_setsockopt(struct sock *sk, int level, int optname, | 18 | extern int udpv6_setsockopt(struct sock *sk, int level, int optname, |
diff --git a/net/ipv6/udplite.c b/net/ipv6/udplite.c index 815190be528c..93e52e0d57f2 100644 --- a/net/ipv6/udplite.c +++ b/net/ipv6/udplite.c | |||
@@ -35,11 +35,6 @@ static struct inet6_protocol udplitev6_protocol = { | |||
35 | .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL, | 35 | .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL, |
36 | }; | 36 | }; |
37 | 37 | ||
38 | static int udplite_v6_get_port(struct sock *sk, unsigned short snum) | ||
39 | { | ||
40 | return udplite_get_port(sk, snum, ipv6_rcv_saddr_equal); | ||
41 | } | ||
42 | |||
43 | DEFINE_PROTO_INUSE(udplitev6) | 38 | DEFINE_PROTO_INUSE(udplitev6) |
44 | 39 | ||
45 | struct proto udplitev6_prot = { | 40 | struct proto udplitev6_prot = { |
@@ -58,8 +53,9 @@ struct proto udplitev6_prot = { | |||
58 | .backlog_rcv = udpv6_queue_rcv_skb, | 53 | .backlog_rcv = udpv6_queue_rcv_skb, |
59 | .hash = udp_lib_hash, | 54 | .hash = udp_lib_hash, |
60 | .unhash = udp_lib_unhash, | 55 | .unhash = udp_lib_unhash, |
61 | .get_port = udplite_v6_get_port, | 56 | .get_port = udp_v6_get_port, |
62 | .obj_size = sizeof(struct udp6_sock), | 57 | .obj_size = sizeof(struct udp6_sock), |
58 | .h.udp_hash = udplite_hash, | ||
63 | #ifdef CONFIG_COMPAT | 59 | #ifdef CONFIG_COMPAT |
64 | .compat_setsockopt = compat_udpv6_setsockopt, | 60 | .compat_setsockopt = compat_udpv6_setsockopt, |
65 | .compat_getsockopt = compat_udpv6_getsockopt, | 61 | .compat_getsockopt = compat_udpv6_getsockopt, |