aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@openvz.org>2008-03-22 19:51:21 -0400
committerDavid S. Miller <davem@davemloft.net>2008-03-22 19:51:21 -0400
commit6ba5a3c52da00015e739469e3b00cd6d0d4c5c67 (patch)
tree0cbccb2dac9307cec25176eb94ff4f406a2061f7 /net
parent39d8cda76cfb1178455f9d196b39e773878e6c05 (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>
Diffstat (limited to 'net')
-rw-r--r--net/ipv4/udp.c22
-rw-r--r--net/ipv4/udp_impl.h6
-rw-r--r--net/ipv4/udplite.c15
-rw-r--r--net/ipv6/udp.c5
-rw-r--r--net/ipv6/udp_impl.h2
-rw-r--r--net/ipv6/udplite.c8
6 files changed, 18 insertions, 40 deletions
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 */
153int __udp_lib_get_port(struct sock *sk, unsigned short snum, 152int 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
243int udp_get_port(struct sock *sk, unsigned short snum, 242static 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
249int 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
258static inline int udp_v4_get_port(struct sock *sk, unsigned short snum) 251int 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);
1741EXPORT_SYMBOL(udp_hash); 1735EXPORT_SYMBOL(udp_hash);
1742EXPORT_SYMBOL(udp_hash_lock); 1736EXPORT_SYMBOL(udp_hash_lock);
1743EXPORT_SYMBOL(udp_ioctl); 1737EXPORT_SYMBOL(udp_ioctl);
1744EXPORT_SYMBOL(udp_get_port);
1745EXPORT_SYMBOL(udp_prot); 1738EXPORT_SYMBOL(udp_prot);
1746EXPORT_SYMBOL(udp_sendmsg); 1739EXPORT_SYMBOL(udp_sendmsg);
1747EXPORT_SYMBOL(udp_lib_getsockopt); 1740EXPORT_SYMBOL(udp_lib_getsockopt);
1748EXPORT_SYMBOL(udp_lib_setsockopt); 1741EXPORT_SYMBOL(udp_lib_setsockopt);
1749EXPORT_SYMBOL(udp_poll); 1742EXPORT_SYMBOL(udp_poll);
1743EXPORT_SYMBOL(udp_lib_get_port);
1750 1744
1751#ifdef CONFIG_PROC_FS 1745#ifdef CONFIG_PROC_FS
1752EXPORT_SYMBOL(udp_proc_register); 1746EXPORT_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 @@
8extern int __udp4_lib_rcv(struct sk_buff *, struct hlist_head [], int ); 8extern int __udp4_lib_rcv(struct sk_buff *, struct hlist_head [], int );
9extern void __udp4_lib_err(struct sk_buff *, u32, struct hlist_head []); 9extern void __udp4_lib_err(struct sk_buff *, u32, struct hlist_head []);
10 10
11extern int __udp_lib_get_port(struct sock *sk, unsigned short snum, 11extern int udp_v4_get_port(struct sock *sk, unsigned short snum);
12 struct hlist_head udptable[],
13 int (*)(const struct sock*,const struct sock*));
14extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
15
16 12
17extern int udp_setsockopt(struct sock *sk, int level, int optname, 13extern 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
18struct hlist_head udplite_hash[UDP_HTABLE_SIZE]; 18struct hlist_head udplite_hash[UDP_HTABLE_SIZE];
19 19
20int 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
26static 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
31static int udplite_rcv(struct sk_buff *skb) 20static 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
119EXPORT_SYMBOL(udplite_hash); 109EXPORT_SYMBOL(udplite_hash);
120EXPORT_SYMBOL(udplite_prot); 110EXPORT_SYMBOL(udplite_prot);
121EXPORT_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
54static inline int udp_v6_get_port(struct sock *sk, unsigned short snum) 54int 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
59static struct sock *__udp6_lib_lookup(struct net *net, 59static 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 );
11extern void __udp6_lib_err(struct sk_buff *, struct inet6_skb_parm *, 11extern 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
14extern int udp_v6_get_port(struct sock *sk, unsigned short snum);
15
14extern int udpv6_getsockopt(struct sock *sk, int level, int optname, 16extern int udpv6_getsockopt(struct sock *sk, int level, int optname,
15 char __user *optval, int __user *optlen); 17 char __user *optval, int __user *optlen);
16extern int udpv6_setsockopt(struct sock *sk, int level, int optname, 18extern 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
38static 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
43DEFINE_PROTO_INUSE(udplitev6) 38DEFINE_PROTO_INUSE(udplitev6)
44 39
45struct proto udplitev6_prot = { 40struct 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,