: consolidate v4 and v6 get|setsockopt code
Subsystems (3)
PATCH 1/1 : consolidate v4 and v6 get|setsockopt code
[UDP(-Lite)]: consolidate v4 and v6 get|setsockopt code
This is for 2.6.20.
This patch consolidates set/getsockopt code between UDP(-Lite) v4 and 6. The justification is that UDP(-Lite) is a transport-layer protocol and therefore the socket option code (at least in theory) should be AF-independent.
Furthermore, there is the following code reduplication:
* do_udp{,v6}_getsockopt is 100% identical between v4 and v6
* do_udp{,v6}_setsockopt is identical up to the following differerence --v4 in contrast to v4 additionally allows the experimental encapsulation types UDP_ENCAP_ESPINUDP and UDP_ENCAP_ESPINUDP_NON_IKE --the remainder is identical between v4 and v6
I believe that this difference is of little relevance.
The advantages in not duplicating twice almost completely identical code.
The patch further simplifies the interface of udp{,v6}_push_pending_frames, since for the second argument (struct udp_sock *up) it always holds that up = udp_sk(sk); where sk is the first function argument.
--- include/net/udp.h | 5 ++ net/ipv4/udp.c | 30 ++++++++----- net/ipv6/udp.c | 118 ++++-------------------------------------------------- 3 files changed, 32 insertions(+), 121 deletions(-)
include/net/udp.h +5 -0
@@ -134,6 +134,11 @@ extern int udp_ioctl(struct sock *sk, inextern int udp_disconnect (struct sock *sk,int flags);extern unsigned int udp_poll (struct file *file,struct socket *sock,poll_table *wait); +extern int udp_lib_getsockopt (struct sock *sk,int level,int optname, +char __user *optval,int __user *optlen); +extern int udp_lib_setsockopt (struct sock *sk,int level,int optname, +char __user *optval,int optlen, +int (*push_pending_frames)(struct sock *)); DECLARE_SNMP_STAT(struct udp_mib, udp_statistics);/*
net/ipv4/udp.c +18 -12
@@ -448,8 +448,9 @@ static void udp4_hwcsum_outgoing(struct/* * Push out all pending data as one UDP datagram. Socket is locked. */ -static int udp_push_pending_frames (struct sock *sk,struct udp_sock *up) +static int udp_push_pending_frames (struct sock *sk) { +struct udp_sock *up =udp_sk (sk);struct inet_sock *inet =inet_sk (sk);struct flowi *fl = &inet->cork.fl;struct sk_buff *skb;
@@ -673,7 +674,7 @@ do_append_data:if (err)udp_flush_pending_frames (sk);else if (!corkreq) - err =udp_push_pending_frames (sk, up); + err =udp_push_pending_frames (sk);else if (unlikely (skb_queue_empty (&sk->sk_write_queue))) up->pending =0 ;release_sock (sk);
@@ -746,7 +747,7 @@ int udp_sendpage(struct sock *sk, struct up->len += size;if (!(up->corkflag || (flags&MSG_MORE ))) - ret =udp_push_pending_frames (sk, up); + ret =udp_push_pending_frames (sk);if (!ret) ret = size; out:
@@ -1290,8 +1291,9 @@ int udp_destroy_sock(struct sock *sk)/* * Socket option code for UDP */ -static int do_udp_setsockopt (struct sock *sk,int level,int optname, -char __user *optval,int optlen) +int udp_lib_setsockopt (struct sock *sk,int level,int optname, +char __user *optval,int optlen, +int (*push_pending_frames)(struct sock *)) {struct udp_sock *up =udp_sk (sk);int val;
@@ -1310,7 +1312,7 @@ static int do_udp_setsockopt(struct sock }else { up->corkflag =0 ;lock_sock (sk); -udp_push_pending_frames (sk, up); + (*push_pending_frames)(sk);release_sock (sk); }break ;
@@ -1366,7 +1368,8 @@ int udp_setsockopt(struct sock *sk, int char __user *optval, int optlen) {if (level ==SOL_UDP || level ==SOL_UDPLITE ) -return do_udp_setsockopt (sk, level, optname, optval, optlen); +return udp_lib_setsockopt (sk, level, optname, optval, optlen, + udp_push_pending_frames );return ip_setsockopt (sk, level, optname, optval, optlen); }
@@ -1375,13 +1378,14 @@ int compat_udp_setsockopt(struct sock *s char __user *optval, int optlen) {if (level ==SOL_UDP || level ==SOL_UDPLITE ) -return do_udp_setsockopt (sk, level, optname, optval, optlen); +return udp_lib_setsockopt (sk, level, optname, optval, optlen, + udp_push_pending_frames );return compat_ip_setsockopt (sk, level, optname, optval, optlen); }#endif -static int do_udp_getsockopt (struct sock *sk,int level,int optname, -char __user *optval,int __user *optlen) +int udp_lib_getsockopt (struct sock *sk,int level,int optname, +char __user *optval,int __user *optlen) {struct udp_sock *up =udp_sk (sk);int val, len;
@@ -1428,7 +1432,7 @@ int udp_getsockopt(struct sock *sk, int char __user *optval, int __user *optlen) {if (level ==SOL_UDP || level ==SOL_UDPLITE ) -return do_udp_getsockopt (sk, level, optname, optval, optlen); +return udp_lib_getsockopt (sk, level, optname, optval, optlen);return ip_getsockopt (sk, level, optname, optval, optlen); }
@@ -1437,7 +1441,7 @@ int compat_udp_getsockopt(struct sock *s char __user *optval, int __user *optlen) {if (level ==SOL_UDP || level ==SOL_UDPLITE ) -return do_udp_getsockopt (sk, level, optname, optval, optlen); +return udp_lib_getsockopt (sk, level, optname, optval, optlen);return compat_ip_getsockopt (sk, level, optname, optval, optlen); }#endif
@@ -1707,6 +1711,8 @@ EXPORT_SYMBOL(udp_ioctl);EXPORT_SYMBOL (udp_get_port);EXPORT_SYMBOL (udp_prot);EXPORT_SYMBOL (udp_sendmsg); +EXPORT_SYMBOL (udp_lib_getsockopt); +EXPORT_SYMBOL (udp_lib_setsockopt);EXPORT_SYMBOL (udp_poll);#ifdef CONFIG_PROC_FS
net/ipv6/udp.c +9 -109
163 lines not on this page · raw message
From: Gerrit Renker <[email protected]>
Date: Mon, 27 Nov 2006 10:44:33 +0000
Quoted 16 lines
[UDP(-Lite)]: consolidate v4 and v6 get|setsockopt code
This is for 2.6.20.
This patch consolidates set/getsockopt code between UDP(-Lite) v4 and 6. The justification is that UDP(-Lite) is a transport-layer protocol and therefore the socket option code (at least in theory) should be AF-independent.
Furthermore, there is the following code reduplication:
* do_udp{,v6}_getsockopt is 100% identical between v4 and v6
* do_udp{,v6}_setsockopt is identical up to the following differerence --v4 in contrast to v4 additionally allows the experimental encapsulation typesUDP_ENCAP_ESPINUDPandUDP_ENCAP_ESPINUDP_NON_IKE--the remainder is identical between v4 and v6
I believe that this difference is of little relevance.
Quoted 8 lines
The advantages in not duplicating twice almost completely identical code.
The patch further simplifies the interface of udp{,v6}_push_pending_frames, since for the second argument (struct
udp_sock*up) it always holds that up =udp_sk(sk); where sk is the first function argument.Signed-off-by Gerrit Renker <[email protected]>
Applied, except that I fixed up the extraneous spaces here:
Quoted 11 lines
net/ipv4/udp.c +2
-1@@ -1366,7 +1368,8 @@ int udp_setsockopt(struct sock *sk, int char __user *optval, int optlen) {if (level ==SOL_UDP || level ==SOL_UDPLITE ) -return do_udp_setsockopt (sk, level, optname, optval, optlen); +return udp_lib_setsockopt (sk, level, optname, optval, optlen, + udp_push_pending_frames );return ip_setsockopt (sk, level, optname, optval, optlen); }
net/ipv4/udp.c int compat_udp_setsockopt(struct sock *s · line 1385
Quoted 9 lines
net/ipv4/udp.c +2
-1@@ -1375,13 +1378,14 @@ int compat_udp_setsockopt(struct sock *s char __user *optval, int optlen) {if (level ==SOL_UDP || level ==SOL_UDPLITE ) -return do_udp_setsockopt (sk, level, optname, optval, optlen); +return udp_lib_setsockopt (sk, level, optname, optval, optlen, + udp_push_pending_frames );return compat_ip_setsockopt (sk, level, optname, optval, optlen); }#endif
and here:
Quoted 11 lines
net/ipv6/udp.c +2
-1int udpv6_setsockopt (struct sock *sk,int level,int optname,char __user *optval,int optlen) {if (level ==SOL_UDP || level ==SOL_UDPLITE ) -return do_udpv6_setsockopt (sk, level, optname, optval, optlen); +return udp_lib_setsockopt (sk, level, optname, optval, optlen, + udp_v6_push_pending_frames );return ipv6_setsockopt (sk, level, optname, optval, optlen); }
net/ipv6/udp.c int compat_udpv6_setsockopt(struct sock · line 867
Quoted 9 lines
net/ipv6/udp.c +2
-1@@ -919,58 +860,17 @@ int compat_udpv6_setsockopt(struct sock char __user *optval, int optlen) {if (level ==SOL_UDP || level ==SOL_UDPLITE ) -return do_udpv6_setsockopt (sk, level, optname, optval, optlen); +return udp_lib_setsockopt (sk, level, optname, optval, optlen, + udp_v6_push_pending_frames );return compat_ipv6_setsockopt (sk, level, optname, optval, optlen); }#endif
Specifically, the space between the push_pending_frames final argument passed and the closing parenthesis was removed. Why did you put that there? It looks fugly :)
Quoting David Miller:
| > if (level == SOL_UDP || level == SOL_UDPLITE) | > - return do_udpv6_setsockopt(sk, level, optname, optval, optlen); | > + return udp_lib_setsockopt(sk, level, optname, optval, optlen, | > + udp_v6_push_pending_frames ); | > return compat_ipv6_setsockopt(sk, level, optname, optval, optlen); | > } | > #endif | | Specifically, the space between the push_pending_frames final argument | passed and the closing parenthesis was removed. Why did you put | that there? It looks fugly :) Thank you for ironing this out, and a nice euphemism, too |-) The intention was to match
the end of the arguments list in the preceding line. But it seems that my feeble attempts to be neat here have not met with wide approval ..... still enjoying the euphemism :-)
Many thanks and best regards
Gerrit