Skip to content

Commit e898d4d

Browse files
committed
[UDP]: Allow users to configure UDP-Lite.
Let's give users an option for disabling UDP-Lite (~4K). old: | text data bss dec hex filename | 286498 12432 6072 305002 4a76a net/ipv4/built-in.o | 193830 8192 3204 205226 321aa net/ipv6/ipv6.o new (without UDP-Lite): | text data bss dec hex filename | 284086 12136 5432 301654 49a56 net/ipv4/built-in.o | 191835 7832 3076 202743 317f7 net/ipv6/ipv6.o Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
1 parent c6aefaf commit e898d4d

14 files changed

Lines changed: 99 additions & 25 deletions

File tree

‎include/linux/udp.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ struct udp_sock {
7070
#define UDPLITE_BIT 0x1 /* set by udplite proto init function */
7171
#define UDPLITE_SEND_CC 0x2 /* set via udplite setsockopt */
7272
#define UDPLITE_RECV_CC 0x4 /* set via udplite setsocktopt */
73+
#ifdef CONFIG_IP_UDPLITE
7374
__u8 pcflag; /* marks socket as UDP-Lite if > 0 */
7475
__u8 unused[3];
76+
#endif
7577
/*
7678
* For encapsulation sockets.
7779
*/
@@ -82,7 +84,16 @@ static inline struct udp_sock *udp_sk(const struct sock *sk)
8284
{
8385
return (struct udp_sock *)sk;
8486
}
87+
88+
#ifdef CONFIG_IP_UDPLITE
8589
#define IS_UDPLITE(__sk) (udp_sk(__sk)->pcflag)
90+
#define IS_PROTO_UDPLITE(__proto) ((__proto) == IPPROTO_UDPLITE)
91+
#define IS_SOL_UDPFAMILY(level) ((level) == SOL_UDP || (level) == SOL_UDPLITE)
92+
#else
93+
#define IS_UDPLITE(__sk) 0
94+
#define IS_PROTO_UDPLITE(__proto) 0
95+
#define IS_SOL_UDPFAMILY(level) ((level) == SOL_UDP)
96+
#endif
8697

8798
#endif
8899

‎include/net/ipv6.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,13 @@ extern int tcp6_proc_init(void);
603603
extern void tcp6_proc_exit(void);
604604
extern int udp6_proc_init(void);
605605
extern void udp6_proc_exit(void);
606+
#ifdef CONFIG_IP_UDPLITE
606607
extern int udplite6_proc_init(void);
607608
extern void udplite6_proc_exit(void);
609+
#else
610+
static inline int udplite6_proc_init(void) { return 0; }
611+
static inline void udplite6_proc_exit(void) { }
612+
#endif
608613
extern int ipv6_misc_proc_init(void);
609614
extern void ipv6_misc_proc_exit(void);
610615
extern int snmp6_register_dev(struct inet6_dev *idev);

‎include/net/transp_v6.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ extern int rawv6_init(void);
2727
extern void rawv6_exit(void);
2828
extern int udpv6_init(void);
2929
extern void udpv6_exit(void);
30+
#ifdef CONFIG_IP_UDPLITE
3031
extern int udplitev6_init(void);
3132
extern void udplitev6_exit(void);
33+
#else
34+
static inline int udplitev6_init(void) { return 0; }
35+
static inline void udplitev6_exit(void) { }
36+
#endif
3237
extern int tcpv6_init(void);
3338
extern void tcpv6_exit(void);
3439

‎include/net/udplite.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ static __inline__ int udplite_getfrag(void *from, char *to, int offset,
2525
/* Designate sk as UDP-Lite socket */
2626
static inline int udplite_sk_init(struct sock *sk)
2727
{
28+
#ifdef CONFIG_IP_UDPLITE
2829
udp_sk(sk)->pcflag = UDPLITE_BIT;
30+
#endif
2931
return 0;
3032
}
3133

@@ -69,7 +71,7 @@ static inline int udplite_checksum_init(struct sk_buff *skb, struct udphdr *uh)
6971
static inline int udplite_sender_cscov(struct udp_sock *up, struct udphdr *uh)
7072
{
7173
int cscov = up->len;
72-
74+
#ifdef CONFIG_IP_UDPLITE
7375
/*
7476
* Sender has set `partial coverage' option on UDP-Lite socket
7577
*/
@@ -93,13 +95,15 @@ static inline int udplite_sender_cscov(struct udp_sock *up, struct udphdr *uh)
9395
* illegal, we fall back to the defaults here.
9496
*/
9597
}
98+
#endif
9699
return cscov;
97100
}
98101

99102
static inline __wsum udplite_csum_outgoing(struct sock *sk, struct sk_buff *skb)
100103
{
101-
int cscov = udplite_sender_cscov(udp_sk(sk), udp_hdr(skb));
102104
__wsum csum = 0;
105+
#ifdef CONFIG_IP_UDPLITE
106+
int cscov = udplite_sender_cscov(udp_sk(sk), udp_hdr(skb));
103107

104108
skb->ip_summed = CHECKSUM_NONE; /* no HW support for checksumming */
105109

@@ -112,6 +116,7 @@ static inline __wsum udplite_csum_outgoing(struct sock *sk, struct sk_buff *skb)
112116
if ((cscov -= len) <= 0)
113117
break;
114118
}
119+
#endif
115120
return csum;
116121
}
117122

