: Fix up AF-specific references in UDP
Subsystems (3)
David Miller
maintainerPATCH 1/1 : Fix up AF-specific references in UDP
As noticed we make some ipv4-specific references in the generic UDP code, I've fixed that up completely below.
This should fix ipv6 and it should be fully functional.
There is enough infrastructure there to write up the non-wildcard IPV6 hashing support. Eric and Yoshifuji had some ideas about how to hash the rcv_saddr so I will leave those bits to them :-)
It is very easy, just add the appropriate hashing to ipv6_hash_port_and_rcv_addr(), then add the lookup logic to the ipv6 UDP socket demux for unicast and multicast to match the ipv4 equivalent code.
Meanwhile I'll push this patch below to Linus so that IPV6 isn't broken.
commit 30959ab670629ac857d04c7bc87df422fc941ec9
Author: David S. Miller <[email protected]> Date: Wed May 9 16:42:20 2007 -0700
[UDP]: Fix AF-specific references in AF-agnostic code.
__udp_lib_port_inuse() cannot make direct references to inet_sk(sk)->rcv_saddr as that is ipv4 specific state and this code is used by ipv6 too.
Use an operations vector to solve this, and this also paves the way for ipv6 support for non-wild saddr hashing in UDP.
include/net/udp.h +8 -1
@@ -119,9 +119,16 @@ static inline void udp_lib_close(struct sock *sk, long timeout) } +struct udp_get_port_ops { +int (*saddr_cmp)(const struct sock *sk1,const struct sock *sk2); +int (*saddr_any)(const struct sock *sk); +unsigned int (*hash_port_and_rcv_saddr)(__u16 port, +const struct sock *sk); +}; +/* net/ipv4/udp.c */ extern int udp_get_port (struct sock *sk,unsigned short snum, -int (*saddr_cmp)(const struct sock *,const struct sock *)); +const struct udp_get_port_ops *ops);extern void udp_err (struct sk_buff *,u32 ); extern int udp_sendmsg(struct kiocb *iocb, struct sock *sk,
include/net/udplite.h +1 -1
@@ -120,5 +120,5 @@ static inline __wsum udplite_csum_outgoing(struct sock *sk, struct sk_buff *skb)extern void udplite4_register (void );extern int udplite_get_port (struct sock *sk,unsigned short snum, -int (*scmp)(const struct sock *,const struct sock *)); +const struct udp_get_port_ops *ops);#endif /* _UDPLITE_H */
net/ipv4/udp.c +54 -31
176 lines not on this page · raw message
net/ipv4/udp_impl.h +3 -3
@@ -5,14 +5,14 @@#include <net/protocol.h> #include <net/inet_common.h> +extern const struct udp_get_port_ops udp_ipv4_ops; +extern int __udp4_lib_rcv (struct sk_buff *,struct hlist_head [],int );extern void __udp4_lib_err (struct sk_buff *,u32 ,struct hlist_head []);extern int __udp_lib_get_port (struct sock *sk,unsigned short snum,struct hlist_head udptable[],int *port_rover, -int (*)(const struct sock *,const struct sock *)); -extern int ipv4_rcv_saddr_equal (const struct sock *,const struct sock *); - +const struct udp_get_port_ops *ops);extern int udp_setsockopt (struct sock *sk,int level,int optname,char __user *optval,int optlen);
net/ipv4/udplite.c +4 -3
@@ -19,14 +19,15 @@ struct hlist_head udplite_hash[UDP_HTABLE_SIZE];static int udplite_port_rover;int udplite_get_port (struct sock *sk,unsigned short p, -int (*c)(const struct sock *,const struct sock *)) +const struct udp_get_port_ops *ops) { -return __udp_lib_get_port (sk, p, udplite_hash, &udplite_port_rover, c); +return __udp_lib_get_port (sk, p, udplite_hash, + &udplite_port_rover, ops); }static int udplite_v4_get_port (struct sock *sk,unsigned short snum) { -return udplite_get_port (sk, snum, ipv4_rcv_saddr_equal); +return udplite_get_port (sk, snum, &udp_ipv4_ops); }static int udplite_rcv (struct sk_buff *skb)
net/ipv6/udp.c +20 -1
@@ -52,9 +52,28 @@ DEFINE_SNMP_STAT(struct udp_mib, udp_stats_in6) __read_mostly; +static int ipv6_rcv_saddr_any (const struct sock *sk) +{ +struct ipv6_pinfo *np =inet6_sk (sk); + +return ipv6_addr_any (&np->rcv_saddr); +} + +static unsigned int ipv6_hash_port_and_rcv_saddr (__u16 port, +const struct sock *sk) +{ +return port; +} + +const struct udp_get_port_ops udp_ipv6_ops = { + .saddr_cmp = ipv6_rcv_saddr_equal, + .saddr_any = ipv6_rcv_saddr_any, + .hash_port_and_rcv_saddr = ipv6_hash_port_and_rcv_saddr, +}; +static inline int udp_v6_get_port (struct sock *sk,unsigned short snum) { -return udp_get_port (sk, snum, ipv6_rcv_saddr_equal); +return udp_get_port (sk, snum, &udp_ipv6_ops); } static struct sock *__udp6_lib_lookup(struct in6_addr *saddr, __be16 sport,
net/ipv6/udp_impl.h +2 -0
@@ -6,6 +6,8 @@#include <net/addrconf.h> #include <net/inet_common.h> +extern const struct udp_get_port_ops udp_ipv6_ops; +extern int __udp6_lib_rcv (struct sk_buff **,struct hlist_head [],int );extern void __udp6_lib_err (struct sk_buff *,struct inet6_skb_parm *,int ,int ,int ,__be32 ,struct hlist_head []);
net/ipv6/udplite.c +1 -1
@@ -37,7 +37,7 @@ static struct inet6_protocol udplitev6_protocol = {static int udplite_v6_get_port (struct sock *sk,unsigned short snum) { -return udplite_get_port (sk, snum, ipv6_rcv_saddr_equal); +return udplite_get_port (sk, snum, &udp_ipv6_ops); }struct proto udplitev6_prot = {