‎net/ipv4/Kconfig‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,5 +632,15 @@ config TCP_MD5SIG
632632

633633
If unsure, say N.
634634

635+
config IP_UDPLITE
636+
bool "IP: UDP-Lite Protocol (RFC 3828)"
637+
default n
638+
---help---
639+
UDP-Lite (RFC 3828) is a UDP-like protocol with variable-length
640+
checksum. Read <file:Documentation/networking/udplite.txt> for
641+
details.
642+
643+
If unsure, say N.
644+
635645
source "net/ipv4/ipvs/Kconfig"
636646

‎net/ipv4/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ obj-y := route.o inetpeer.o protocol.o \
88
inet_timewait_sock.o inet_connection_sock.o \
99
tcp.o tcp_input.o tcp_output.o tcp_timer.o tcp_ipv4.o \
1010
tcp_minisocks.o tcp_cong.o \
11-
datagram.o raw.o udp.o udplite.o \
11+
datagram.o raw.o udp.o \
1212
arp.o icmp.o devinet.o af_inet.o igmp.o \
1313
fib_frontend.o fib_semantics.o \
1414
inet_fragment.o
@@ -49,6 +49,7 @@ obj-$(CONFIG_TCP_CONG_SCALABLE) += tcp_scalable.o
4949
obj-$(CONFIG_TCP_CONG_LP) += tcp_lp.o
5050
obj-$(CONFIG_TCP_CONG_YEAH) += tcp_yeah.o
5151
obj-$(CONFIG_TCP_CONG_ILLINOIS) += tcp_illinois.o
52+
obj-$(CONFIG_IP_UDPLITE) += udplite.o
5253
obj-$(CONFIG_NETLABEL) += cipso_ipv4.o
5354

5455
obj-$(CONFIG_XFRM) += xfrm4_policy.o xfrm4_state.o xfrm4_input.o \

‎net/ipv4/af_inet.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1317,15 +1317,18 @@ static int __init init_ipv4_mibs(void)
13171317
if (snmp_mib_init((void **)udp_statistics,
13181318
sizeof(struct udp_mib)) < 0)
13191319
goto err_udp_mib;
1320+
#ifdef CONFIG_IP_UDPLITE
13201321
if (snmp_mib_init((void **)udplite_statistics,
13211322
sizeof(struct udp_mib)) < 0)
13221323
goto err_udplite_mib;
1323-
1324+
#endif
13241325
tcp_mib_init();
13251326

13261327
return 0;
13271328

1329+
#ifdef CONFIG_IP_UDPLITE
13281330
err_udplite_mib:
1331+
#endif
13291332
snmp_mib_free((void **)udp_statistics);
13301333
err_udp_mib:
13311334
snmp_mib_free((void **)tcp_statistics);
@@ -1423,8 +1426,10 @@ static int __init inet_init(void)
14231426
/* Setup UDP memory threshold */
14241427
udp_init();
14251428

1429+
#ifdef CONFIG_IP_UDPLITE
14261430
/* Add UDP-Lite (RFC 3828) */
14271431
udplite4_register();
1432+
#endif
14281433

14291434
/*
14301435
* Set the ICMP layer up

‎net/ipv4/proc.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ static int sockstat_seq_show(struct seq_file *seq, void *v)
5959
atomic_read(&tcp_memory_allocated));
6060
seq_printf(seq, "UDP: inuse %d mem %d\n", sock_prot_inuse_get(&udp_prot),
6161
atomic_read(&udp_memory_allocated));
62+
#ifdef CONFIG_IP_UDPLITE
6263
seq_printf(seq, "UDPLITE: inuse %d\n", sock_prot_inuse_get(&udplite_prot));
64+
#endif
6365
seq_printf(seq, "RAW: inuse %d\n", sock_prot_inuse_get(&raw_prot));
6466
seq_printf(seq, "FRAG: inuse %d memory %d\n",
6567
ip_frag_nqueues(&init_net), ip_frag_mem(&init_net));
@@ -349,6 +351,7 @@ static int snmp_seq_show(struct seq_file *seq, void *v)
349351
snmp_fold_field((void **)udp_statistics,
350352
snmp4_udp_list[i].entry));
351353

354+
#ifdef CONFIG_IP_UDPLITE
352355
/* the UDP and UDP-Lite MIBs are the same */
353356
seq_puts(seq, "\nUdpLite:");
354357
for (i = 0; snmp4_udp_list[i].name != NULL; i++)
@@ -359,7 +362,7 @@ static int snmp_seq_show(struct seq_file *seq, void *v)
359362
seq_printf(seq, " %lu",
360363
snmp_fold_field((void **)udplite_statistics,
361364
snmp4_udp_list[i].entry));
362-
365+
#endif
363366
seq_putc(seq, '\n');
364367
return 0;
365368
}

‎net/ipv4/udp.c‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ static inline int udp4_csum_init(struct sk_buff *skb, struct udphdr *uh,
11271127
UDP_SKB_CB(skb)->partial_cov = 0;
11281128
UDP_SKB_CB(skb)->cscov = skb->len;
11291129

1130-
if (proto == IPPROTO_UDPLITE) {
1130+
if (IS_PROTO_UDPLITE(proto)) {
11311131
err = udplite_checksum_init(skb, uh);
11321132
if (err)
11331133
return err;
@@ -1175,7 +1175,7 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct hlist_head udptable[],
11751175
if (ulen > skb->len)
11761176
goto short_packet;
11771177

1178-
if (proto == IPPROTO_UDP) {
1178+
if (IS_PROTO_UDPLITE(proto)) {
11791179
/* UDP validates ulen. */
11801180
if (ulen < sizeof(*uh) || pskb_trim_rcsum(skb, ulen))
11811181
goto short_packet;
@@ -1217,7 +1217,7 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct hlist_head udptable[],
12171217
if (udp_lib_checksum_complete(skb))
12181218
goto csum_error;
12191219

1220-
UDP_INC_STATS_BH(UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
1220+
UDP_INC_STATS_BH(UDP_MIB_NOPORTS, IS_PROTO_UDPLITE(proto));
12211221
icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
12221222

12231223
/*
@@ -1229,7 +1229,7 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct hlist_head udptable[],
12291229

12301230
short_packet:
12311231
LIMIT_NETDEBUG(KERN_DEBUG "UDP%s: short packet: From %u.%u.%u.%u:%u %d/%d to %u.%u.%u.%u:%u\n",
1232-
proto == IPPROTO_UDPLITE ? "-Lite" : "",
1232+
IS_PROTO_UDPLITE(proto) ? "-Lite" : "",
12331233
NIPQUAD(saddr),
12341234
ntohs(uh->source),
12351235
ulen,
@@ -1244,14 +1244,14 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct hlist_head udptable[],
12441244
* the network is concerned, anyway) as per 4.1.3.4 (MUST).
12451245
*/
12461246
LIMIT_NETDEBUG(KERN_DEBUG "UDP%s: bad checksum. From %d.%d.%d.%d:%d to %d.%d.%d.%d:%d ulen %d\n",
1247-
proto == IPPROTO_UDPLITE ? "-Lite" : "",
1247+
IS_PROTO_UDPLITE(proto) ? "-Lite" : "",
12481248
NIPQUAD(saddr),
12491249
ntohs(uh->source),
12501250
NIPQUAD(daddr),
12511251
ntohs(uh->dest),
12521252
ulen);
12531253
drop:
1254-
UDP_INC_STATS_BH(UDP_MIB_INERRORS, proto == IPPROTO_UDPLITE);
1254+
UDP_INC_STATS_BH(UDP_MIB_INERRORS, IS_PROTO_UDPLITE(proto));
12551255
kfree_skb(skb);
12561256
return 0;
12571257
}
@@ -1279,7 +1279,9 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname,
12791279
struct udp_sock *up = udp_sk(sk);
12801280
int val;
12811281
int err = 0;
1282+
#ifdef CONFIG_IP_UDPLITE
12821283
int is_udplite = IS_UDPLITE(sk);
1284+
#endif
12831285

12841286
if (optlen<sizeof(int))
12851287
return -EINVAL;
@@ -1315,6 +1317,7 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname,
13151317
}
13161318
break;
13171319

1320+
#ifdef CONFIG_IP_UDPLITE
13181321
/*
13191322
* UDP-Lite's partial checksum coverage (RFC 3828).
13201323
*/
@@ -1340,6 +1343,7 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname,
13401343
up->pcrlen = val;
13411344
up->pcflag |= UDPLITE_RECV_CC;
13421345
break;
1346+
#endif
13431347

13441348
default:
13451349
err = -ENOPROTOOPT;
@@ -1352,7 +1356,7 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname,
13521356
int udp_setsockopt(struct sock *sk, int level, int optname,
13531357
char __user *optval, int optlen)
13541358
{
1355-
if (level == SOL_UDP || level == SOL_UDPLITE)
1359+
if (IS_SOL_UDPFAMILY(level))
13561360
return udp_lib_setsockopt(sk, level, optname, optval, optlen,
13571361
udp_push_pending_frames);
13581362
return ip_setsockopt(sk, level, optname, optval, optlen);
@@ -1362,7 +1366,7 @@ int udp_setsockopt(struct sock *sk, int level, int optname,
13621366
int compat_udp_setsockopt(struct sock *sk, int level, int optname,
13631367
char __user *optval, int optlen)
13641368
{
1365-
if (level == SOL_UDP || level == SOL_UDPLITE)
1369+
if (IS_SOL_UDPFAMILY(level))
13661370
return udp_lib_setsockopt(sk, level, optname, optval, optlen,
13671371
udp_push_pending_frames);
13681372
return compat_ip_setsockopt(sk, level, optname, optval, optlen);
@@ -1416,7 +1420,7 @@ int udp_lib_getsockopt(struct sock *sk, int level, int optname,
14161420
int udp_getsockopt(struct sock *sk, int level, int optname,
14171421
char __user *optval, int __user *optlen)
14181422
{
1419-
if (level == SOL_UDP || level == SOL_UDPLITE)
1423+
if (IS_SOL_UDPFAMILY(level))
14201424
return udp_lib_getsockopt(sk, level, optname, optval, optlen);
14211425
return ip_getsockopt(sk, level, optname, optval, optlen);
14221426
}
@@ -1425,7 +1429,7 @@ int udp_getsockopt(struct sock *sk, int level, int optname,
14251429
int compat_udp_getsockopt(struct sock *sk, int level, int optname,
14261430
char __user *optval, int __user *optlen)
14271431
{
1428-
if (level == SOL_UDP || level == SOL_UDPLITE)
1432+
if (IS_SOL_UDPFAMILY(level))
14291433
return udp_lib_getsockopt(sk, level, optname, optval, optlen);
14301434
return compat_ip_getsockopt(sk, level, optname, optval, optlen);
14311435
}

‎net/ipv6/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ obj-$(CONFIG_IPV6) += ipv6.o
66

77
ipv6-objs := af_inet6.o anycast.o ip6_output.o ip6_input.o addrconf.o \
88
addrlabel.o \
9-
route.o ip6_fib.o ipv6_sockglue.o ndisc.o udp.o udplite.o \
9+
route.o ip6_fib.o ipv6_sockglue.o ndisc.o udp.o \
1010
raw.o protocol.o icmp.o mcast.o reassembly.o tcp_ipv6.o \
1111
exthdrs.o datagram.o ip6_flowlabel.o inet6_connection_sock.o
1212

@@ -17,6 +17,7 @@ ipv6-$(CONFIG_NETFILTER) += netfilter.o
1717
ipv6-$(CONFIG_IPV6_MULTIPLE_TABLES) += fib6_rules.o
1818
ipv6-$(CONFIG_PROC_FS) += proc.o
1919
ipv6-$(CONFIG_SYN_COOKIES) += syncookies.o
20+
ipv6-$(CONFIG_IP_UDPLITE) += udplite.o
2021

2122
ipv6-objs += $(ipv6-y)
2223

0 commit comments

Comments
 (0)