Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'udp-retire-udp-lite'

Kuniyuki Iwashima says:

====================
udp: Retire UDP-Lite.

In 2023, syzbot found a null-ptr-deref bug triggered when UDP-Lite
attempted to charge an skb after the total memory usage for UDP-Lite
_and_ UDP exceeded a system-wide threshold, net.ipv4.udp_mem[1].

Since this threshold is shared with UDP, the bug would have been
easy to trigger if any real-world applications were using UDP-Lite;
however, only syzbot ever stumbled upon it.

The bug had persisted since 2016, suggesting that UDP-Lite had
remained unused for 7 years at that point.

The bug was fixed in commit ad42a35bdfc6 ("udplite: Fix NULL pointer
dereference in __sk_mem_raise_allocated()."), and we added another
commit be28c14ac8bb ("udplite: Print deprecation notice.") to
announce the deprecation plan.

Since then, no one has complained, so it is time to officially
retire UDP-Lite.

This series first removes IPv6 and IPv4 UDP-Lite sockets, then
gradually cleans up the remaining dead/unnecessary code within
the UDP stack.

By removing a bunch of conditionals for UDP-Lite from the fast
path, udp_rr with 20,000 flows sees a 10% increase in pps
(13.3 Mpps -> 14.7 Mpps) on an AMD EPYC 7B12 (Zen 2) 64-Core
Processor platform.

[ With FDO, the baseline is much higher and the delta was ~3%,
20.1 Mpps -> 20.7 Mpps ]

Before:

$ nstat > /dev/null; sleep 1; nstat | grep Udp
Udp6InDatagrams 14013408 0.0
Udp6OutDatagrams 14013128 0.0

After:

$ nstat > /dev/null; sleep 1; nstat | grep Udp
Udp6InDatagrams 15491971 0.0
Udp6OutDatagrams 15491671 0.0

$ ./scripts/bloat-o-meter vmlinux.before vmlinux.after
add/remove: 13/75 grow/shrink: 11/75 up/down: 13777/-18401 (-4624)
Function old new delta
udp4_gro_receive 872 866 -6
udp6_gro_receive 910 903 -7
udp_rcv 32 1727 +1695
udpv6_rcv 32 1450 +1418
__udp4_lib_rcv 2045 - -2045
__udp6_lib_rcv 2084 - -2084
udp_unicast_rcv_skb 160 149 -11
udp6_unicast_rcv_skb 196 181 -15
__udp4_lib_mcast_deliver 925 846 -79
__udp6_lib_mcast_deliver 922 810 -112
__udp4_lib_lookup 973 969 -4
__udp6_lib_lookup 940 929 -11
__udp4_lib_lookup_skb 106 100 -6
__udp6_lib_lookup_skb 71 66 -5
udp4_lib_lookup_skb 132 127 -5
udp6_lib_lookup_skb 87 81 -6
udp_queue_rcv_skb 326 356 +30
udpv6_queue_rcv_skb 331 361 +30
udp_queue_rcv_one_skb 1233 914 -319
udpv6_queue_rcv_one_skb 1250 930 -320
__udp_enqueue_schedule_skb 1067 995 -72
udp_rcv_segment 520 480 -40
udp_post_segment_fix_csum 120 - -120
udp_lib_checksum_complete 200 84 -116
udp_err 27 1103 +1076
udpv6_err 36 1417 +1381
__udp4_lib_err 1112 - -1112
__udp6_lib_err 1448 - -1448
udp_recvmsg 1149 994 -155
udpv6_recvmsg 1349 1294 -55
udp_sendmsg 2730 2648 -82
udp_send_skb 909 681 -228
udpv6_sendmsg 3022 2861 -161
udp_v6_send_skb 1214 952 -262
...
Total: Before=18446744073748075501, After=18446744073748070877, chg -0.00%
====================

Link: https://patch.msgid.link/20260311052020.1213705-1-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+345 -1181
+1 -9
include/linux/udp.h
··· 40 40 UDP_FLAGS_ACCEPT_FRAGLIST, 41 41 UDP_FLAGS_ACCEPT_L4, 42 42 UDP_FLAGS_ENCAP_ENABLED, /* This socket enabled encap */ 43 - UDP_FLAGS_UDPLITE_SEND_CC, /* set via udplite setsockopt */ 44 - UDP_FLAGS_UDPLITE_RECV_CC, /* set via udplite setsockopt */ 45 43 }; 46 44 47 45 /* per NUMA structure for lockless producer usage. */ ··· 72 74 */ 73 75 __u16 len; /* total length of pending frames */ 74 76 __u16 gso_size; 75 - /* 76 - * Fields specific to UDP-Lite. 77 - */ 78 - __u16 pcslen; 79 - __u16 pcrlen; 77 + 80 78 /* 81 79 * For encapsulation sockets. 82 80 */ ··· 229 235 #define udp_lrpa_for_each_entry_rcu(__up, node, list) \ 230 236 hlist_nulls_for_each_entry_rcu(__up, node, list, udp_lrpa_node) 231 237 #endif 232 - 233 - #define IS_UDPLITE(__sk) (unlikely(__sk->sk_protocol == IPPROTO_UDPLITE)) 234 238 235 239 static inline struct sock *udp_tunnel_sk(const struct net *net, bool is_ipv6) 236 240 {
-2
include/net/ipv6.h
··· 1179 1179 void tcp6_proc_exit(struct net *net); 1180 1180 int udp6_proc_init(struct net *net); 1181 1181 void udp6_proc_exit(struct net *net); 1182 - int udplite6_proc_init(void); 1183 - void udplite6_proc_exit(void); 1184 1182 int ipv6_misc_proc_init(void); 1185 1183 void ipv6_misc_proc_exit(void); 1186 1184 int snmp6_register_dev(struct inet6_dev *idev);
+3 -4
include/net/ipv6_stubs.h
··· 83 83 int (*inet6_bind)(struct sock *sk, struct sockaddr_unsized *uaddr, int addr_len, 84 84 u32 flags); 85 85 struct sock *(*udp6_lib_lookup)(const struct net *net, 86 - const struct in6_addr *saddr, __be16 sport, 87 - const struct in6_addr *daddr, __be16 dport, 88 - int dif, int sdif, struct udp_table *tbl, 89 - struct sk_buff *skb); 86 + const struct in6_addr *saddr, __be16 sport, 87 + const struct in6_addr *daddr, __be16 dport, 88 + int dif, int sdif, struct sk_buff *skb); 90 89 int (*ipv6_setsockopt)(struct sock *sk, int level, int optname, 91 90 sockptr_t optval, unsigned int optlen); 92 91 int (*ipv6_getsockopt)(struct sock *sk, int level, int optname,
-5
include/net/netns/mib.h
··· 28 28 DEFINE_SNMP_STAT(struct mptcp_mib, mptcp_statistics); 29 29 #endif 30 30 31 - DEFINE_SNMP_STAT(struct udp_mib, udplite_statistics); 32 - #if IS_ENABLED(CONFIG_IPV6) 33 - DEFINE_SNMP_STAT(struct udp_mib, udplite_stats_in6); 34 - #endif 35 - 36 31 DEFINE_SNMP_STAT(struct icmp_mib, icmp_statistics); 37 32 DEFINE_SNMP_STAT_ATOMIC(struct icmpmsg_mib, icmpmsg_statistics); 38 33 #if IS_ENABLED(CONFIG_IPV6)
+2 -3
include/net/sock.h
··· 126 126 * @skc_bypass_prot_mem: bypass the per-protocol memory accounting for skb 127 127 * @skc_bound_dev_if: bound device index if != 0 128 128 * @skc_bind_node: bind hash linkage for various protocol lookup tables 129 - * @skc_portaddr_node: second hash linkage for UDP/UDP-Lite protocol 129 + * @skc_portaddr_node: second hash linkage for UDP 130 130 * @skc_prot: protocol handlers inside a network family 131 131 * @skc_net: reference to the network namespace of this socket 132 132 * @skc_v6_daddr: IPV6 destination address 133 133 * @skc_v6_rcv_saddr: IPV6 source address 134 134 * @skc_cookie: socket's cookie value 135 135 * @skc_node: main hash linkage for various protocol lookup tables 136 - * @skc_nulls_node: main hash linkage for TCP/UDP/UDP-Lite protocol 136 + * @skc_nulls_node: main hash linkage for TCP 137 137 * @skc_tx_queue_mapping: tx queue number for this connection 138 138 * @skc_rx_queue_mapping: rx queue number for this connection 139 139 * @skc_flags: place holder for sk_flags ··· 1392 1392 1393 1393 union { 1394 1394 struct inet_hashinfo *hashinfo; 1395 - struct udp_table *udp_table; 1396 1395 struct raw_hashinfo *raw_hash; 1397 1396 struct smc_hashinfo *smc_hash; 1398 1397 } h;
-3
include/net/transp_v6.h
··· 8 8 /* IPv6 transport protocols */ 9 9 extern struct proto rawv6_prot; 10 10 extern struct proto udpv6_prot; 11 - extern struct proto udplitev6_prot; 12 11 extern struct proto tcpv6_prot; 13 12 extern struct proto pingv6_prot; 14 13 ··· 27 28 void rawv6_exit(void); 28 29 int udpv6_init(void); 29 30 void udpv6_exit(void); 30 - int udplitev6_init(void); 31 - void udplitev6_exit(void); 32 31 int tcpv6_init(void); 33 32 void tcpv6_exit(void); 34 33
+32 -54
include/net/udp.h
··· 32 32 #include <linux/math.h> 33 33 34 34 /** 35 - * struct udp_skb_cb - UDP(-Lite) private variables 35 + * struct udp_skb_cb - UDP private variables 36 36 * 37 37 * @header: private variables used by IPv4/IPv6 38 - * @cscov: checksum coverage length (UDP-Lite only) 39 - * @partial_cov: if set indicates partial csum coverage 40 38 */ 41 39 struct udp_skb_cb { 42 40 union { ··· 43 45 struct inet6_skb_parm h6; 44 46 #endif 45 47 } header; 46 - __u16 cscov; 47 - __u8 partial_cov; 48 48 }; 49 49 #define UDP_SKB_CB(__skb) ((struct udp_skb_cb *)((__skb)->cb)) 50 50 ··· 101 105 unsigned int log; 102 106 }; 103 107 extern struct udp_table udp_table; 104 - void udp_table_init(struct udp_table *, const char *); 108 + 105 109 static inline struct udp_hslot *udp_hashslot(struct udp_table *table, 106 110 const struct net *net, 107 111 unsigned int num) ··· 212 216 struct sk_buff; 213 217 214 218 /* 215 - * Generic checksumming routines for UDP(-Lite) v4 and v6 219 + * Generic checksumming routines for UDP v4 and v6 216 220 */ 217 221 static inline __sum16 __udp_lib_checksum_complete(struct sk_buff *skb) 218 222 { 219 - return (UDP_SKB_CB(skb)->cscov == skb->len ? 220 - __skb_checksum_complete(skb) : 221 - __skb_checksum_complete_head(skb, UDP_SKB_CB(skb)->cscov)); 223 + return __skb_checksum_complete(skb); 222 224 } 223 225 224 226 static inline int udp_lib_checksum_complete(struct sk_buff *skb) ··· 267 273 skb->csum = csum_partial(skb->data, sizeof(struct udphdr), 268 274 skb->csum); 269 275 skb_pull_rcsum(skb, sizeof(struct udphdr)); 270 - UDP_SKB_CB(skb)->cscov -= sizeof(struct udphdr); 271 276 } 272 277 273 278 typedef struct sock *(*udp_lookup_t)(const struct sk_buff *skb, __be16 sport, ··· 274 281 275 282 void udp_v6_early_demux(struct sk_buff *skb); 276 283 INDIRECT_CALLABLE_DECLARE(int udpv6_rcv(struct sk_buff *)); 284 + 285 + int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len); 286 + INDIRECT_CALLABLE_DECLARE(int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, 287 + size_t len, int flags)); 277 288 278 289 struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, 279 290 netdev_features_t features, bool is_ipv6); ··· 305 308 numa_drop_add(&udp_sk(sk)->drop_counters, 1); 306 309 } 307 310 308 - /* hash routines shared between UDPv4/6 and UDP-Litev4/6 */ 311 + /* hash routines shared between UDPv4/6 */ 309 312 static inline int udp_lib_hash(struct sock *sk) 310 313 { 311 314 BUG(); ··· 413 416 int udp_err(struct sk_buff *, u32); 414 417 int udp_abort(struct sock *sk, int err); 415 418 int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len); 419 + INDIRECT_CALLABLE_DECLARE(int udp_recvmsg(struct sock *sk, struct msghdr *msg, 420 + size_t len, int flags)); 416 421 void udp_splice_eof(struct socket *sock); 417 422 int udp_push_pending_frames(struct sock *sk); 418 423 void udp_flush_pending_frames(struct sock *sk); ··· 422 423 void udp4_hwcsum(struct sk_buff *skb, __be32 src, __be32 dst); 423 424 int udp_rcv(struct sk_buff *skb); 424 425 int udp_ioctl(struct sock *sk, int cmd, int *karg); 425 - int udp_init_sock(struct sock *sk); 426 426 int udp_pre_connect(struct sock *sk, struct sockaddr_unsized *uaddr, int addr_len); 427 427 int __udp_disconnect(struct sock *sk, int flags); 428 428 int udp_disconnect(struct sock *sk, int flags); ··· 437 439 struct sock *udp4_lib_lookup(const struct net *net, __be32 saddr, __be16 sport, 438 440 __be32 daddr, __be16 dport, int dif); 439 441 struct sock *__udp4_lib_lookup(const struct net *net, __be32 saddr, 440 - __be16 sport, 441 - __be32 daddr, __be16 dport, int dif, int sdif, 442 - struct udp_table *tbl, struct sk_buff *skb); 442 + __be16 sport, __be32 daddr, __be16 dport, 443 + int dif, int sdif, struct sk_buff *skb); 443 444 struct sock *udp4_lib_lookup_skb(const struct sk_buff *skb, 444 445 __be16 sport, __be16 dport); 445 446 struct sock *udp6_lib_lookup(const struct net *net, ··· 448 451 struct sock *__udp6_lib_lookup(const struct net *net, 449 452 const struct in6_addr *saddr, __be16 sport, 450 453 const struct in6_addr *daddr, __be16 dport, 451 - int dif, int sdif, struct udp_table *tbl, 452 - struct sk_buff *skb); 454 + int dif, int sdif, struct sk_buff *skb); 453 455 struct sock *udp6_lib_lookup_skb(const struct sk_buff *skb, 454 456 __be16 sport, __be16 dport); 455 457 int udp_read_skb(struct sock *sk, skb_read_actor_t recv_actor); ··· 520 524 } 521 525 522 526 /* 523 - * SNMP statistics for UDP and UDP-Lite 527 + * SNMP statistics for UDP 524 528 */ 525 - #define UDP_INC_STATS(net, field, is_udplite) do { \ 526 - if (unlikely(is_udplite)) SNMP_INC_STATS((net)->mib.udplite_statistics, field); \ 527 - else SNMP_INC_STATS((net)->mib.udp_statistics, field); } while(0) 528 - #define __UDP_INC_STATS(net, field, is_udplite) do { \ 529 - if (unlikely(is_udplite)) __SNMP_INC_STATS((net)->mib.udplite_statistics, field); \ 530 - else __SNMP_INC_STATS((net)->mib.udp_statistics, field); } while(0) 531 - 532 - #define __UDP6_INC_STATS(net, field, is_udplite) do { \ 533 - if (unlikely(is_udplite)) __SNMP_INC_STATS((net)->mib.udplite_stats_in6, field); \ 534 - else __SNMP_INC_STATS((net)->mib.udp_stats_in6, field); \ 535 - } while(0) 536 - #define UDP6_INC_STATS(net, field, __lite) do { \ 537 - if (unlikely(__lite)) SNMP_INC_STATS((net)->mib.udplite_stats_in6, field); \ 538 - else SNMP_INC_STATS((net)->mib.udp_stats_in6, field); \ 539 - } while(0) 529 + #define __UDP_INC_STATS(net, field) \ 530 + __SNMP_INC_STATS((net)->mib.udp_statistics, field) 531 + #define UDP_INC_STATS(net, field) \ 532 + SNMP_INC_STATS((net)->mib.udp_statistics, field) 533 + #define __UDP6_INC_STATS(net, field) \ 534 + __SNMP_INC_STATS((net)->mib.udp_stats_in6, field) 535 + #define UDP6_INC_STATS(net, field) \ 536 + SNMP_INC_STATS((net)->mib.udp_stats_in6, field) 540 537 541 538 #if IS_ENABLED(CONFIG_IPV6) 542 - #define __UDPX_MIB(sk, ipv4) \ 543 - ({ \ 544 - ipv4 ? (IS_UDPLITE(sk) ? sock_net(sk)->mib.udplite_statistics : \ 545 - sock_net(sk)->mib.udp_statistics) : \ 546 - (IS_UDPLITE(sk) ? sock_net(sk)->mib.udplite_stats_in6 : \ 547 - sock_net(sk)->mib.udp_stats_in6); \ 548 - }) 539 + #define __UDPX_MIB(sk, ipv4) \ 540 + ({ \ 541 + ipv4 ? sock_net(sk)->mib.udp_statistics : \ 542 + sock_net(sk)->mib.udp_stats_in6; \ 543 + }) 549 544 #else 550 - #define __UDPX_MIB(sk, ipv4) \ 551 - ({ \ 552 - IS_UDPLITE(sk) ? sock_net(sk)->mib.udplite_statistics : \ 553 - sock_net(sk)->mib.udp_statistics; \ 554 - }) 545 + #define __UDPX_MIB(sk, ipv4) \ 546 + ({ \ 547 + sock_net(sk)->mib.udp_statistics; \ 548 + }) 555 549 #endif 556 550 557 551 #define __UDPX_INC_STATS(sk, field) \ ··· 550 564 #ifdef CONFIG_PROC_FS 551 565 struct udp_seq_afinfo { 552 566 sa_family_t family; 553 - struct udp_table *udp_table; 554 567 }; 555 568 556 569 struct udp_iter_state { ··· 560 575 void *udp_seq_start(struct seq_file *seq, loff_t *pos); 561 576 void *udp_seq_next(struct seq_file *seq, void *v, loff_t *pos); 562 577 void udp_seq_stop(struct seq_file *seq, void *v); 563 - 564 - extern const struct seq_operations udp_seq_ops; 565 - extern const struct seq_operations udp6_seq_ops; 566 578 567 579 int udp4_proc_init(void); 568 580 void udp4_proc_exit(void); ··· 631 649 632 650 static inline void udp_post_segment_fix_csum(struct sk_buff *skb) 633 651 { 634 - /* UDP-lite can't land here - no GRO */ 635 - WARN_ON_ONCE(UDP_SKB_CB(skb)->partial_cov); 636 - 637 652 /* UDP packets generated with UDP_SEGMENT and traversing: 638 653 * 639 654 * UDP tunnel(xmit) -> veth (segmentation) -> veth (gro) -> UDP tunnel (rx) ··· 644 665 * a valid csum after the segmentation. 645 666 * Additionally fixup the UDP CB. 646 667 */ 647 - UDP_SKB_CB(skb)->cscov = skb->len; 648 668 if (skb->ip_summed == CHECKSUM_NONE && !skb->csum_valid) 649 669 skb->csum_valid = 1; 650 670 }
-88
include/net/udplite.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - /* 3 - * Definitions for the UDP-Lite (RFC 3828) code. 4 - */ 5 - #ifndef _UDPLITE_H 6 - #define _UDPLITE_H 7 - 8 - #include <net/ip6_checksum.h> 9 - #include <net/udp.h> 10 - 11 - /* UDP-Lite socket options */ 12 - #define UDPLITE_SEND_CSCOV 10 /* sender partial coverage (as sent) */ 13 - #define UDPLITE_RECV_CSCOV 11 /* receiver partial coverage (threshold ) */ 14 - 15 - extern struct proto udplite_prot; 16 - extern struct udp_table udplite_table; 17 - 18 - /* 19 - * Checksum computation is all in software, hence simpler getfrag. 20 - */ 21 - static __inline__ int udplite_getfrag(void *from, char *to, int offset, 22 - int len, int odd, struct sk_buff *skb) 23 - { 24 - struct msghdr *msg = from; 25 - return copy_from_iter_full(to, len, &msg->msg_iter) ? 0 : -EFAULT; 26 - } 27 - 28 - /* 29 - * Checksumming routines 30 - */ 31 - static inline int udplite_checksum_init(struct sk_buff *skb, struct udphdr *uh) 32 - { 33 - u16 cscov; 34 - 35 - /* In UDPv4 a zero checksum means that the transmitter generated no 36 - * checksum. UDP-Lite (like IPv6) mandates checksums, hence packets 37 - * with a zero checksum field are illegal. */ 38 - if (uh->check == 0) { 39 - net_dbg_ratelimited("UDPLite: zeroed checksum field\n"); 40 - return 1; 41 - } 42 - 43 - cscov = ntohs(uh->len); 44 - 45 - if (cscov == 0) /* Indicates that full coverage is required. */ 46 - ; 47 - else if (cscov < 8 || cscov > skb->len) { 48 - /* 49 - * Coverage length violates RFC 3828: log and discard silently. 50 - */ 51 - net_dbg_ratelimited("UDPLite: bad csum coverage %d/%d\n", 52 - cscov, skb->len); 53 - return 1; 54 - 55 - } else if (cscov < skb->len) { 56 - UDP_SKB_CB(skb)->partial_cov = 1; 57 - UDP_SKB_CB(skb)->cscov = cscov; 58 - if (skb->ip_summed == CHECKSUM_COMPLETE) 59 - skb->ip_summed = CHECKSUM_NONE; 60 - skb->csum_valid = 0; 61 - } 62 - 63 - return 0; 64 - } 65 - 66 - /* Fast-path computation of checksum. Socket may not be locked. */ 67 - static inline __wsum udplite_csum(struct sk_buff *skb) 68 - { 69 - const int off = skb_transport_offset(skb); 70 - const struct sock *sk = skb->sk; 71 - int len = skb->len - off; 72 - 73 - if (udp_test_bit(UDPLITE_SEND_CC, sk)) { 74 - u16 pcslen = READ_ONCE(udp_sk(sk)->pcslen); 75 - 76 - if (pcslen < len) { 77 - if (pcslen > 0) 78 - len = pcslen; 79 - udp_hdr(skb)->len = htons(pcslen); 80 - } 81 - } 82 - skb->ip_summed = CHECKSUM_NONE; /* no HW support for checksumming */ 83 - 84 - return skb_checksum(skb, off, len, 0); 85 - } 86 - 87 - void udplite4_register(void); 88 - #endif /* _UDPLITE_H */
+2
include/uapi/linux/udp.h
··· 29 29 30 30 /* UDP socket options */ 31 31 #define UDP_CORK 1 /* Never send partially complete segments */ 32 + /* Deprecated, reserved for UDPLITE_SEND_CSCOV 10 */ 33 + /* Deprecated, reserved for UDPLITE_RECV_CSCOV 11 */ 32 34 #define UDP_ENCAP 100 /* Set the socket to accept encapsulated packets */ 33 35 #define UDP_NO_CHECK6_TX 101 /* Disable sending checksum for UDP6X */ 34 36 #define UDP_NO_CHECK6_RX 102 /* Disable accepting checksum for UDP6 */
+2 -3
net/core/filter.c
··· 6889 6889 else 6890 6890 sk = __udp4_lib_lookup(net, src4, tuple->ipv4.sport, 6891 6891 dst4, tuple->ipv4.dport, 6892 - dif, sdif, net->ipv4.udp_table, NULL); 6892 + dif, sdif, NULL); 6893 6893 #if IS_ENABLED(CONFIG_IPV6) 6894 6894 } else { 6895 6895 struct in6_addr *src6 = (struct in6_addr *)&tuple->ipv6.saddr; ··· 6904 6904 sk = ipv6_bpf_stub->udp6_lib_lookup(net, 6905 6905 src6, tuple->ipv6.sport, 6906 6906 dst6, tuple->ipv6.dport, 6907 - dif, sdif, 6908 - net->ipv4.udp_table, NULL); 6907 + dif, sdif, NULL); 6909 6908 #endif 6910 6909 } 6911 6910
+1 -1
net/ipv4/Makefile
··· 10 10 tcp.o tcp_input.o tcp_output.o tcp_timer.o tcp_ipv4.o \ 11 11 tcp_minisocks.o tcp_cong.o tcp_metrics.o tcp_fastopen.o \ 12 12 tcp_recovery.o tcp_ulp.o \ 13 - tcp_offload.o tcp_plb.o datagram.o raw.o udp.o udplite.o \ 13 + tcp_offload.o tcp_plb.o datagram.o raw.o udp.o \ 14 14 udp_offload.o arp.o icmp.o devinet.o af_inet.o igmp.o \ 15 15 fib_frontend.o fib_semantics.o fib_trie.o fib_notifier.o \ 16 16 inet_fragment.o ping.o ip_tunnel_core.o gre_offload.o \
-12
net/ipv4/af_inet.c
··· 104 104 #include <net/tcp.h> 105 105 #include <net/psp.h> 106 106 #include <net/udp.h> 107 - #include <net/udplite.h> 108 107 #include <net/ping.h> 109 108 #include <linux/skbuff.h> 110 109 #include <net/sock.h> ··· 883 884 } 884 885 EXPORT_SYMBOL_GPL(inet_splice_eof); 885 886 886 - INDIRECT_CALLABLE_DECLARE(int udp_recvmsg(struct sock *, struct msghdr *, 887 - size_t, int)); 888 887 int inet_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, 889 888 int flags) 890 889 { ··· 1733 1736 net->mib.udp_statistics = alloc_percpu(struct udp_mib); 1734 1737 if (!net->mib.udp_statistics) 1735 1738 goto err_udp_mib; 1736 - net->mib.udplite_statistics = alloc_percpu(struct udp_mib); 1737 - if (!net->mib.udplite_statistics) 1738 - goto err_udplite_mib; 1739 1739 net->mib.icmp_statistics = alloc_percpu(struct icmp_mib); 1740 1740 if (!net->mib.icmp_statistics) 1741 1741 goto err_icmp_mib; ··· 1746 1752 err_icmpmsg_mib: 1747 1753 free_percpu(net->mib.icmp_statistics); 1748 1754 err_icmp_mib: 1749 - free_percpu(net->mib.udplite_statistics); 1750 - err_udplite_mib: 1751 1755 free_percpu(net->mib.udp_statistics); 1752 1756 err_udp_mib: 1753 1757 free_percpu(net->mib.net_statistics); ··· 1761 1769 { 1762 1770 kfree(net->mib.icmpmsg_statistics); 1763 1771 free_percpu(net->mib.icmp_statistics); 1764 - free_percpu(net->mib.udplite_statistics); 1765 1772 free_percpu(net->mib.udp_statistics); 1766 1773 free_percpu(net->mib.net_statistics); 1767 1774 free_percpu(net->mib.ip_statistics); ··· 1975 1984 1976 1985 /* Setup UDP memory threshold */ 1977 1986 udp_init(); 1978 - 1979 - /* Add UDP-Lite (RFC 3828) */ 1980 - udplite4_register(); 1981 1987 1982 1988 raw_init(); 1983 1989
-16
net/ipv4/proc.c
··· 35 35 #include <net/mptcp.h> 36 36 #include <net/proto_memory.h> 37 37 #include <net/udp.h> 38 - #include <net/udplite.h> 39 38 #include <linux/bottom_half.h> 40 39 #include <linux/inetdevice.h> 41 40 #include <linux/proc_fs.h> ··· 64 65 seq_printf(seq, "UDP: inuse %d mem %ld\n", 65 66 sock_prot_inuse_get(net, &udp_prot), 66 67 proto_memory_allocated(&udp_prot)); 67 - seq_printf(seq, "UDPLITE: inuse %d\n", 68 - sock_prot_inuse_get(net, &udplite_prot)); 69 68 seq_printf(seq, "RAW: inuse %d\n", 70 69 sock_prot_inuse_get(net, &raw_prot)); 71 70 seq_printf(seq, "FRAG: inuse %u memory %lu\n", ··· 441 444 for (i = 0; i < udp_cnt; i++) 442 445 seq_printf(seq, " %s", snmp4_udp_list[i].name); 443 446 seq_puts(seq, "\nUdp:"); 444 - for (i = 0; i < udp_cnt; i++) 445 - seq_printf(seq, " %lu", buff[i]); 446 - 447 - memset(buff, 0, udp_cnt * sizeof(unsigned long)); 448 - 449 - /* the UDP and UDP-Lite MIBs are the same */ 450 - seq_puts(seq, "\nUdpLite:"); 451 - snmp_get_cpu_field_batch_cnt(buff, snmp4_udp_list, 452 - udp_cnt, 453 - net->mib.udplite_statistics); 454 - for (i = 0; i < udp_cnt; i++) 455 - seq_printf(seq, " %s", snmp4_udp_list[i].name); 456 - seq_puts(seq, "\nUdpLite:"); 457 447 for (i = 0; i < udp_cnt; i++) 458 448 seq_printf(seq, " %lu", buff[i]); 459 449
+142 -292
net/ipv4/udp.c
··· 98 98 #include <linux/skbuff.h> 99 99 #include <linux/proc_fs.h> 100 100 #include <linux/seq_file.h> 101 + #include <net/aligned_data.h> 101 102 #include <net/net_namespace.h> 102 103 #include <net/icmp.h> 104 + #include <net/inet_common.h> 103 105 #include <net/inet_hashtables.h> 104 106 #include <net/ip.h> 105 107 #include <net/ip_tunnels.h> ··· 114 112 #include <linux/btf_ids.h> 115 113 #include <trace/events/skb.h> 116 114 #include <net/busy_poll.h> 117 - #include "udp_impl.h" 118 115 #include <net/sock_reuseport.h> 119 116 #include <net/addrconf.h> 120 117 #include <net/udp_tunnel.h> ··· 133 132 134 133 #define MAX_UDP_PORTS 65536 135 134 #define PORTS_PER_CHAIN (MAX_UDP_PORTS / UDP_HTABLE_SIZE_MIN_PERNET) 136 - 137 - static struct udp_table *udp_get_table_prot(struct sock *sk) 138 - { 139 - return sk->sk_prot->h.udp_table ? : sock_net(sk)->ipv4.udp_table; 140 - } 141 135 142 136 static int udp_lib_lport_inuse(struct net *net, __u16 num, 143 137 const struct udp_hslot *hslot, ··· 225 229 } 226 230 227 231 /** 228 - * udp_lib_get_port - UDP/-Lite port lookup for IPv4 and IPv6 232 + * udp_lib_get_port - UDP port lookup for IPv4 and IPv6 229 233 * 230 234 * @sk: socket struct in question 231 235 * @snum: port number to look up ··· 235 239 int udp_lib_get_port(struct sock *sk, unsigned short snum, 236 240 unsigned int hash2_nulladdr) 237 241 { 238 - struct udp_table *udptable = udp_get_table_prot(sk); 239 242 struct udp_hslot *hslot, *hslot2; 240 243 struct net *net = sock_net(sk); 244 + struct udp_table *udptable; 241 245 int error = -EADDRINUSE; 246 + 247 + udptable = net->ipv4.udp_table; 242 248 243 249 if (!snum) { 244 250 DECLARE_BITMAP(bitmap, PORTS_PER_CHAIN); ··· 351 353 } 352 354 EXPORT_IPV6_MOD(udp_lib_get_port); 353 355 354 - int udp_v4_get_port(struct sock *sk, unsigned short snum) 356 + static int udp_v4_get_port(struct sock *sk, unsigned short snum) 355 357 { 356 358 unsigned int hash2_nulladdr = 357 359 ipv4_portaddr_hash(sock_net(sk), htonl(INADDR_ANY), snum); ··· 673 675 * harder than this. -DaveM 674 676 */ 675 677 struct sock *__udp4_lib_lookup(const struct net *net, __be32 saddr, 676 - __be16 sport, __be32 daddr, __be16 dport, int dif, 677 - int sdif, struct udp_table *udptable, struct sk_buff *skb) 678 + __be16 sport, __be32 daddr, __be16 dport, 679 + int dif, int sdif, struct sk_buff *skb) 678 680 { 681 + struct udp_table *udptable = net->ipv4.udp_table; 679 682 unsigned short hnum = ntohs(dport); 680 683 struct udp_hslot *hslot2; 681 684 struct sock *result, *sk; ··· 700 701 goto done; 701 702 702 703 /* Lookup redirect from BPF */ 703 - if (static_branch_unlikely(&bpf_sk_lookup_enabled) && 704 - udptable == net->ipv4.udp_table) { 704 + if (static_branch_unlikely(&bpf_sk_lookup_enabled)) { 705 705 sk = inet_lookup_run_sk_lookup(net, IPPROTO_UDP, skb, sizeof(struct udphdr), 706 706 saddr, sport, daddr, hnum, dif, 707 707 udp_ehashfn); ··· 742 744 EXPORT_SYMBOL_GPL(__udp4_lib_lookup); 743 745 744 746 static inline struct sock *__udp4_lib_lookup_skb(struct sk_buff *skb, 745 - __be16 sport, __be16 dport, 746 - struct udp_table *udptable) 747 + __be16 sport, __be16 dport) 747 748 { 748 749 const struct iphdr *iph = ip_hdr(skb); 749 750 750 751 return __udp4_lib_lookup(dev_net(skb->dev), iph->saddr, sport, 751 752 iph->daddr, dport, inet_iif(skb), 752 - inet_sdif(skb), udptable, skb); 753 + inet_sdif(skb), skb); 753 754 } 754 755 755 756 struct sock *udp4_lib_lookup_skb(const struct sk_buff *skb, ··· 756 759 { 757 760 const u16 offset = NAPI_GRO_CB(skb)->network_offsets[skb->encapsulation]; 758 761 const struct iphdr *iph = (struct iphdr *)(skb->data + offset); 759 - struct net *net = dev_net(skb->dev); 760 762 int iif, sdif; 761 763 762 764 inet_get_iif_sdif(skb, &iif, &sdif); 763 765 764 - return __udp4_lib_lookup(net, iph->saddr, sport, 765 - iph->daddr, dport, iif, 766 - sdif, net->ipv4.udp_table, NULL); 766 + return __udp4_lib_lookup(dev_net(skb->dev), iph->saddr, sport, 767 + iph->daddr, dport, iif, sdif, NULL); 767 768 } 768 769 769 770 /* Must be called under rcu_read_lock(). ··· 773 778 { 774 779 struct sock *sk; 775 780 776 - sk = __udp4_lib_lookup(net, saddr, sport, daddr, dport, 777 - dif, 0, net->ipv4.udp_table, NULL); 781 + sk = __udp4_lib_lookup(net, saddr, sport, daddr, dport, dif, 0, NULL); 778 782 if (sk && !refcount_inc_not_zero(&sk->sk_refcnt)) 779 783 sk = NULL; 780 784 return sk; ··· 863 869 static struct sock *__udp4_lib_err_encap(struct net *net, 864 870 const struct iphdr *iph, 865 871 struct udphdr *uh, 866 - struct udp_table *udptable, 867 872 struct sock *sk, 868 873 struct sk_buff *skb, u32 info) 869 874 { ··· 890 897 } 891 898 892 899 sk = __udp4_lib_lookup(net, iph->daddr, uh->source, 893 - iph->saddr, uh->dest, skb->dev->ifindex, 0, 894 - udptable, NULL); 900 + iph->saddr, uh->dest, skb->dev->ifindex, 0, NULL); 895 901 if (sk) { 896 902 up = udp_sk(sk); 897 903 ··· 919 927 * header points to the first 8 bytes of the udp header. We need 920 928 * to find the appropriate port. 921 929 */ 922 - 923 - int __udp4_lib_err(struct sk_buff *skb, u32 info, struct udp_table *udptable) 930 + int udp_err(struct sk_buff *skb, u32 info) 924 931 { 925 - struct inet_sock *inet; 926 932 const struct iphdr *iph = (const struct iphdr *)skb->data; 927 - struct udphdr *uh = (struct udphdr *)(skb->data+(iph->ihl<<2)); 928 933 const int type = icmp_hdr(skb)->type; 929 934 const int code = icmp_hdr(skb)->code; 935 + struct net *net = dev_net(skb->dev); 936 + struct inet_sock *inet; 930 937 bool tunnel = false; 938 + struct udphdr *uh; 931 939 struct sock *sk; 932 940 int harderr; 933 941 int err; 934 - struct net *net = dev_net(skb->dev); 935 942 943 + uh = (struct udphdr *)(skb->data + (iph->ihl << 2)); 936 944 sk = __udp4_lib_lookup(net, iph->daddr, uh->dest, 937 945 iph->saddr, uh->source, skb->dev->ifindex, 938 - inet_sdif(skb), udptable, NULL); 946 + inet_sdif(skb), NULL); 939 947 940 948 if (!sk || READ_ONCE(udp_sk(sk)->encap_type)) { 941 949 /* No socket for error: try tunnels before discarding */ 942 950 if (static_branch_unlikely(&udp_encap_needed_key)) { 943 - sk = __udp4_lib_err_encap(net, iph, uh, udptable, sk, skb, 944 - info); 951 + sk = __udp4_lib_err_encap(net, iph, uh, sk, skb, info); 945 952 if (!sk) 946 953 return 0; 947 954 } else ··· 1011 1020 sk_error_report(sk); 1012 1021 out: 1013 1022 return 0; 1014 - } 1015 - 1016 - int udp_err(struct sk_buff *skb, u32 info) 1017 - { 1018 - return __udp4_lib_err(skb, info, dev_net(skb->dev)->ipv4.udp_table); 1019 1023 } 1020 1024 1021 1025 /* ··· 1104 1118 struct inet_cork *cork) 1105 1119 { 1106 1120 struct sock *sk = skb->sk; 1107 - struct inet_sock *inet = inet_sk(sk); 1121 + int offset, len, datalen; 1108 1122 struct udphdr *uh; 1109 1123 int err; 1110 - int is_udplite = IS_UDPLITE(sk); 1111 - int offset = skb_transport_offset(skb); 1112 - int len = skb->len - offset; 1113 - int datalen = len - sizeof(*uh); 1114 - __wsum csum = 0; 1124 + 1125 + offset = skb_transport_offset(skb); 1126 + len = skb->len - offset; 1127 + datalen = len - sizeof(*uh); 1115 1128 1116 1129 /* 1117 1130 * Create a UDP header 1118 1131 */ 1119 1132 uh = udp_hdr(skb); 1120 - uh->source = inet->inet_sport; 1133 + uh->source = inet_sk(sk)->inet_sport; 1121 1134 uh->dest = fl4->fl4_dport; 1122 1135 uh->len = htons(len); 1123 1136 uh->check = 0; ··· 1137 1152 kfree_skb(skb); 1138 1153 return -EINVAL; 1139 1154 } 1140 - if (is_udplite || dst_xfrm(skb_dst(skb))) { 1155 + if (dst_xfrm(skb_dst(skb))) { 1141 1156 kfree_skb(skb); 1142 1157 return -EIO; 1143 1158 } ··· 1153 1168 } 1154 1169 } 1155 1170 1156 - if (is_udplite) /* UDP-Lite */ 1157 - csum = udplite_csum(skb); 1158 - 1159 - else if (sk->sk_no_check_tx) { /* UDP csum off */ 1160 - 1171 + if (sk->sk_no_check_tx) { /* UDP csum off */ 1161 1172 skb->ip_summed = CHECKSUM_NONE; 1162 1173 goto send; 1163 - 1164 1174 } else if (skb->ip_summed == CHECKSUM_PARTIAL) { /* UDP hardware csum */ 1165 1175 csum_partial: 1166 - 1167 1176 udp4_hwcsum(skb, fl4->saddr, fl4->daddr); 1168 1177 goto send; 1169 - 1170 - } else 1171 - csum = udp_csum(skb); 1178 + } 1172 1179 1173 1180 /* add protocol-dependent pseudo-header */ 1174 1181 uh->check = csum_tcpudp_magic(fl4->saddr, fl4->daddr, len, 1175 - sk->sk_protocol, csum); 1182 + IPPROTO_UDP, udp_csum(skb)); 1176 1183 if (uh->check == 0) 1177 1184 uh->check = CSUM_MANGLED_0; 1178 1185 ··· 1173 1196 if (unlikely(err)) { 1174 1197 if (err == -ENOBUFS && 1175 1198 !inet_test_bit(RECVERR, sk)) { 1176 - UDP_INC_STATS(sock_net(sk), 1177 - UDP_MIB_SNDBUFERRORS, is_udplite); 1199 + UDP_INC_STATS(sock_net(sk), UDP_MIB_SNDBUFERRORS); 1178 1200 err = 0; 1179 1201 } 1180 - } else 1181 - UDP_INC_STATS(sock_net(sk), 1182 - UDP_MIB_OUTDATAGRAMS, is_udplite); 1202 + } else { 1203 + UDP_INC_STATS(sock_net(sk), UDP_MIB_OUTDATAGRAMS); 1204 + } 1183 1205 return err; 1184 1206 } 1185 1207 ··· 1245 1269 1246 1270 int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) 1247 1271 { 1272 + int corkreq = udp_test_bit(CORK, sk) || msg->msg_flags & MSG_MORE; 1248 1273 DEFINE_RAW_FLEX(struct ip_options_rcu, opt_copy, opt.__data, 1249 1274 IP_OPTIONS_DATA_FIXED_SIZE); 1275 + DECLARE_SOCKADDR(struct sockaddr_in *, usin, msg->msg_name); 1276 + int ulen = len, free = 0, connected = 0; 1250 1277 struct inet_sock *inet = inet_sk(sk); 1251 1278 struct udp_sock *up = udp_sk(sk); 1252 - DECLARE_SOCKADDR(struct sockaddr_in *, usin, msg->msg_name); 1253 - struct flowi4 fl4_stack; 1254 - struct flowi4 *fl4; 1255 - int ulen = len; 1256 - struct ipcm_cookie ipc; 1257 - struct rtable *rt = NULL; 1258 - int free = 0; 1259 - int connected = 0; 1260 1279 __be32 daddr, faddr, saddr; 1261 - u8 scope; 1262 - __be16 dport; 1263 - int err, is_udplite = IS_UDPLITE(sk); 1264 - int corkreq = udp_test_bit(CORK, sk) || msg->msg_flags & MSG_MORE; 1265 - int (*getfrag)(void *, char *, int, int, int, struct sk_buff *); 1280 + struct rtable *rt = NULL; 1281 + struct flowi4 fl4_stack; 1282 + struct ipcm_cookie ipc; 1266 1283 struct sk_buff *skb; 1284 + struct flowi4 *fl4; 1285 + __be16 dport; 1267 1286 int uc_index; 1287 + u8 scope; 1288 + int err; 1268 1289 1269 1290 if (len > 0xFFFF) 1270 1291 return -EMSGSIZE; ··· 1272 1299 1273 1300 if (msg->msg_flags & MSG_OOB) /* Mirror BSD error message compatibility */ 1274 1301 return -EOPNOTSUPP; 1275 - 1276 - getfrag = is_udplite ? udplite_getfrag : ip_generic_getfrag; 1277 1302 1278 1303 fl4 = &inet->cork.fl.u.ip4; 1279 1304 if (READ_ONCE(up->pending)) { ··· 1414 1443 1415 1444 flowi4_init_output(fl4, ipc.oif, ipc.sockc.mark, 1416 1445 ipc.tos & INET_DSCP_MASK, scope, 1417 - sk->sk_protocol, flow_flags, faddr, saddr, 1446 + IPPROTO_UDP, flow_flags, faddr, saddr, 1418 1447 dport, inet->inet_sport, 1419 1448 sk_uid(sk)); 1420 1449 ··· 1448 1477 if (!corkreq) { 1449 1478 struct inet_cork cork; 1450 1479 1451 - skb = ip_make_skb(sk, fl4, getfrag, msg, ulen, 1480 + skb = ip_make_skb(sk, fl4, ip_generic_getfrag, msg, ulen, 1452 1481 sizeof(struct udphdr), &ipc, &rt, 1453 1482 &cork, msg->msg_flags); 1454 1483 err = PTR_ERR(skb); ··· 1479 1508 1480 1509 do_append_data: 1481 1510 up->len += ulen; 1482 - err = ip_append_data(sk, fl4, getfrag, msg, ulen, 1511 + err = ip_append_data(sk, fl4, ip_generic_getfrag, msg, ulen, 1483 1512 sizeof(struct udphdr), &ipc, &rt, 1484 1513 corkreq ? msg->msg_flags|MSG_MORE : msg->msg_flags); 1485 1514 if (err) ··· 1504 1533 * things). We could add another new stat but at least for now that 1505 1534 * seems like overkill. 1506 1535 */ 1507 - if (err == -ENOBUFS || test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) { 1508 - UDP_INC_STATS(sock_net(sk), 1509 - UDP_MIB_SNDBUFERRORS, is_udplite); 1510 - } 1536 + if (err == -ENOBUFS || test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) 1537 + UDP_INC_STATS(sock_net(sk), UDP_MIB_SNDBUFERRORS); 1538 + 1511 1539 return err; 1512 1540 1513 1541 do_confirm: ··· 1825 1855 inet_sock_destruct(sk); 1826 1856 } 1827 1857 1828 - int udp_init_sock(struct sock *sk) 1858 + static int udp_init_sock(struct sock *sk) 1829 1859 { 1830 1860 int res = udp_lib_init_sock(sk); 1831 1861 ··· 1865 1895 1866 1896 while ((skb = skb_peek(rcvq)) != NULL) { 1867 1897 if (udp_lib_checksum_complete(skb)) { 1868 - __UDP_INC_STATS(sock_net(sk), UDP_MIB_CSUMERRORS, 1869 - IS_UDPLITE(sk)); 1870 - __UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, 1871 - IS_UDPLITE(sk)); 1898 + struct net *net = sock_net(sk); 1899 + 1900 + __UDP_INC_STATS(net, UDP_MIB_CSUMERRORS); 1901 + __UDP_INC_STATS(net, UDP_MIB_INERRORS); 1872 1902 udp_drops_inc(sk); 1873 1903 __skb_unlink(skb, rcvq); 1874 1904 *total += skb->truesize; ··· 2020 2050 return err; 2021 2051 2022 2052 if (udp_lib_checksum_complete(skb)) { 2023 - int is_udplite = IS_UDPLITE(sk); 2024 2053 struct net *net = sock_net(sk); 2025 2054 2026 - __UDP_INC_STATS(net, UDP_MIB_CSUMERRORS, is_udplite); 2027 - __UDP_INC_STATS(net, UDP_MIB_INERRORS, is_udplite); 2055 + __UDP_INC_STATS(net, UDP_MIB_CSUMERRORS); 2056 + __UDP_INC_STATS(net, UDP_MIB_INERRORS); 2028 2057 udp_drops_inc(sk); 2029 2058 kfree_skb_reason(skb, SKB_DROP_REASON_UDP_CSUM); 2030 2059 goto try_again; ··· 2039 2070 * return it, otherwise we block. 2040 2071 */ 2041 2072 2073 + INDIRECT_CALLABLE_SCOPE 2042 2074 int udp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int flags) 2043 2075 { 2044 - struct inet_sock *inet = inet_sk(sk); 2045 2076 DECLARE_SOCKADDR(struct sockaddr_in *, sin, msg->msg_name); 2046 - struct sk_buff *skb; 2047 - unsigned int ulen, copied; 2048 2077 int off, err, peeking = flags & MSG_PEEK; 2049 - int is_udplite = IS_UDPLITE(sk); 2078 + struct inet_sock *inet = inet_sk(sk); 2079 + struct net *net = sock_net(sk); 2050 2080 bool checksum_valid = false; 2081 + unsigned int ulen, copied; 2082 + struct sk_buff *skb; 2051 2083 2052 2084 if (flags & MSG_ERRQUEUE) 2053 2085 return ip_recv_error(sk, msg, len); ··· 2066 2096 else if (copied < ulen) 2067 2097 msg->msg_flags |= MSG_TRUNC; 2068 2098 2069 - /* 2070 - * If checksum is needed at all, try to do it while copying the 2071 - * data. If the data is truncated, or if we only want a partial 2072 - * coverage checksum (UDP-Lite), do it before the copy. 2099 + /* If checksum is needed at all, try to do it while copying the 2100 + * data. If the data is truncated, do it before the copy. 2073 2101 */ 2074 - 2075 - if (copied < ulen || peeking || 2076 - (is_udplite && UDP_SKB_CB(skb)->partial_cov)) { 2102 + if (copied < ulen || peeking) { 2077 2103 checksum_valid = udp_skb_csum_unnecessary(skb) || 2078 2104 !__udp_lib_checksum_complete(skb); 2079 2105 if (!checksum_valid) ··· 2091 2125 if (unlikely(err)) { 2092 2126 if (!peeking) { 2093 2127 udp_drops_inc(sk); 2094 - UDP_INC_STATS(sock_net(sk), 2095 - UDP_MIB_INERRORS, is_udplite); 2128 + UDP_INC_STATS(net, UDP_MIB_INERRORS); 2096 2129 } 2097 2130 kfree_skb(skb); 2098 2131 return err; 2099 2132 } 2100 2133 2101 2134 if (!peeking) 2102 - UDP_INC_STATS(sock_net(sk), 2103 - UDP_MIB_INDATAGRAMS, is_udplite); 2135 + UDP_INC_STATS(net, UDP_MIB_INDATAGRAMS); 2104 2136 2105 2137 sock_recv_cmsgs(msg, sk, skb); 2106 2138 ··· 2131 2167 csum_copy_err: 2132 2168 if (!__sk_queue_drop_skb(sk, &udp_sk(sk)->reader_queue, skb, flags, 2133 2169 udp_skb_destructor)) { 2134 - UDP_INC_STATS(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite); 2135 - UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite); 2170 + UDP_INC_STATS(net, UDP_MIB_CSUMERRORS); 2171 + UDP_INC_STATS(net, UDP_MIB_INERRORS); 2136 2172 } 2137 2173 kfree_skb_reason(skb, SKB_DROP_REASON_UDP_CSUM); 2138 2174 ··· 2209 2245 void udp_lib_unhash(struct sock *sk) 2210 2246 { 2211 2247 if (sk_hashed(sk)) { 2212 - struct udp_table *udptable = udp_get_table_prot(sk); 2213 2248 struct udp_hslot *hslot, *hslot2; 2249 + struct net *net = sock_net(sk); 2250 + struct udp_table *udptable; 2214 2251 2215 2252 sock_rps_delete_flow(sk); 2216 - hslot = udp_hashslot(udptable, sock_net(sk), 2217 - udp_sk(sk)->udp_port_hash); 2253 + udptable = net->ipv4.udp_table; 2254 + hslot = udp_hashslot(udptable, net, udp_sk(sk)->udp_port_hash); 2218 2255 hslot2 = udp_hashslot2(udptable, udp_sk(sk)->udp_portaddr_hash); 2219 2256 2220 2257 spin_lock_bh(&hslot->lock); ··· 2224 2259 if (sk_del_node_init_rcu(sk)) { 2225 2260 hslot->count--; 2226 2261 inet_sk(sk)->inet_num = 0; 2227 - sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); 2262 + sock_prot_inuse_add(net, sk->sk_prot, -1); 2228 2263 2229 2264 spin_lock(&hslot2->lock); 2230 2265 hlist_del_init_rcu(&udp_sk(sk)->udp_portaddr_node); ··· 2244 2279 void udp_lib_rehash(struct sock *sk, u16 newhash, u16 newhash4) 2245 2280 { 2246 2281 if (sk_hashed(sk)) { 2247 - struct udp_table *udptable = udp_get_table_prot(sk); 2248 2282 struct udp_hslot *hslot, *hslot2, *nhslot2; 2283 + struct net *net = sock_net(sk); 2284 + struct udp_table *udptable; 2249 2285 2250 - hslot = udp_hashslot(udptable, sock_net(sk), 2251 - udp_sk(sk)->udp_port_hash); 2286 + udptable = net->ipv4.udp_table; 2287 + hslot = udp_hashslot(udptable, net, udp_sk(sk)->udp_port_hash); 2252 2288 hslot2 = udp_hashslot2(udptable, udp_sk(sk)->udp_portaddr_hash); 2253 2289 nhslot2 = udp_hashslot2(udptable, newhash); 2254 2290 ··· 2308 2342 } 2309 2343 EXPORT_IPV6_MOD(udp_lib_rehash); 2310 2344 2311 - void udp_v4_rehash(struct sock *sk) 2345 + static void udp_v4_rehash(struct sock *sk) 2312 2346 { 2313 2347 u16 new_hash = ipv4_portaddr_hash(sock_net(sk), 2314 2348 inet_sk(sk)->inet_rcv_saddr, ··· 2334 2368 2335 2369 rc = __udp_enqueue_schedule_skb(sk, skb); 2336 2370 if (rc < 0) { 2337 - int is_udplite = IS_UDPLITE(sk); 2371 + struct net *net = sock_net(sk); 2338 2372 int drop_reason; 2339 2373 2340 2374 /* Note that an ENOMEM error is charged twice */ 2341 2375 if (rc == -ENOMEM) { 2342 - UDP_INC_STATS(sock_net(sk), UDP_MIB_RCVBUFERRORS, 2343 - is_udplite); 2376 + UDP_INC_STATS(net, UDP_MIB_RCVBUFERRORS); 2344 2377 drop_reason = SKB_DROP_REASON_SOCKET_RCVBUFF; 2345 2378 } else { 2346 - UDP_INC_STATS(sock_net(sk), UDP_MIB_MEMERRORS, 2347 - is_udplite); 2379 + UDP_INC_STATS(net, UDP_MIB_MEMERRORS); 2348 2380 drop_reason = SKB_DROP_REASON_PROTO_MEM; 2349 2381 } 2350 - UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite); 2382 + UDP_INC_STATS(net, UDP_MIB_INERRORS); 2351 2383 trace_udp_fail_queue_rcv_skb(rc, sk, skb); 2352 2384 sk_skb_reason_drop(sk, skb, drop_reason); 2353 2385 return -1; ··· 2366 2402 { 2367 2403 enum skb_drop_reason drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; 2368 2404 struct udp_sock *up = udp_sk(sk); 2369 - int is_udplite = IS_UDPLITE(sk); 2405 + struct net *net = sock_net(sk); 2370 2406 2371 2407 /* 2372 2408 * Charge it to the socket, dropping if the queue is full. ··· 2403 2439 2404 2440 ret = encap_rcv(sk, skb); 2405 2441 if (ret <= 0) { 2406 - __UDP_INC_STATS(sock_net(sk), 2407 - UDP_MIB_INDATAGRAMS, 2408 - is_udplite); 2442 + __UDP_INC_STATS(net, UDP_MIB_INDATAGRAMS); 2409 2443 return -ret; 2410 2444 } 2411 2445 } 2412 2446 2413 2447 /* FALLTHROUGH -- it's a UDP Packet */ 2414 - } 2415 - 2416 - /* 2417 - * UDP-Lite specific tests, ignored on UDP sockets 2418 - */ 2419 - if (unlikely(udp_test_bit(UDPLITE_RECV_CC, sk) && 2420 - UDP_SKB_CB(skb)->partial_cov)) { 2421 - u16 pcrlen = READ_ONCE(up->pcrlen); 2422 - 2423 - /* 2424 - * MIB statistics other than incrementing the error count are 2425 - * disabled for the following two types of errors: these depend 2426 - * on the application settings, not on the functioning of the 2427 - * protocol stack as such. 2428 - * 2429 - * RFC 3828 here recommends (sec 3.3): "There should also be a 2430 - * way ... to ... at least let the receiving application block 2431 - * delivery of packets with coverage values less than a value 2432 - * provided by the application." 2433 - */ 2434 - if (pcrlen == 0) { /* full coverage was set */ 2435 - net_dbg_ratelimited("UDPLite: partial coverage %d while full coverage %d requested\n", 2436 - UDP_SKB_CB(skb)->cscov, skb->len); 2437 - goto drop; 2438 - } 2439 - /* The next case involves violating the min. coverage requested 2440 - * by the receiver. This is subtle: if receiver wants x and x is 2441 - * greater than the buffersize/MTU then receiver will complain 2442 - * that it wants x while sender emits packets of smaller size y. 2443 - * Therefore the above ...()->partial_cov statement is essential. 2444 - */ 2445 - if (UDP_SKB_CB(skb)->cscov < pcrlen) { 2446 - net_dbg_ratelimited("UDPLite: coverage %d too small, need min %d\n", 2447 - UDP_SKB_CB(skb)->cscov, pcrlen); 2448 - goto drop; 2449 - } 2450 2448 } 2451 2449 2452 2450 prefetch(&sk->sk_rmem_alloc); ··· 2426 2500 2427 2501 csum_error: 2428 2502 drop_reason = SKB_DROP_REASON_UDP_CSUM; 2429 - __UDP_INC_STATS(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite); 2503 + __UDP_INC_STATS(net, UDP_MIB_CSUMERRORS); 2430 2504 drop: 2431 - __UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite); 2505 + __UDP_INC_STATS(net, UDP_MIB_INERRORS); 2432 2506 udp_drops_inc(sk); 2433 2507 sk_skb_reason_drop(sk, skb, drop_reason); 2434 2508 return -1; ··· 2479 2553 */ 2480 2554 static int __udp4_lib_mcast_deliver(struct net *net, struct sk_buff *skb, 2481 2555 struct udphdr *uh, 2482 - __be32 saddr, __be32 daddr, 2483 - struct udp_table *udptable, 2484 - int proto) 2556 + __be32 saddr, __be32 daddr) 2485 2557 { 2486 - struct sock *sk, *first = NULL; 2558 + struct udp_table *udptable = net->ipv4.udp_table; 2559 + unsigned int hash2, hash2_any, offset; 2487 2560 unsigned short hnum = ntohs(uh->dest); 2488 - struct udp_hslot *hslot = udp_hashslot(udptable, net, hnum); 2489 - unsigned int hash2 = 0, hash2_any = 0, use_hash2 = (hslot->count > 10); 2490 - unsigned int offset = offsetof(typeof(*sk), sk_node); 2561 + struct sock *sk, *first = NULL; 2491 2562 int dif = skb->dev->ifindex; 2492 2563 int sdif = inet_sdif(skb); 2493 2564 struct hlist_node *node; 2565 + struct udp_hslot *hslot; 2494 2566 struct sk_buff *nskb; 2567 + bool use_hash2; 2568 + 2569 + hash2_any = 0; 2570 + hash2 = 0; 2571 + hslot = udp_hashslot(udptable, net, hnum); 2572 + use_hash2 = hslot->count > 10; 2573 + offset = offsetof(typeof(*sk), sk_node); 2495 2574 2496 2575 if (use_hash2) { 2497 2576 hash2_any = ipv4_portaddr_hash(net, htonl(INADDR_ANY), hnum) & ··· 2520 2589 2521 2590 if (unlikely(!nskb)) { 2522 2591 udp_drops_inc(sk); 2523 - __UDP_INC_STATS(net, UDP_MIB_RCVBUFERRORS, 2524 - IS_UDPLITE(sk)); 2525 - __UDP_INC_STATS(net, UDP_MIB_INERRORS, 2526 - IS_UDPLITE(sk)); 2592 + __UDP_INC_STATS(net, UDP_MIB_RCVBUFERRORS); 2593 + __UDP_INC_STATS(net, UDP_MIB_INERRORS); 2527 2594 continue; 2528 2595 } 2529 2596 if (udp_queue_rcv_skb(sk, nskb) > 0) ··· 2539 2610 consume_skb(skb); 2540 2611 } else { 2541 2612 kfree_skb(skb); 2542 - __UDP_INC_STATS(net, UDP_MIB_IGNOREDMULTI, 2543 - proto == IPPROTO_UDPLITE); 2613 + __UDP_INC_STATS(net, UDP_MIB_IGNOREDMULTI); 2544 2614 } 2545 2615 return 0; 2546 2616 } ··· 2549 2621 * Otherwise, csum completion requires checksumming packet body, 2550 2622 * including udp header and folding it to skb->csum. 2551 2623 */ 2552 - static inline int udp4_csum_init(struct sk_buff *skb, struct udphdr *uh, 2553 - int proto) 2624 + static inline int udp4_csum_init(struct sk_buff *skb, struct udphdr *uh) 2554 2625 { 2555 2626 int err; 2556 - 2557 - UDP_SKB_CB(skb)->partial_cov = 0; 2558 - UDP_SKB_CB(skb)->cscov = skb->len; 2559 - 2560 - if (proto == IPPROTO_UDPLITE) { 2561 - err = udplite_checksum_init(skb, uh); 2562 - if (err) 2563 - return err; 2564 - 2565 - if (UDP_SKB_CB(skb)->partial_cov) { 2566 - skb->csum = inet_compute_pseudo(skb, proto); 2567 - return 0; 2568 - } 2569 - } 2570 2627 2571 2628 /* Note, we are only interested in != 0 or == 0, thus the 2572 2629 * force to int. 2573 2630 */ 2574 - err = (__force int)skb_checksum_init_zero_check(skb, proto, uh->check, 2631 + err = (__force int)skb_checksum_init_zero_check(skb, IPPROTO_UDP, uh->check, 2575 2632 inet_compute_pseudo); 2576 2633 if (err) 2577 2634 return err; ··· 2584 2671 { 2585 2672 int ret; 2586 2673 2587 - if (inet_get_convert_csum(sk) && uh->check && !IS_UDPLITE(sk)) 2674 + if (inet_get_convert_csum(sk) && uh->check) 2588 2675 skb_checksum_try_convert(skb, IPPROTO_UDP, inet_compute_pseudo); 2589 2676 2590 2677 ret = udp_queue_rcv_skb(sk, skb); ··· 2601 2688 * All we need to do is get the socket, and then do a checksum. 2602 2689 */ 2603 2690 2604 - int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, 2605 - int proto) 2691 + int udp_rcv(struct sk_buff *skb) 2606 2692 { 2607 - struct sock *sk = NULL; 2608 - struct udphdr *uh; 2609 - unsigned short ulen; 2610 2693 struct rtable *rt = skb_rtable(skb); 2611 - __be32 saddr, daddr; 2612 2694 struct net *net = dev_net(skb->dev); 2695 + struct sock *sk = NULL; 2696 + unsigned short ulen; 2697 + __be32 saddr, daddr; 2698 + struct udphdr *uh; 2613 2699 bool refcounted; 2614 2700 int drop_reason; 2615 2701 ··· 2628 2716 if (ulen > skb->len) 2629 2717 goto short_packet; 2630 2718 2631 - if (proto == IPPROTO_UDP) { 2632 - /* UDP validates ulen. */ 2633 - if (ulen < sizeof(*uh) || pskb_trim_rcsum(skb, ulen)) 2719 + if (ulen < sizeof(*uh)) 2720 + goto short_packet; 2721 + 2722 + if (ulen < skb->len) { 2723 + if (pskb_trim_rcsum(skb, ulen)) 2634 2724 goto short_packet; 2725 + 2635 2726 uh = udp_hdr(skb); 2636 2727 } 2637 2728 2638 - if (udp4_csum_init(skb, uh, proto)) 2729 + if (udp4_csum_init(skb, uh)) 2639 2730 goto csum_error; 2640 2731 2641 2732 sk = inet_steal_sock(net, skb, sizeof(struct udphdr), saddr, uh->source, daddr, uh->dest, ··· 2660 2745 } 2661 2746 2662 2747 if (rt->rt_flags & (RTCF_BROADCAST|RTCF_MULTICAST)) 2663 - return __udp4_lib_mcast_deliver(net, skb, uh, 2664 - saddr, daddr, udptable, proto); 2748 + return __udp4_lib_mcast_deliver(net, skb, uh, saddr, daddr); 2665 2749 2666 - sk = __udp4_lib_lookup_skb(skb, uh->source, uh->dest, udptable); 2750 + sk = __udp4_lib_lookup_skb(skb, uh->source, uh->dest); 2667 2751 if (sk) 2668 2752 return udp_unicast_rcv_skb(sk, skb, uh); 2669 2753 no_sk: ··· 2675 2761 goto csum_error; 2676 2762 2677 2763 drop_reason = SKB_DROP_REASON_NO_SOCKET; 2678 - __UDP_INC_STATS(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE); 2764 + __UDP_INC_STATS(net, UDP_MIB_NOPORTS); 2679 2765 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0); 2680 2766 2681 2767 /* ··· 2687 2773 2688 2774 short_packet: 2689 2775 drop_reason = SKB_DROP_REASON_PKT_TOO_SMALL; 2690 - net_dbg_ratelimited("UDP%s: short packet: From %pI4:%u %d/%d to %pI4:%u\n", 2691 - proto == IPPROTO_UDPLITE ? "Lite" : "", 2776 + net_dbg_ratelimited("UDP: short packet: From %pI4:%u %d/%d to %pI4:%u\n", 2692 2777 &saddr, ntohs(uh->source), 2693 2778 ulen, skb->len, 2694 2779 &daddr, ntohs(uh->dest)); ··· 2699 2786 * the network is concerned, anyway) as per 4.1.3.4 (MUST). 2700 2787 */ 2701 2788 drop_reason = SKB_DROP_REASON_UDP_CSUM; 2702 - net_dbg_ratelimited("UDP%s: bad checksum. From %pI4:%u to %pI4:%u ulen %d\n", 2703 - proto == IPPROTO_UDPLITE ? "Lite" : "", 2789 + net_dbg_ratelimited("UDP: bad checksum. From %pI4:%u to %pI4:%u ulen %d\n", 2704 2790 &saddr, ntohs(uh->source), &daddr, ntohs(uh->dest), 2705 2791 ulen); 2706 - __UDP_INC_STATS(net, UDP_MIB_CSUMERRORS, proto == IPPROTO_UDPLITE); 2792 + __UDP_INC_STATS(net, UDP_MIB_CSUMERRORS); 2707 2793 drop: 2708 - __UDP_INC_STATS(net, UDP_MIB_INERRORS, proto == IPPROTO_UDPLITE); 2794 + __UDP_INC_STATS(net, UDP_MIB_INERRORS); 2709 2795 sk_skb_reason_drop(sk, skb, drop_reason); 2710 2796 return 0; 2711 2797 } ··· 2842 2930 return SKB_NOT_DROPPED_YET; 2843 2931 } 2844 2932 2845 - int udp_rcv(struct sk_buff *skb) 2846 - { 2847 - return __udp4_lib_rcv(skb, dev_net(skb->dev)->ipv4.udp_table, IPPROTO_UDP); 2848 - } 2849 - 2850 - void udp_destroy_sock(struct sock *sk) 2933 + static void udp_destroy_sock(struct sock *sk) 2851 2934 { 2852 2935 struct udp_sock *up = udp_sk(sk); 2853 2936 bool slow = lock_sock_fast(sk); ··· 2906 2999 struct udp_sock *up = udp_sk(sk); 2907 3000 int val, valbool; 2908 3001 int err = 0; 2909 - int is_udplite = IS_UDPLITE(sk); 2910 3002 2911 3003 if (level == SOL_SOCKET) { 2912 3004 err = sk_setsockopt(sk, level, optname, optval, optlen); ··· 2992 3086 sockopt_release_sock(sk); 2993 3087 break; 2994 3088 2995 - /* 2996 - * UDP-Lite's partial checksum coverage (RFC 3828). 2997 - */ 2998 - /* The sender sets actual checksum coverage length via this option. 2999 - * The case coverage > packet length is handled by send module. */ 3000 - case UDPLITE_SEND_CSCOV: 3001 - if (!is_udplite) /* Disable the option on UDP sockets */ 3002 - return -ENOPROTOOPT; 3003 - if (val != 0 && val < 8) /* Illegal coverage: use default (8) */ 3004 - val = 8; 3005 - else if (val > USHRT_MAX) 3006 - val = USHRT_MAX; 3007 - WRITE_ONCE(up->pcslen, val); 3008 - udp_set_bit(UDPLITE_SEND_CC, sk); 3009 - break; 3010 - 3011 - /* The receiver specifies a minimum checksum coverage value. To make 3012 - * sense, this should be set to at least 8 (as done below). If zero is 3013 - * used, this again means full checksum coverage. */ 3014 - case UDPLITE_RECV_CSCOV: 3015 - if (!is_udplite) /* Disable the option on UDP sockets */ 3016 - return -ENOPROTOOPT; 3017 - if (val != 0 && val < 8) /* Avoid silly minimal values. */ 3018 - val = 8; 3019 - else if (val > USHRT_MAX) 3020 - val = USHRT_MAX; 3021 - WRITE_ONCE(up->pcrlen, val); 3022 - udp_set_bit(UDPLITE_RECV_CC, sk); 3023 - break; 3024 - 3025 3089 default: 3026 3090 err = -ENOPROTOOPT; 3027 3091 break; ··· 3001 3125 } 3002 3126 EXPORT_IPV6_MOD(udp_lib_setsockopt); 3003 3127 3004 - int udp_setsockopt(struct sock *sk, int level, int optname, sockptr_t optval, 3005 - unsigned int optlen) 3128 + static int udp_setsockopt(struct sock *sk, int level, int optname, sockptr_t optval, 3129 + unsigned int optlen) 3006 3130 { 3007 - if (level == SOL_UDP || level == SOL_UDPLITE || level == SOL_SOCKET) 3131 + if (level == SOL_UDP || level == SOL_SOCKET) 3008 3132 return udp_lib_setsockopt(sk, level, optname, 3009 3133 optval, optlen, 3010 3134 udp_push_pending_frames); ··· 3050 3174 val = udp_test_bit(GRO_ENABLED, sk); 3051 3175 break; 3052 3176 3053 - /* The following two cannot be changed on UDP sockets, the return is 3054 - * always 0 (which corresponds to the full checksum coverage of UDP). */ 3055 - case UDPLITE_SEND_CSCOV: 3056 - val = READ_ONCE(up->pcslen); 3057 - break; 3058 - 3059 - case UDPLITE_RECV_CSCOV: 3060 - val = READ_ONCE(up->pcrlen); 3061 - break; 3062 - 3063 3177 default: 3064 3178 return -ENOPROTOOPT; 3065 3179 } ··· 3062 3196 } 3063 3197 EXPORT_IPV6_MOD(udp_lib_getsockopt); 3064 3198 3065 - int udp_getsockopt(struct sock *sk, int level, int optname, 3066 - char __user *optval, int __user *optlen) 3199 + static int udp_getsockopt(struct sock *sk, int level, int optname, 3200 + char __user *optval, int __user *optlen) 3067 3201 { 3068 - if (level == SOL_UDP || level == SOL_UDPLITE) 3202 + if (level == SOL_UDP) 3069 3203 return udp_lib_getsockopt(sk, level, optname, optval, optlen); 3070 3204 return ip_getsockopt(sk, level, optname, optval, optlen); 3071 3205 } ··· 3158 3292 .sysctl_wmem_offset = offsetof(struct net, ipv4.sysctl_udp_wmem_min), 3159 3293 .sysctl_rmem_offset = offsetof(struct net, ipv4.sysctl_udp_rmem_min), 3160 3294 .obj_size = sizeof(struct udp_sock), 3161 - .h.udp_table = NULL, 3162 3295 .diag_destroy = udp_abort, 3163 3296 }; 3164 3297 EXPORT_SYMBOL(udp_prot); ··· 3178 3313 #ifdef CONFIG_BPF_SYSCALL 3179 3314 static const struct seq_operations bpf_iter_udp_seq_ops; 3180 3315 #endif 3181 - static struct udp_table *udp_get_table_seq(struct seq_file *seq, 3182 - struct net *net) 3183 - { 3184 - const struct udp_seq_afinfo *afinfo; 3185 - 3186 - #ifdef CONFIG_BPF_SYSCALL 3187 - if (seq->op == &bpf_iter_udp_seq_ops) 3188 - return net->ipv4.udp_table; 3189 - #endif 3190 - 3191 - afinfo = pde_data(file_inode(seq->file)); 3192 - return afinfo->udp_table ? : net->ipv4.udp_table; 3193 - } 3194 3316 3195 3317 static struct sock *udp_get_first(struct seq_file *seq, int start) 3196 3318 { ··· 3186 3334 struct udp_table *udptable; 3187 3335 struct sock *sk; 3188 3336 3189 - udptable = udp_get_table_seq(seq, net); 3337 + udptable = net->ipv4.udp_table; 3190 3338 3191 3339 for (state->bucket = start; state->bucket <= udptable->mask; 3192 3340 ++state->bucket) { ··· 3218 3366 } while (sk && !seq_sk_match(seq, sk)); 3219 3367 3220 3368 if (!sk) { 3221 - udptable = udp_get_table_seq(seq, net); 3369 + udptable = net->ipv4.udp_table; 3222 3370 3223 3371 if (state->bucket <= udptable->mask) 3224 3372 spin_unlock_bh(&udptable->hash[state->bucket].lock); ··· 3266 3414 struct udp_iter_state *state = seq->private; 3267 3415 struct udp_table *udptable; 3268 3416 3269 - udptable = udp_get_table_seq(seq, seq_file_net(seq)); 3417 + udptable = seq_file_net(seq)->ipv4.udp_table; 3270 3418 3271 3419 if (state->bucket <= udptable->mask) 3272 3420 spin_unlock_bh(&udptable->hash[state->bucket].lock); ··· 3295 3443 sk_drops_read(sp)); 3296 3444 } 3297 3445 3298 - int udp4_seq_show(struct seq_file *seq, void *v) 3446 + static int udp4_seq_show(struct seq_file *seq, void *v) 3299 3447 { 3300 3448 seq_setwidth(seq, 127); 3301 3449 if (v == SEQ_START_TOKEN) ··· 3370 3518 if (iter->cur_sk == iter->end_sk) 3371 3519 state->bucket++; 3372 3520 3373 - udptable = udp_get_table_seq(seq, net); 3521 + udptable = net->ipv4.udp_table; 3374 3522 3375 3523 again: 3376 3524 /* New batch for the next bucket. ··· 3599 3747 return afinfo->family; 3600 3748 } 3601 3749 3602 - const struct seq_operations udp_seq_ops = { 3750 + static const struct seq_operations udp_seq_ops = { 3603 3751 .start = udp_seq_start, 3604 3752 .next = udp_seq_next, 3605 3753 .stop = udp_seq_stop, 3606 3754 .show = udp4_seq_show, 3607 3755 }; 3608 - EXPORT_IPV6_MOD(udp_seq_ops); 3609 3756 3610 3757 static struct udp_seq_afinfo udp4_seq_afinfo = { 3611 3758 .family = AF_INET, 3612 - .udp_table = NULL, 3613 3759 }; 3614 3760 3615 3761 static int __net_init udp4_proc_init_net(struct net *net) ··· 3657 3807 } 3658 3808 __setup("uhash_entries=", set_uhash_entries); 3659 3809 3660 - void __init udp_table_init(struct udp_table *table, const char *name) 3810 + static void __init udp_table_init(struct udp_table *table, const char *name) 3661 3811 { 3662 3812 unsigned int i, slot_size; 3663 3813
-2
net/ipv4/udp_bpf.c
··· 7 7 #include <net/inet_common.h> 8 8 #include <asm/ioctls.h> 9 9 10 - #include "udp_impl.h" 11 - 12 10 static struct proto *udpv6_prot_saved __read_mostly; 13 11 14 12 static int sk_udp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
+32 -96
net/ipv4/udp_diag.c
··· 10 10 #include <linux/inet_diag.h> 11 11 #include <linux/udp.h> 12 12 #include <net/udp.h> 13 - #include <net/udplite.h> 14 13 #include <linux/sock_diag.h> 15 14 16 15 static int sk_diag_dump(struct sock *sk, struct sk_buff *skb, ··· 24 25 net_admin); 25 26 } 26 27 27 - static int udp_dump_one(struct udp_table *tbl, 28 - struct netlink_callback *cb, 29 - const struct inet_diag_req_v2 *req) 28 + static int udp_diag_dump_one(struct netlink_callback *cb, 29 + const struct inet_diag_req_v2 *req) 30 30 { 31 31 struct sk_buff *in_skb = cb->skb; 32 - int err; 33 32 struct sock *sk = NULL; 34 33 struct sk_buff *rep; 35 - struct net *net = sock_net(in_skb->sk); 34 + struct net *net; 35 + int err; 36 + 37 + net = sock_net(in_skb->sk); 36 38 37 39 rcu_read_lock(); 38 40 if (req->sdiag_family == AF_INET) 39 41 /* src and dst are swapped for historical reasons */ 40 42 sk = __udp4_lib_lookup(net, 41 - req->id.idiag_src[0], req->id.idiag_sport, 42 - req->id.idiag_dst[0], req->id.idiag_dport, 43 - req->id.idiag_if, 0, tbl, NULL); 43 + req->id.idiag_src[0], req->id.idiag_sport, 44 + req->id.idiag_dst[0], req->id.idiag_dport, 45 + req->id.idiag_if, 0, NULL); 44 46 #if IS_ENABLED(CONFIG_IPV6) 45 47 else if (req->sdiag_family == AF_INET6) 46 48 sk = __udp6_lib_lookup(net, 47 - (struct in6_addr *)req->id.idiag_src, 48 - req->id.idiag_sport, 49 - (struct in6_addr *)req->id.idiag_dst, 50 - req->id.idiag_dport, 51 - req->id.idiag_if, 0, tbl, NULL); 49 + (struct in6_addr *)req->id.idiag_src, 50 + req->id.idiag_sport, 51 + (struct in6_addr *)req->id.idiag_dst, 52 + req->id.idiag_dport, 53 + req->id.idiag_if, 0, NULL); 52 54 #endif 53 55 if (sk && !refcount_inc_not_zero(&sk->sk_refcnt)) 54 56 sk = NULL; ··· 86 86 return err; 87 87 } 88 88 89 - static void udp_dump(struct udp_table *table, struct sk_buff *skb, 90 - struct netlink_callback *cb, 91 - const struct inet_diag_req_v2 *r) 89 + static void udp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb, 90 + const struct inet_diag_req_v2 *r) 92 91 { 93 92 bool net_admin = netlink_net_capable(cb->skb, CAP_NET_ADMIN); 94 93 struct net *net = sock_net(skb->sk); 95 94 int num, s_num, slot, s_slot; 95 + struct udp_table *table; 96 96 97 + table = net->ipv4.udp_table; 97 98 s_slot = cb->args[0]; 98 99 num = s_num = cb->args[1]; 99 100 ··· 141 140 cb->args[1] = num; 142 141 } 143 142 144 - static void udp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb, 145 - const struct inet_diag_req_v2 *r) 146 - { 147 - udp_dump(sock_net(cb->skb->sk)->ipv4.udp_table, skb, cb, r); 148 - } 149 - 150 - static int udp_diag_dump_one(struct netlink_callback *cb, 151 - const struct inet_diag_req_v2 *req) 152 - { 153 - return udp_dump_one(sock_net(cb->skb->sk)->ipv4.udp_table, cb, req); 154 - } 155 - 156 143 static void udp_diag_get_info(struct sock *sk, struct inet_diag_msg *r, 157 144 void *info) 158 145 { ··· 149 160 } 150 161 151 162 #ifdef CONFIG_INET_DIAG_DESTROY 152 - static int __udp_diag_destroy(struct sk_buff *in_skb, 153 - const struct inet_diag_req_v2 *req, 154 - struct udp_table *tbl) 163 + static int udp_diag_destroy(struct sk_buff *in_skb, 164 + const struct inet_diag_req_v2 *req) 155 165 { 156 166 struct net *net = sock_net(in_skb->sk); 157 167 struct sock *sk; ··· 160 172 161 173 if (req->sdiag_family == AF_INET) 162 174 sk = __udp4_lib_lookup(net, 163 - req->id.idiag_dst[0], req->id.idiag_dport, 164 - req->id.idiag_src[0], req->id.idiag_sport, 165 - req->id.idiag_if, 0, tbl, NULL); 175 + req->id.idiag_dst[0], req->id.idiag_dport, 176 + req->id.idiag_src[0], req->id.idiag_sport, 177 + req->id.idiag_if, 0, NULL); 166 178 #if IS_ENABLED(CONFIG_IPV6) 167 179 else if (req->sdiag_family == AF_INET6) { 168 180 if (ipv6_addr_v4mapped((struct in6_addr *)req->id.idiag_dst) && 169 181 ipv6_addr_v4mapped((struct in6_addr *)req->id.idiag_src)) 170 182 sk = __udp4_lib_lookup(net, 171 - req->id.idiag_dst[3], req->id.idiag_dport, 172 - req->id.idiag_src[3], req->id.idiag_sport, 173 - req->id.idiag_if, 0, tbl, NULL); 174 - 183 + req->id.idiag_dst[3], req->id.idiag_dport, 184 + req->id.idiag_src[3], req->id.idiag_sport, 185 + req->id.idiag_if, 0, NULL); 175 186 else 176 187 sk = __udp6_lib_lookup(net, 177 - (struct in6_addr *)req->id.idiag_dst, 178 - req->id.idiag_dport, 179 - (struct in6_addr *)req->id.idiag_src, 180 - req->id.idiag_sport, 181 - req->id.idiag_if, 0, tbl, NULL); 188 + (struct in6_addr *)req->id.idiag_dst, 189 + req->id.idiag_dport, 190 + (struct in6_addr *)req->id.idiag_src, 191 + req->id.idiag_sport, 192 + req->id.idiag_if, 0, NULL); 182 193 } 183 194 #endif 184 195 else { ··· 204 217 205 218 return err; 206 219 } 207 - 208 - static int udp_diag_destroy(struct sk_buff *in_skb, 209 - const struct inet_diag_req_v2 *req) 210 - { 211 - return __udp_diag_destroy(in_skb, req, sock_net(in_skb->sk)->ipv4.udp_table); 212 - } 213 - 214 - static int udplite_diag_destroy(struct sk_buff *in_skb, 215 - const struct inet_diag_req_v2 *req) 216 - { 217 - return __udp_diag_destroy(in_skb, req, &udplite_table); 218 - } 219 - 220 220 #endif 221 221 222 222 static const struct inet_diag_handler udp_diag_handler = { ··· 218 244 #endif 219 245 }; 220 246 221 - static void udplite_diag_dump(struct sk_buff *skb, struct netlink_callback *cb, 222 - const struct inet_diag_req_v2 *r) 223 - { 224 - udp_dump(&udplite_table, skb, cb, r); 225 - } 226 - 227 - static int udplite_diag_dump_one(struct netlink_callback *cb, 228 - const struct inet_diag_req_v2 *req) 229 - { 230 - return udp_dump_one(&udplite_table, cb, req); 231 - } 232 - 233 - static const struct inet_diag_handler udplite_diag_handler = { 234 - .owner = THIS_MODULE, 235 - .dump = udplite_diag_dump, 236 - .dump_one = udplite_diag_dump_one, 237 - .idiag_get_info = udp_diag_get_info, 238 - .idiag_type = IPPROTO_UDPLITE, 239 - .idiag_info_size = 0, 240 - #ifdef CONFIG_INET_DIAG_DESTROY 241 - .destroy = udplite_diag_destroy, 242 - #endif 243 - }; 244 - 245 247 static int __init udp_diag_init(void) 246 248 { 247 - int err; 248 - 249 - err = inet_diag_register(&udp_diag_handler); 250 - if (err) 251 - goto out; 252 - err = inet_diag_register(&udplite_diag_handler); 253 - if (err) 254 - goto out_lite; 255 - out: 256 - return err; 257 - out_lite: 258 - inet_diag_unregister(&udp_diag_handler); 259 - goto out; 249 + return inet_diag_register(&udp_diag_handler); 260 250 } 261 251 262 252 static void __exit udp_diag_exit(void) 263 253 { 264 - inet_diag_unregister(&udplite_diag_handler); 265 254 inet_diag_unregister(&udp_diag_handler); 266 255 } 267 256 ··· 233 296 MODULE_LICENSE("GPL"); 234 297 MODULE_DESCRIPTION("UDP socket monitoring via SOCK_DIAG"); 235 298 MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 2-17 /* AF_INET - IPPROTO_UDP */); 236 - MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 2-136 /* AF_INET - IPPROTO_UDPLITE */);
-27
net/ipv4/udp_impl.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef _UDP4_IMPL_H 3 - #define _UDP4_IMPL_H 4 - #include <net/aligned_data.h> 5 - #include <net/udp.h> 6 - #include <net/udplite.h> 7 - #include <net/protocol.h> 8 - #include <net/inet_common.h> 9 - 10 - int __udp4_lib_rcv(struct sk_buff *, struct udp_table *, int); 11 - int __udp4_lib_err(struct sk_buff *, u32, struct udp_table *); 12 - 13 - int udp_v4_get_port(struct sock *sk, unsigned short snum); 14 - void udp_v4_rehash(struct sock *sk); 15 - 16 - int udp_setsockopt(struct sock *sk, int level, int optname, sockptr_t optval, 17 - unsigned int optlen); 18 - int udp_getsockopt(struct sock *sk, int level, int optname, 19 - char __user *optval, int __user *optlen); 20 - 21 - int udp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int flags); 22 - void udp_destroy_sock(struct sock *sk); 23 - 24 - #ifdef CONFIG_PROC_FS 25 - int udp4_seq_show(struct seq_file *seq, void *v); 26 - #endif 27 - #endif /* _UDP4_IMPL_H */
+1 -2
net/ipv4/udp_offload.c
··· 869 869 inet_get_iif_sdif(skb, &iif, &sdif); 870 870 871 871 return __udp4_lib_lookup(net, iph->saddr, sport, 872 - iph->daddr, dport, iif, 873 - sdif, net->ipv4.udp_table, NULL); 872 + iph->daddr, dport, iif, sdif, NULL); 874 873 } 875 874 876 875 INDIRECT_CALLABLE_SCOPE
-135
net/ipv4/udplite.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * UDPLITE An implementation of the UDP-Lite protocol (RFC 3828). 4 - * 5 - * Authors: Gerrit Renker <gerrit@erg.abdn.ac.uk> 6 - * 7 - * Changes: 8 - * Fixes: 9 - */ 10 - 11 - #define pr_fmt(fmt) "UDPLite: " fmt 12 - 13 - #include <linux/export.h> 14 - #include <linux/proc_fs.h> 15 - #include "udp_impl.h" 16 - 17 - struct udp_table udplite_table __read_mostly; 18 - EXPORT_SYMBOL(udplite_table); 19 - 20 - /* Designate sk as UDP-Lite socket */ 21 - static int udplite_sk_init(struct sock *sk) 22 - { 23 - pr_warn_once("UDP-Lite is deprecated and scheduled to be removed in 2025, " 24 - "please contact the netdev mailing list\n"); 25 - return udp_init_sock(sk); 26 - } 27 - 28 - static int udplite_rcv(struct sk_buff *skb) 29 - { 30 - return __udp4_lib_rcv(skb, &udplite_table, IPPROTO_UDPLITE); 31 - } 32 - 33 - static int udplite_err(struct sk_buff *skb, u32 info) 34 - { 35 - return __udp4_lib_err(skb, info, &udplite_table); 36 - } 37 - 38 - static const struct net_protocol udplite_protocol = { 39 - .handler = udplite_rcv, 40 - .err_handler = udplite_err, 41 - .no_policy = 1, 42 - }; 43 - 44 - struct proto udplite_prot = { 45 - .name = "UDP-Lite", 46 - .owner = THIS_MODULE, 47 - .close = udp_lib_close, 48 - .connect = ip4_datagram_connect, 49 - .disconnect = udp_disconnect, 50 - .ioctl = udp_ioctl, 51 - .init = udplite_sk_init, 52 - .destroy = udp_destroy_sock, 53 - .setsockopt = udp_setsockopt, 54 - .getsockopt = udp_getsockopt, 55 - .sendmsg = udp_sendmsg, 56 - .recvmsg = udp_recvmsg, 57 - .hash = udp_lib_hash, 58 - .unhash = udp_lib_unhash, 59 - .rehash = udp_v4_rehash, 60 - .get_port = udp_v4_get_port, 61 - 62 - .memory_allocated = &net_aligned_data.udp_memory_allocated, 63 - .per_cpu_fw_alloc = &udp_memory_per_cpu_fw_alloc, 64 - 65 - .sysctl_mem = sysctl_udp_mem, 66 - .sysctl_wmem_offset = offsetof(struct net, ipv4.sysctl_udp_wmem_min), 67 - .sysctl_rmem_offset = offsetof(struct net, ipv4.sysctl_udp_rmem_min), 68 - .obj_size = sizeof(struct udp_sock), 69 - .h.udp_table = &udplite_table, 70 - }; 71 - EXPORT_SYMBOL(udplite_prot); 72 - 73 - static struct inet_protosw udplite4_protosw = { 74 - .type = SOCK_DGRAM, 75 - .protocol = IPPROTO_UDPLITE, 76 - .prot = &udplite_prot, 77 - .ops = &inet_dgram_ops, 78 - .flags = INET_PROTOSW_PERMANENT, 79 - }; 80 - 81 - #ifdef CONFIG_PROC_FS 82 - static struct udp_seq_afinfo udplite4_seq_afinfo = { 83 - .family = AF_INET, 84 - .udp_table = &udplite_table, 85 - }; 86 - 87 - static int __net_init udplite4_proc_init_net(struct net *net) 88 - { 89 - if (!proc_create_net_data("udplite", 0444, net->proc_net, &udp_seq_ops, 90 - sizeof(struct udp_iter_state), &udplite4_seq_afinfo)) 91 - return -ENOMEM; 92 - return 0; 93 - } 94 - 95 - static void __net_exit udplite4_proc_exit_net(struct net *net) 96 - { 97 - remove_proc_entry("udplite", net->proc_net); 98 - } 99 - 100 - static struct pernet_operations udplite4_net_ops = { 101 - .init = udplite4_proc_init_net, 102 - .exit = udplite4_proc_exit_net, 103 - }; 104 - 105 - static __init int udplite4_proc_init(void) 106 - { 107 - return register_pernet_subsys(&udplite4_net_ops); 108 - } 109 - #else 110 - static inline int udplite4_proc_init(void) 111 - { 112 - return 0; 113 - } 114 - #endif 115 - 116 - void __init udplite4_register(void) 117 - { 118 - udp_table_init(&udplite_table, "UDP-Lite"); 119 - if (proto_register(&udplite_prot, 1)) 120 - goto out_register_err; 121 - 122 - if (inet_add_protocol(&udplite_protocol, IPPROTO_UDPLITE) < 0) 123 - goto out_unregister_proto; 124 - 125 - inet_register_protosw(&udplite4_protosw); 126 - 127 - if (udplite4_proc_init()) 128 - pr_err("%s: Cannot register /proc!\n", __func__); 129 - return; 130 - 131 - out_unregister_proto: 132 - proto_unregister(&udplite_prot); 133 - out_register_err: 134 - pr_crit("%s: Cannot add UDP-Lite protocol\n", __func__); 135 - }
+1 -1
net/ipv6/Makefile
··· 7 7 8 8 ipv6-y := af_inet6.o anycast.o ip6_output.o ip6_input.o addrconf.o \ 9 9 addrlabel.o \ 10 - route.o ip6_fib.o ipv6_sockglue.o ndisc.o udp.o udplite.o \ 10 + route.o ip6_fib.o ipv6_sockglue.o ndisc.o udp.o \ 11 11 raw.o icmp.o mcast.o reassembly.o tcp_ipv6.o ping.o \ 12 12 exthdrs.o datagram.o ip6_flowlabel.o inet6_connection_sock.o \ 13 13 udp_offload.o seg6.o fib6_notifier.o rpl.o ioam6.o
+3 -29
net/ipv6/af_inet6.c
··· 43 43 #include <net/ip.h> 44 44 #include <net/ipv6.h> 45 45 #include <net/udp.h> 46 - #include <net/udplite.h> 47 46 #include <net/tcp.h> 48 47 #include <net/ping.h> 49 48 #include <net/protocol.h> ··· 635 636 EXPORT_SYMBOL_GPL(inet6_compat_ioctl); 636 637 #endif /* CONFIG_COMPAT */ 637 638 638 - INDIRECT_CALLABLE_DECLARE(int udpv6_sendmsg(struct sock *, struct msghdr *, 639 - size_t)); 640 639 int inet6_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) 641 640 { 642 641 struct sock *sk = sock->sk; ··· 649 652 sk, msg, size); 650 653 } 651 654 652 - INDIRECT_CALLABLE_DECLARE(int udpv6_recvmsg(struct sock *, struct msghdr *, 653 - size_t, int)); 654 655 int inet6_recvmsg(struct socket *sock, struct msghdr *msg, size_t size, 655 656 int flags) 656 657 { ··· 886 891 net->mib.udp_stats_in6 = alloc_percpu(struct udp_mib); 887 892 if (!net->mib.udp_stats_in6) 888 893 return -ENOMEM; 889 - net->mib.udplite_stats_in6 = alloc_percpu(struct udp_mib); 890 - if (!net->mib.udplite_stats_in6) 891 - goto err_udplite_mib; 894 + 892 895 net->mib.ipv6_statistics = alloc_percpu(struct ipstats_mib); 893 896 if (!net->mib.ipv6_statistics) 894 897 goto err_ip_mib; ··· 897 904 u64_stats_init(&af_inet6_stats->syncp); 898 905 } 899 906 900 - 901 907 net->mib.icmpv6_statistics = alloc_percpu(struct icmpv6_mib); 902 908 if (!net->mib.icmpv6_statistics) 903 909 goto err_icmp_mib; 910 + 904 911 net->mib.icmpv6msg_statistics = kzalloc_obj(struct icmpv6msg_mib); 905 912 if (!net->mib.icmpv6msg_statistics) 906 913 goto err_icmpmsg_mib; ··· 911 918 err_icmp_mib: 912 919 free_percpu(net->mib.ipv6_statistics); 913 920 err_ip_mib: 914 - free_percpu(net->mib.udplite_stats_in6); 915 - err_udplite_mib: 916 921 free_percpu(net->mib.udp_stats_in6); 917 922 return -ENOMEM; 918 923 } ··· 918 927 static void ipv6_cleanup_mibs(struct net *net) 919 928 { 920 929 free_percpu(net->mib.udp_stats_in6); 921 - free_percpu(net->mib.udplite_stats_in6); 922 930 free_percpu(net->mib.ipv6_statistics); 923 931 free_percpu(net->mib.icmpv6_statistics); 924 932 kfree(net->mib.icmpv6msg_statistics); ··· 1070 1080 if (err) 1071 1081 goto out_unregister_tcp_proto; 1072 1082 1073 - err = proto_register(&udplitev6_prot, 1); 1074 - if (err) 1075 - goto out_unregister_udp_proto; 1076 - 1077 1083 err = proto_register(&rawv6_prot, 1); 1078 1084 if (err) 1079 - goto out_unregister_udplite_proto; 1085 + goto out_unregister_udp_proto; 1080 1086 1081 1087 err = proto_register(&pingv6_prot, 1); 1082 1088 if (err) ··· 1123 1137 err = -ENOMEM; 1124 1138 if (raw6_proc_init()) 1125 1139 goto proc_raw6_fail; 1126 - if (udplite6_proc_init()) 1127 - goto proc_udplite6_fail; 1128 1140 if (ipv6_misc_proc_init()) 1129 1141 goto proc_misc6_fail; 1130 1142 if (if6_proc_init()) ··· 1157 1173 err = udpv6_init(); 1158 1174 if (err) 1159 1175 goto udpv6_fail; 1160 - 1161 - err = udplitev6_init(); 1162 - if (err) 1163 - goto udplitev6_fail; 1164 1176 1165 1177 err = udpv6_offload_init(); 1166 1178 if (err) ··· 1228 1248 tcpv6_fail: 1229 1249 udpv6_offload_exit(); 1230 1250 udpv6_offload_fail: 1231 - udplitev6_exit(); 1232 - udplitev6_fail: 1233 1251 udpv6_exit(); 1234 1252 udpv6_fail: 1235 1253 ipv6_frag_exit(); ··· 1249 1271 proc_if6_fail: 1250 1272 ipv6_misc_proc_exit(); 1251 1273 proc_misc6_fail: 1252 - udplite6_proc_exit(); 1253 - proc_udplite6_fail: 1254 1274 raw6_proc_exit(); 1255 1275 proc_raw6_fail: 1256 1276 #endif ··· 1272 1296 proto_unregister(&pingv6_prot); 1273 1297 out_unregister_raw_proto: 1274 1298 proto_unregister(&rawv6_prot); 1275 - out_unregister_udplite_proto: 1276 - proto_unregister(&udplitev6_prot); 1277 1299 out_unregister_udp_proto: 1278 1300 proto_unregister(&udpv6_prot); 1279 1301 out_unregister_tcp_proto:
+1 -1
net/ipv6/ip6_checksum.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 #include <net/ip.h> 3 + #include <net/ip6_checksum.h> 3 4 #include <net/udp.h> 4 - #include <net/udplite.h> 5 5 #include <asm/checksum.h> 6 6 7 7 #ifndef _HAVE_ARCH_IPV6_CSUM
+4 -13
net/ipv6/ipv6_sockglue.c
··· 45 45 #include <net/inet_common.h> 46 46 #include <net/tcp.h> 47 47 #include <net/udp.h> 48 - #include <net/udplite.h> 49 48 #include <net/xfrm.h> 50 49 #include <net/compat.h> 51 50 #include <net/seg6.h> ··· 562 563 if (sk->sk_type == SOCK_RAW) 563 564 break; 564 565 565 - if (sk->sk_protocol == IPPROTO_UDP || 566 - sk->sk_protocol == IPPROTO_UDPLITE) { 567 - struct udp_sock *up = udp_sk(sk); 568 - if (up->pending == AF_INET6) { 566 + if (sk->sk_protocol == IPPROTO_UDP) { 567 + if (udp_sk(sk)->pending == AF_INET6) { 569 568 retv = -EBUSY; 570 569 break; 571 570 } ··· 604 607 WRITE_ONCE(sk->sk_family, PF_INET); 605 608 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie); 606 609 } else { 607 - struct proto *prot = &udp_prot; 608 - 609 - if (sk->sk_protocol == IPPROTO_UDPLITE) 610 - prot = &udplite_prot; 611 - 612 610 sock_prot_inuse_add(net, sk->sk_prot, -1); 613 - sock_prot_inuse_add(net, prot, 1); 611 + sock_prot_inuse_add(net, &udp_prot, 1); 614 612 615 613 /* Paired with READ_ONCE(sk->sk_prot) in inet6_dgram_ops */ 616 - WRITE_ONCE(sk->sk_prot, prot); 614 + WRITE_ONCE(sk->sk_prot, &udp_prot); 617 615 WRITE_ONCE(sk->sk_socket->ops, &inet_dgram_ops); 618 616 WRITE_ONCE(sk->sk_family, PF_INET); 619 617 } ··· 1090 1098 switch (optname) { 1091 1099 case IPV6_ADDRFORM: 1092 1100 if (sk->sk_protocol != IPPROTO_UDP && 1093 - sk->sk_protocol != IPPROTO_UDPLITE && 1094 1101 sk->sk_protocol != IPPROTO_TCP) 1095 1102 return -ENOPROTOOPT; 1096 1103 if (sk->sk_state != TCP_ESTABLISHED)
-16
net/ipv6/proc.c
··· 39 39 sock_prot_inuse_get(net, &tcpv6_prot)); 40 40 seq_printf(seq, "UDP6: inuse %d\n", 41 41 sock_prot_inuse_get(net, &udpv6_prot)); 42 - seq_printf(seq, "UDPLITE6: inuse %d\n", 43 - sock_prot_inuse_get(net, &udplitev6_prot)); 44 42 seq_printf(seq, "RAW6: inuse %d\n", 45 43 sock_prot_inuse_get(net, &rawv6_prot)); 46 44 seq_printf(seq, "FRAG6: inuse %u memory %lu\n", ··· 106 108 SNMP_MIB_ITEM("Udp6InCsumErrors", UDP_MIB_CSUMERRORS), 107 109 SNMP_MIB_ITEM("Udp6IgnoredMulti", UDP_MIB_IGNOREDMULTI), 108 110 SNMP_MIB_ITEM("Udp6MemErrors", UDP_MIB_MEMERRORS), 109 - }; 110 - 111 - static const struct snmp_mib snmp6_udplite6_list[] = { 112 - SNMP_MIB_ITEM("UdpLite6InDatagrams", UDP_MIB_INDATAGRAMS), 113 - SNMP_MIB_ITEM("UdpLite6NoPorts", UDP_MIB_NOPORTS), 114 - SNMP_MIB_ITEM("UdpLite6InErrors", UDP_MIB_INERRORS), 115 - SNMP_MIB_ITEM("UdpLite6OutDatagrams", UDP_MIB_OUTDATAGRAMS), 116 - SNMP_MIB_ITEM("UdpLite6RcvbufErrors", UDP_MIB_RCVBUFERRORS), 117 - SNMP_MIB_ITEM("UdpLite6SndbufErrors", UDP_MIB_SNDBUFERRORS), 118 - SNMP_MIB_ITEM("UdpLite6InCsumErrors", UDP_MIB_CSUMERRORS), 119 - SNMP_MIB_ITEM("UdpLite6MemErrors", UDP_MIB_MEMERRORS), 120 111 }; 121 112 122 113 static void snmp6_seq_show_icmpv6msg(struct seq_file *seq, atomic_long_t *smib) ··· 215 228 snmp6_seq_show_item(seq, net->mib.udp_stats_in6, 216 229 NULL, snmp6_udp6_list, 217 230 ARRAY_SIZE(snmp6_udp6_list)); 218 - snmp6_seq_show_item(seq, net->mib.udplite_stats_in6, 219 - NULL, snmp6_udplite6_list, 220 - ARRAY_SIZE(snmp6_udplite6_list)); 221 231 return 0; 222 232 } 223 233
+116 -190
net/ipv6/udp.c
··· 37 37 #include <trace/events/udp.h> 38 38 39 39 #include <net/addrconf.h> 40 + #include <net/aligned_data.h> 40 41 #include <net/ndisc.h> 41 42 #include <net/protocol.h> 42 43 #include <net/transp_v6.h> ··· 58 57 #include <linux/proc_fs.h> 59 58 #include <linux/seq_file.h> 60 59 #include <trace/events/skb.h> 61 - #include "udp_impl.h" 62 60 63 61 static void udpv6_destruct_sock(struct sock *sk) 64 62 { ··· 65 65 inet6_sock_destruct(sk); 66 66 } 67 67 68 - int udpv6_init_sock(struct sock *sk) 68 + static int udpv6_init_sock(struct sock *sk) 69 69 { 70 70 int res = udp_lib_init_sock(sk); 71 71 ··· 95 95 udp6_ehash_secret + net_hash_mix(net)); 96 96 } 97 97 98 - int udp_v6_get_port(struct sock *sk, unsigned short snum) 98 + static int udp_v6_get_port(struct sock *sk, unsigned short snum) 99 99 { 100 100 unsigned int hash2_nulladdr = 101 101 ipv6_portaddr_hash(sock_net(sk), &in6addr_any, snum); ··· 107 107 return udp_lib_get_port(sk, snum, hash2_nulladdr); 108 108 } 109 109 110 - void udp_v6_rehash(struct sock *sk) 110 + static void udp_v6_rehash(struct sock *sk) 111 111 { 112 112 u16 new_hash = ipv6_portaddr_hash(sock_net(sk), 113 113 &sk->sk_v6_rcv_saddr, ··· 344 344 struct sock *__udp6_lib_lookup(const struct net *net, 345 345 const struct in6_addr *saddr, __be16 sport, 346 346 const struct in6_addr *daddr, __be16 dport, 347 - int dif, int sdif, struct udp_table *udptable, 348 - struct sk_buff *skb) 347 + int dif, int sdif, struct sk_buff *skb) 349 348 { 349 + struct udp_table *udptable = net->ipv4.udp_table; 350 350 unsigned short hnum = ntohs(dport); 351 351 struct udp_hslot *hslot2; 352 352 struct sock *result, *sk; ··· 370 370 goto done; 371 371 372 372 /* Lookup redirect from BPF */ 373 - if (static_branch_unlikely(&bpf_sk_lookup_enabled) && 374 - udptable == net->ipv4.udp_table) { 373 + if (static_branch_unlikely(&bpf_sk_lookup_enabled)) { 375 374 sk = inet6_lookup_run_sk_lookup(net, IPPROTO_UDP, skb, sizeof(struct udphdr), 376 375 saddr, sport, daddr, hnum, dif, 377 376 udp6_ehashfn); ··· 406 407 EXPORT_SYMBOL_GPL(__udp6_lib_lookup); 407 408 408 409 static struct sock *__udp6_lib_lookup_skb(struct sk_buff *skb, 409 - __be16 sport, __be16 dport, 410 - struct udp_table *udptable) 410 + __be16 sport, __be16 dport) 411 411 { 412 412 const struct ipv6hdr *iph = ipv6_hdr(skb); 413 413 414 414 return __udp6_lib_lookup(dev_net(skb->dev), &iph->saddr, sport, 415 415 &iph->daddr, dport, inet6_iif(skb), 416 - inet6_sdif(skb), udptable, skb); 416 + inet6_sdif(skb), skb); 417 417 } 418 418 419 419 struct sock *udp6_lib_lookup_skb(const struct sk_buff *skb, ··· 420 422 { 421 423 const u16 offset = NAPI_GRO_CB(skb)->network_offsets[skb->encapsulation]; 422 424 const struct ipv6hdr *iph = (struct ipv6hdr *)(skb->data + offset); 423 - struct net *net = dev_net(skb->dev); 424 425 int iif, sdif; 425 426 426 427 inet6_get_iif_sdif(skb, &iif, &sdif); 427 428 428 - return __udp6_lib_lookup(net, &iph->saddr, sport, 429 - &iph->daddr, dport, iif, 430 - sdif, net->ipv4.udp_table, NULL); 429 + return __udp6_lib_lookup(dev_net(skb->dev), &iph->saddr, sport, 430 + &iph->daddr, dport, iif, sdif, NULL); 431 431 } 432 432 433 433 /* Must be called under rcu_read_lock(). ··· 437 441 { 438 442 struct sock *sk; 439 443 440 - sk = __udp6_lib_lookup(net, saddr, sport, daddr, dport, 441 - dif, 0, net->ipv4.udp_table, NULL); 444 + sk = __udp6_lib_lookup(net, saddr, sport, daddr, dport, dif, 0, NULL); 442 445 if (sk && !refcount_inc_not_zero(&sk->sk_refcnt)) 443 446 sk = NULL; 444 447 return sk; ··· 459 464 * return it, otherwise we block. 460 465 */ 461 466 467 + INDIRECT_CALLABLE_SCOPE 462 468 int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, 463 469 int flags) 464 470 { 471 + int off, is_udp4, err, peeking = flags & MSG_PEEK; 465 472 struct ipv6_pinfo *np = inet6_sk(sk); 466 473 struct inet_sock *inet = inet_sk(sk); 467 - struct sk_buff *skb; 468 - unsigned int ulen, copied; 469 - int off, err, peeking = flags & MSG_PEEK; 470 - int is_udplite = IS_UDPLITE(sk); 471 474 struct udp_mib __percpu *mib; 472 475 bool checksum_valid = false; 473 - int is_udp4; 476 + unsigned int ulen, copied; 477 + struct sk_buff *skb; 474 478 475 479 if (flags & MSG_ERRQUEUE) 476 480 return ipv6_recv_error(sk, msg, len); ··· 493 499 is_udp4 = (skb->protocol == htons(ETH_P_IP)); 494 500 mib = __UDPX_MIB(sk, is_udp4); 495 501 496 - /* 497 - * If checksum is needed at all, try to do it while copying the 498 - * data. If the data is truncated, or if we only want a partial 499 - * coverage checksum (UDP-Lite), do it before the copy. 502 + /* If checksum is needed at all, try to do it while copying the 503 + * data. If the data is truncated, do it before the copy. 500 504 */ 501 - 502 - if (copied < ulen || peeking || 503 - (is_udplite && UDP_SKB_CB(skb)->partial_cov)) { 505 + if (copied < ulen || peeking) { 504 506 checksum_valid = udp_skb_csum_unnecessary(skb) || 505 507 !__udp_lib_checksum_complete(skb); 506 508 if (!checksum_valid) ··· 638 648 static struct sock *__udp6_lib_err_encap(struct net *net, 639 649 const struct ipv6hdr *hdr, int offset, 640 650 struct udphdr *uh, 641 - struct udp_table *udptable, 642 651 struct sock *sk, 643 652 struct sk_buff *skb, 644 653 struct inet6_skb_parm *opt, ··· 668 679 669 680 sk = __udp6_lib_lookup(net, &hdr->daddr, uh->source, 670 681 &hdr->saddr, uh->dest, 671 - inet6_iif(skb), 0, udptable, skb); 682 + inet6_iif(skb), 0, skb); 672 683 if (sk) { 673 684 up = udp_sk(sk); 674 685 ··· 689 700 return sk; 690 701 } 691 702 692 - int __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt, 693 - u8 type, u8 code, int offset, __be32 info, 694 - struct udp_table *udptable) 703 + static int udpv6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, 704 + u8 type, u8 code, int offset, __be32 info) 695 705 { 696 - struct ipv6_pinfo *np; 697 706 const struct ipv6hdr *hdr = (const struct ipv6hdr *)skb->data; 698 - const struct in6_addr *saddr = &hdr->saddr; 699 - const struct in6_addr *daddr = seg6_get_daddr(skb, opt) ? : &hdr->daddr; 700 - struct udphdr *uh = (struct udphdr *)(skb->data+offset); 707 + struct udphdr *uh = (struct udphdr *)(skb->data + offset); 708 + const struct in6_addr *saddr, *daddr; 709 + struct net *net = dev_net(skb->dev); 710 + struct ipv6_pinfo *np; 701 711 bool tunnel = false; 702 712 struct sock *sk; 703 713 int harderr; 704 714 int err; 705 - struct net *net = dev_net(skb->dev); 706 715 716 + daddr = seg6_get_daddr(skb, opt) ? : &hdr->daddr; 717 + saddr = &hdr->saddr; 707 718 sk = __udp6_lib_lookup(net, daddr, uh->dest, saddr, uh->source, 708 - inet6_iif(skb), inet6_sdif(skb), udptable, NULL); 719 + inet6_iif(skb), inet6_sdif(skb), NULL); 709 720 710 721 if (!sk || READ_ONCE(udp_sk(sk)->encap_type)) { 711 722 /* No socket for error: try tunnels before discarding */ 712 723 if (static_branch_unlikely(&udpv6_encap_needed_key)) { 713 - sk = __udp6_lib_err_encap(net, hdr, offset, uh, 714 - udptable, sk, skb, 724 + sk = __udp6_lib_err_encap(net, hdr, offset, uh, sk, skb, 715 725 opt, type, code, info); 716 726 if (!sk) 717 727 return 0; ··· 782 794 783 795 rc = __udp_enqueue_schedule_skb(sk, skb); 784 796 if (rc < 0) { 785 - int is_udplite = IS_UDPLITE(sk); 786 797 enum skb_drop_reason drop_reason; 798 + struct net *net = sock_net(sk); 787 799 788 800 /* Note that an ENOMEM error is charged twice */ 789 801 if (rc == -ENOMEM) { 790 - UDP6_INC_STATS(sock_net(sk), 791 - UDP_MIB_RCVBUFERRORS, is_udplite); 802 + UDP6_INC_STATS(net, UDP_MIB_RCVBUFERRORS); 792 803 drop_reason = SKB_DROP_REASON_SOCKET_RCVBUFF; 793 804 } else { 794 - UDP6_INC_STATS(sock_net(sk), 795 - UDP_MIB_MEMERRORS, is_udplite); 805 + UDP6_INC_STATS(net, UDP_MIB_MEMERRORS); 796 806 drop_reason = SKB_DROP_REASON_PROTO_MEM; 797 807 } 798 - UDP6_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite); 808 + UDP6_INC_STATS(net, UDP_MIB_INERRORS); 799 809 trace_udp_fail_queue_rcv_skb(rc, sk, skb); 800 810 sk_skb_reason_drop(sk, skb, drop_reason); 801 811 return -1; ··· 802 816 return 0; 803 817 } 804 818 805 - static __inline__ int udpv6_err(struct sk_buff *skb, 806 - struct inet6_skb_parm *opt, u8 type, 807 - u8 code, int offset, __be32 info) 808 - { 809 - return __udp6_lib_err(skb, opt, type, code, offset, info, 810 - dev_net(skb->dev)->ipv4.udp_table); 811 - } 812 - 813 819 static int udpv6_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb) 814 820 { 815 821 enum skb_drop_reason drop_reason = SKB_DROP_REASON_NOT_SPECIFIED; 816 822 struct udp_sock *up = udp_sk(sk); 817 - int is_udplite = IS_UDPLITE(sk); 823 + struct net *net = sock_net(sk); 818 824 819 825 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) { 820 826 drop_reason = SKB_DROP_REASON_XFRM_POLICY; ··· 840 862 841 863 ret = encap_rcv(sk, skb); 842 864 if (ret <= 0) { 843 - __UDP6_INC_STATS(sock_net(sk), 844 - UDP_MIB_INDATAGRAMS, 845 - is_udplite); 865 + __UDP6_INC_STATS(net, UDP_MIB_INDATAGRAMS); 846 866 return -ret; 847 867 } 848 868 } 849 869 850 870 /* FALLTHROUGH -- it's a UDP Packet */ 851 - } 852 - 853 - /* 854 - * UDP-Lite specific tests, ignored on UDP sockets (see net/ipv4/udp.c). 855 - */ 856 - if (unlikely(udp_test_bit(UDPLITE_RECV_CC, sk) && 857 - UDP_SKB_CB(skb)->partial_cov)) { 858 - u16 pcrlen = READ_ONCE(up->pcrlen); 859 - 860 - if (pcrlen == 0) { /* full coverage was set */ 861 - net_dbg_ratelimited("UDPLITE6: partial coverage %d while full coverage %d requested\n", 862 - UDP_SKB_CB(skb)->cscov, skb->len); 863 - goto drop; 864 - } 865 - if (UDP_SKB_CB(skb)->cscov < pcrlen) { 866 - net_dbg_ratelimited("UDPLITE6: coverage %d too small, need min %d\n", 867 - UDP_SKB_CB(skb)->cscov, pcrlen); 868 - goto drop; 869 - } 870 871 } 871 872 872 873 prefetch(&sk->sk_rmem_alloc); ··· 864 907 865 908 csum_error: 866 909 drop_reason = SKB_DROP_REASON_UDP_CSUM; 867 - __UDP6_INC_STATS(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite); 910 + __UDP6_INC_STATS(net, UDP_MIB_CSUMERRORS); 868 911 drop: 869 - __UDP6_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite); 912 + __UDP6_INC_STATS(net, UDP_MIB_INERRORS); 870 913 udp_drops_inc(sk); 871 914 sk_skb_reason_drop(sk, skb, drop_reason); 872 915 return -1; ··· 933 976 * so we don't need to lock the hashes. 934 977 */ 935 978 static int __udp6_lib_mcast_deliver(struct net *net, struct sk_buff *skb, 936 - const struct in6_addr *saddr, const struct in6_addr *daddr, 937 - struct udp_table *udptable, int proto) 979 + const struct in6_addr *saddr, 980 + const struct in6_addr *daddr) 938 981 { 939 - struct sock *sk, *first = NULL; 982 + struct udp_table *udptable = net->ipv4.udp_table; 940 983 const struct udphdr *uh = udp_hdr(skb); 984 + unsigned int hash2, hash2_any, offset; 941 985 unsigned short hnum = ntohs(uh->dest); 942 - struct udp_hslot *hslot = udp_hashslot(udptable, net, hnum); 943 - unsigned int offset = offsetof(typeof(*sk), sk_node); 944 - unsigned int hash2 = 0, hash2_any = 0, use_hash2 = (hslot->count > 10); 945 - int dif = inet6_iif(skb); 986 + struct sock *sk, *first = NULL; 946 987 int sdif = inet6_sdif(skb); 988 + int dif = inet6_iif(skb); 947 989 struct hlist_node *node; 990 + struct udp_hslot *hslot; 948 991 struct sk_buff *nskb; 992 + bool use_hash2; 993 + 994 + hash2_any = 0; 995 + hash2 = 0; 996 + hslot = udp_hashslot(udptable, net, hnum); 997 + use_hash2 = hslot->count > 10; 998 + offset = offsetof(typeof(*sk), sk_node); 949 999 950 1000 if (use_hash2) { 951 1001 hash2_any = ipv6_portaddr_hash(net, &in6addr_any, hnum) & ··· 980 1016 nskb = skb_clone(skb, GFP_ATOMIC); 981 1017 if (unlikely(!nskb)) { 982 1018 udp_drops_inc(sk); 983 - __UDP6_INC_STATS(net, UDP_MIB_RCVBUFERRORS, 984 - IS_UDPLITE(sk)); 985 - __UDP6_INC_STATS(net, UDP_MIB_INERRORS, 986 - IS_UDPLITE(sk)); 1019 + __UDP6_INC_STATS(net, UDP_MIB_RCVBUFERRORS); 1020 + __UDP6_INC_STATS(net, UDP_MIB_INERRORS); 987 1021 continue; 988 1022 } 989 1023 ··· 1000 1038 consume_skb(skb); 1001 1039 } else { 1002 1040 kfree_skb(skb); 1003 - __UDP6_INC_STATS(net, UDP_MIB_IGNOREDMULTI, 1004 - proto == IPPROTO_UDPLITE); 1041 + __UDP6_INC_STATS(net, UDP_MIB_IGNOREDMULTI); 1005 1042 } 1006 1043 return 0; 1007 1044 } ··· 1019 1058 { 1020 1059 int ret; 1021 1060 1022 - if (inet_get_convert_csum(sk) && uh->check && !IS_UDPLITE(sk)) 1061 + if (inet_get_convert_csum(sk) && uh->check) 1023 1062 skb_checksum_try_convert(skb, IPPROTO_UDP, ip6_compute_pseudo); 1024 1063 1025 1064 ret = udpv6_queue_rcv_skb(sk, skb); ··· 1030 1069 return 0; 1031 1070 } 1032 1071 1033 - static int udp6_csum_init(struct sk_buff *skb, struct udphdr *uh, int proto) 1072 + static int udp6_csum_init(struct sk_buff *skb, struct udphdr *uh) 1034 1073 { 1035 1074 int err; 1036 - 1037 - UDP_SKB_CB(skb)->partial_cov = 0; 1038 - UDP_SKB_CB(skb)->cscov = skb->len; 1039 - 1040 - if (proto == IPPROTO_UDPLITE) { 1041 - err = udplite_checksum_init(skb, uh); 1042 - if (err) 1043 - return err; 1044 - 1045 - if (UDP_SKB_CB(skb)->partial_cov) { 1046 - skb->csum = ip6_compute_pseudo(skb, proto); 1047 - return 0; 1048 - } 1049 - } 1050 1075 1051 1076 /* To support RFC 6936 (allow zero checksum in UDP/IPV6 for tunnels) 1052 1077 * we accept a checksum of zero here. When we find the socket ··· 1042 1095 * Note, we are only interested in != 0 or == 0, thus the 1043 1096 * force to int. 1044 1097 */ 1045 - err = (__force int)skb_checksum_init_zero_check(skb, proto, uh->check, 1098 + err = (__force int)skb_checksum_init_zero_check(skb, IPPROTO_UDP, uh->check, 1046 1099 ip6_compute_pseudo); 1047 1100 if (err) 1048 1101 return err; ··· 1062 1115 return 0; 1063 1116 } 1064 1117 1065 - int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable, 1066 - int proto) 1118 + INDIRECT_CALLABLE_SCOPE int udpv6_rcv(struct sk_buff *skb) 1067 1119 { 1068 1120 enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED; 1069 1121 const struct in6_addr *saddr, *daddr; ··· 1083 1137 if (ulen > skb->len) 1084 1138 goto short_packet; 1085 1139 1086 - if (proto == IPPROTO_UDP) { 1087 - /* UDP validates ulen. */ 1140 + /* Check for jumbo payload */ 1141 + if (ulen == 0) 1142 + ulen = skb->len; 1088 1143 1089 - /* Check for jumbo payload */ 1090 - if (ulen == 0) 1091 - ulen = skb->len; 1144 + if (ulen < sizeof(*uh)) 1145 + goto short_packet; 1092 1146 1093 - if (ulen < sizeof(*uh)) 1147 + if (ulen < skb->len) { 1148 + if (pskb_trim_rcsum(skb, ulen)) 1094 1149 goto short_packet; 1095 1150 1096 - if (ulen < skb->len) { 1097 - if (pskb_trim_rcsum(skb, ulen)) 1098 - goto short_packet; 1099 - saddr = &ipv6_hdr(skb)->saddr; 1100 - daddr = &ipv6_hdr(skb)->daddr; 1101 - uh = udp_hdr(skb); 1102 - } 1151 + saddr = &ipv6_hdr(skb)->saddr; 1152 + daddr = &ipv6_hdr(skb)->daddr; 1153 + uh = udp_hdr(skb); 1103 1154 } 1104 1155 1105 - if (udp6_csum_init(skb, uh, proto)) 1156 + if (udp6_csum_init(skb, uh)) 1106 1157 goto csum_error; 1107 1158 1108 1159 /* Check if the socket is already available, e.g. due to early demux */ ··· 1131 1188 * Multicast receive code 1132 1189 */ 1133 1190 if (ipv6_addr_is_multicast(daddr)) 1134 - return __udp6_lib_mcast_deliver(net, skb, 1135 - saddr, daddr, udptable, proto); 1191 + return __udp6_lib_mcast_deliver(net, skb, saddr, daddr); 1136 1192 1137 1193 /* Unicast */ 1138 - sk = __udp6_lib_lookup_skb(skb, uh->source, uh->dest, udptable); 1194 + sk = __udp6_lib_lookup_skb(skb, uh->source, uh->dest); 1139 1195 if (sk) { 1140 1196 if (!uh->check && !udp_get_no_check6_rx(sk)) 1141 1197 goto report_csum_error; ··· 1153 1211 if (udp_lib_checksum_complete(skb)) 1154 1212 goto csum_error; 1155 1213 1156 - __UDP6_INC_STATS(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE); 1214 + __UDP6_INC_STATS(net, UDP_MIB_NOPORTS); 1157 1215 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0); 1158 1216 1159 1217 sk_skb_reason_drop(sk, skb, reason); ··· 1162 1220 short_packet: 1163 1221 if (reason == SKB_DROP_REASON_NOT_SPECIFIED) 1164 1222 reason = SKB_DROP_REASON_PKT_TOO_SMALL; 1165 - net_dbg_ratelimited("UDP%sv6: short packet: From [%pI6c]:%u %d/%d to [%pI6c]:%u\n", 1166 - proto == IPPROTO_UDPLITE ? "-Lite" : "", 1223 + net_dbg_ratelimited("UDPv6: short packet: From [%pI6c]:%u %d/%d to [%pI6c]:%u\n", 1167 1224 saddr, ntohs(uh->source), 1168 1225 ulen, skb->len, 1169 1226 daddr, ntohs(uh->dest)); ··· 1173 1232 csum_error: 1174 1233 if (reason == SKB_DROP_REASON_NOT_SPECIFIED) 1175 1234 reason = SKB_DROP_REASON_UDP_CSUM; 1176 - __UDP6_INC_STATS(net, UDP_MIB_CSUMERRORS, proto == IPPROTO_UDPLITE); 1235 + __UDP6_INC_STATS(net, UDP_MIB_CSUMERRORS); 1177 1236 discard: 1178 - __UDP6_INC_STATS(net, UDP_MIB_INERRORS, proto == IPPROTO_UDPLITE); 1237 + __UDP6_INC_STATS(net, UDP_MIB_INERRORS); 1179 1238 sk_skb_reason_drop(sk, skb, reason); 1180 1239 return 0; 1181 1240 } ··· 1247 1306 */ 1248 1307 skb_dst_set_noref(skb, dst); 1249 1308 } 1250 - } 1251 - 1252 - INDIRECT_CALLABLE_SCOPE int udpv6_rcv(struct sk_buff *skb) 1253 - { 1254 - return __udp6_lib_rcv(skb, dev_net(skb->dev)->ipv4.udp_table, IPPROTO_UDP); 1255 1309 } 1256 1310 1257 1311 /* ··· 1353 1417 struct inet_cork *cork) 1354 1418 { 1355 1419 struct sock *sk = skb->sk; 1420 + int offset, len, datalen; 1356 1421 struct udphdr *uh; 1357 1422 int err = 0; 1358 - int is_udplite = IS_UDPLITE(sk); 1359 - __wsum csum = 0; 1360 - int offset = skb_transport_offset(skb); 1361 - int len = skb->len - offset; 1362 - int datalen = len - sizeof(*uh); 1423 + 1424 + offset = skb_transport_offset(skb); 1425 + len = skb->len - offset; 1426 + datalen = len - sizeof(*uh); 1363 1427 1364 1428 /* 1365 1429 * Create a UDP header ··· 1386 1450 kfree_skb(skb); 1387 1451 return -EINVAL; 1388 1452 } 1389 - if (is_udplite || dst_xfrm(skb_dst(skb))) { 1453 + if (dst_xfrm(skb_dst(skb))) { 1390 1454 kfree_skb(skb); 1391 1455 return -EIO; 1392 1456 } ··· 1402 1466 } 1403 1467 } 1404 1468 1405 - if (is_udplite) 1406 - csum = udplite_csum(skb); 1407 - else if (udp_get_no_check6_tx(sk)) { /* UDP csum disabled */ 1469 + if (udp_get_no_check6_tx(sk)) { /* UDP csum disabled */ 1408 1470 skb->ip_summed = CHECKSUM_NONE; 1409 1471 goto send; 1410 1472 } else if (skb->ip_summed == CHECKSUM_PARTIAL) { /* UDP hardware csum */ 1411 1473 csum_partial: 1412 1474 udp6_hwcsum_outgoing(sk, skb, &fl6->saddr, &fl6->daddr, len); 1413 1475 goto send; 1414 - } else 1415 - csum = udp_csum(skb); 1476 + } 1416 1477 1417 1478 /* add protocol-dependent pseudo-header */ 1418 1479 uh->check = csum_ipv6_magic(&fl6->saddr, &fl6->daddr, 1419 - len, fl6->flowi6_proto, csum); 1480 + len, IPPROTO_UDP, udp_csum(skb)); 1420 1481 if (uh->check == 0) 1421 1482 uh->check = CSUM_MANGLED_0; 1422 1483 ··· 1421 1488 err = ip6_send_skb(skb); 1422 1489 if (unlikely(err)) { 1423 1490 if (err == -ENOBUFS && !inet6_test_bit(RECVERR6, sk)) { 1424 - UDP6_INC_STATS(sock_net(sk), 1425 - UDP_MIB_SNDBUFERRORS, is_udplite); 1491 + UDP6_INC_STATS(sock_net(sk), UDP_MIB_SNDBUFERRORS); 1426 1492 err = 0; 1427 1493 } 1428 1494 } else { 1429 - UDP6_INC_STATS(sock_net(sk), 1430 - UDP_MIB_OUTDATAGRAMS, is_udplite); 1495 + UDP6_INC_STATS(sock_net(sk), UDP_MIB_OUTDATAGRAMS); 1431 1496 } 1432 1497 return err; 1433 1498 } ··· 1453 1522 1454 1523 int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) 1455 1524 { 1456 - struct ipv6_txoptions opt_space; 1457 - struct udp_sock *up = udp_sk(sk); 1525 + int corkreq = udp_test_bit(CORK, sk) || msg->msg_flags & MSG_MORE; 1526 + DECLARE_SOCKADDR(struct sockaddr_in6 *, sin6, msg->msg_name); 1527 + struct ipv6_txoptions *opt_to_free = NULL; 1528 + struct in6_addr *daddr, *final_p, final; 1529 + struct ip6_flowlabel *flowlabel = NULL; 1458 1530 struct inet_sock *inet = inet_sk(sk); 1459 1531 struct ipv6_pinfo *np = inet6_sk(sk); 1460 - DECLARE_SOCKADDR(struct sockaddr_in6 *, sin6, msg->msg_name); 1461 - struct in6_addr *daddr, *final_p, final; 1462 1532 struct ipv6_txoptions *opt = NULL; 1463 - struct ipv6_txoptions *opt_to_free = NULL; 1464 - struct ip6_flowlabel *flowlabel = NULL; 1465 - struct inet_cork_full cork; 1466 - struct flowi6 *fl6 = &cork.fl.u.ip6; 1467 - struct dst_entry *dst; 1468 - struct ipcm6_cookie ipc6; 1533 + struct udp_sock *up = udp_sk(sk); 1534 + struct ipv6_txoptions opt_space; 1469 1535 int addr_len = msg->msg_namelen; 1536 + struct inet_cork_full cork; 1537 + struct ipcm6_cookie ipc6; 1470 1538 bool connected = false; 1539 + struct dst_entry *dst; 1540 + struct flowi6 *fl6; 1471 1541 int ulen = len; 1472 - int corkreq = udp_test_bit(CORK, sk) || msg->msg_flags & MSG_MORE; 1473 1542 int err; 1474 - int is_udplite = IS_UDPLITE(sk); 1475 - int (*getfrag)(void *, char *, int, int, int, struct sk_buff *); 1476 1543 1544 + fl6 = &cork.fl.u.ip6; 1477 1545 ipcm6_init_sk(&ipc6, sk); 1478 1546 ipc6.gso_size = READ_ONCE(up->gso_size); 1479 1547 ··· 1531 1601 if (len > INT_MAX - sizeof(struct udphdr)) 1532 1602 return -EMSGSIZE; 1533 1603 1534 - getfrag = is_udplite ? udplite_getfrag : ip_generic_getfrag; 1535 1604 if (READ_ONCE(up->pending)) { 1536 1605 if (READ_ONCE(up->pending) == AF_INET) 1537 1606 return udp_sendmsg(sk, msg, len); ··· 1632 1703 opt = ipv6_fixup_options(&opt_space, opt); 1633 1704 ipc6.opt = opt; 1634 1705 1635 - fl6->flowi6_proto = sk->sk_protocol; 1706 + fl6->flowi6_proto = IPPROTO_UDP; 1636 1707 fl6->flowi6_mark = ipc6.sockc.mark; 1637 1708 fl6->daddr = *daddr; 1638 1709 if (ipv6_addr_any(&fl6->saddr) && !ipv6_addr_any(&np->saddr)) ··· 1699 1770 if (!corkreq) { 1700 1771 struct sk_buff *skb; 1701 1772 1702 - skb = ip6_make_skb(sk, getfrag, msg, ulen, 1773 + skb = ip6_make_skb(sk, ip_generic_getfrag, msg, ulen, 1703 1774 sizeof(struct udphdr), &ipc6, 1704 1775 dst_rt6_info(dst), 1705 1776 msg->msg_flags, &cork); ··· 1725 1796 1726 1797 do_append_data: 1727 1798 up->len += ulen; 1728 - err = ip6_append_data(sk, getfrag, msg, ulen, sizeof(struct udphdr), 1729 - &ipc6, fl6, dst_rt6_info(dst), 1799 + err = ip6_append_data(sk, ip_generic_getfrag, msg, ulen, 1800 + sizeof(struct udphdr), &ipc6, fl6, 1801 + dst_rt6_info(dst), 1730 1802 corkreq ? msg->msg_flags|MSG_MORE : msg->msg_flags); 1731 1803 if (err) 1732 1804 udp_v6_flush_pending_frames(sk); ··· 1754 1824 * things). We could add another new stat but at least for now that 1755 1825 * seems like overkill. 1756 1826 */ 1757 - if (err == -ENOBUFS || test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) { 1758 - UDP6_INC_STATS(sock_net(sk), 1759 - UDP_MIB_SNDBUFERRORS, is_udplite); 1760 - } 1827 + if (err == -ENOBUFS || test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) 1828 + UDP6_INC_STATS(sock_net(sk), UDP_MIB_SNDBUFERRORS); 1829 + 1761 1830 return err; 1762 1831 1763 1832 do_confirm: ··· 1783 1854 release_sock(sk); 1784 1855 } 1785 1856 1786 - void udpv6_destroy_sock(struct sock *sk) 1857 + static void udpv6_destroy_sock(struct sock *sk) 1787 1858 { 1788 1859 struct udp_sock *up = udp_sk(sk); 1789 1860 lock_sock(sk); ··· 1811 1882 /* 1812 1883 * Socket option code for UDP 1813 1884 */ 1814 - int udpv6_setsockopt(struct sock *sk, int level, int optname, sockptr_t optval, 1815 - unsigned int optlen) 1885 + static int udpv6_setsockopt(struct sock *sk, int level, int optname, 1886 + sockptr_t optval, unsigned int optlen) 1816 1887 { 1817 - if (level == SOL_UDP || level == SOL_UDPLITE || level == SOL_SOCKET) 1888 + if (level == SOL_UDP || level == SOL_SOCKET) 1818 1889 return udp_lib_setsockopt(sk, level, optname, 1819 1890 optval, optlen, 1820 1891 udp_v6_push_pending_frames); 1821 1892 return ipv6_setsockopt(sk, level, optname, optval, optlen); 1822 1893 } 1823 1894 1824 - int udpv6_getsockopt(struct sock *sk, int level, int optname, 1825 - char __user *optval, int __user *optlen) 1895 + static int udpv6_getsockopt(struct sock *sk, int level, int optname, 1896 + char __user *optval, int __user *optlen) 1826 1897 { 1827 - if (level == SOL_UDP || level == SOL_UDPLITE) 1898 + if (level == SOL_UDP) 1828 1899 return udp_lib_getsockopt(sk, level, optname, optval, optlen); 1829 1900 return ipv6_getsockopt(sk, level, optname, optval, optlen); 1830 1901 } ··· 1832 1903 1833 1904 /* ------------------------------------------------------------------------ */ 1834 1905 #ifdef CONFIG_PROC_FS 1835 - int udp6_seq_show(struct seq_file *seq, void *v) 1906 + static int udp6_seq_show(struct seq_file *seq, void *v) 1836 1907 { 1837 1908 if (v == SEQ_START_TOKEN) { 1838 1909 seq_puts(seq, IPV6_SEQ_DGRAM_HEADER); ··· 1847 1918 return 0; 1848 1919 } 1849 1920 1850 - const struct seq_operations udp6_seq_ops = { 1921 + static const struct seq_operations udp6_seq_ops = { 1851 1922 .start = udp_seq_start, 1852 1923 .next = udp_seq_next, 1853 1924 .stop = udp_seq_stop, 1854 1925 .show = udp6_seq_show, 1855 1926 }; 1856 - EXPORT_SYMBOL(udp6_seq_ops); 1857 1927 1858 1928 static struct udp_seq_afinfo udp6_seq_afinfo = { 1859 1929 .family = AF_INET6, 1860 - .udp_table = NULL, 1861 1930 }; 1862 1931 1863 1932 int __net_init udp6_proc_init(struct net *net) ··· 1907 1980 .sysctl_rmem_offset = offsetof(struct net, ipv4.sysctl_udp_rmem_min), 1908 1981 .obj_size = sizeof(struct udp6_sock), 1909 1982 .ipv6_pinfo_offset = offsetof(struct udp6_sock, inet6), 1910 - .h.udp_table = NULL, 1911 1983 .diag_destroy = udp_abort, 1912 1984 }; 1913 1985
-31
net/ipv6/udp_impl.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef _UDP6_IMPL_H 3 - #define _UDP6_IMPL_H 4 - #include <net/aligned_data.h> 5 - #include <net/udp.h> 6 - #include <net/udplite.h> 7 - #include <net/protocol.h> 8 - #include <net/addrconf.h> 9 - #include <net/inet_common.h> 10 - #include <net/transp_v6.h> 11 - 12 - int __udp6_lib_rcv(struct sk_buff *, struct udp_table *, int); 13 - int __udp6_lib_err(struct sk_buff *, struct inet6_skb_parm *, u8, u8, int, 14 - __be32, struct udp_table *); 15 - 16 - int udpv6_init_sock(struct sock *sk); 17 - int udp_v6_get_port(struct sock *sk, unsigned short snum); 18 - void udp_v6_rehash(struct sock *sk); 19 - 20 - int udpv6_getsockopt(struct sock *sk, int level, int optname, 21 - char __user *optval, int __user *optlen); 22 - int udpv6_setsockopt(struct sock *sk, int level, int optname, sockptr_t optval, 23 - unsigned int optlen); 24 - int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len); 25 - int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int flags); 26 - void udpv6_destroy_sock(struct sock *sk); 27 - 28 - #ifdef CONFIG_PROC_FS 29 - int udp6_seq_show(struct seq_file *seq, void *v); 30 - #endif 31 - #endif /* _UDP6_IMPL_H */
+1 -2
net/ipv6/udp_offload.c
··· 128 128 inet6_get_iif_sdif(skb, &iif, &sdif); 129 129 130 130 return __udp6_lib_lookup(net, &iph->saddr, sport, 131 - &iph->daddr, dport, iif, 132 - sdif, net->ipv4.udp_table, NULL); 131 + &iph->daddr, dport, iif, sdif, NULL); 133 132 } 134 133 135 134 struct sk_buff *udp6_gro_receive(struct list_head *head, struct sk_buff *skb)
-139
net/ipv6/udplite.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-or-later 2 - /* 3 - * UDPLITEv6 An implementation of the UDP-Lite protocol over IPv6. 4 - * See also net/ipv4/udplite.c 5 - * 6 - * Authors: Gerrit Renker <gerrit@erg.abdn.ac.uk> 7 - * 8 - * Changes: 9 - * Fixes: 10 - */ 11 - #define pr_fmt(fmt) "UDPLite6: " fmt 12 - 13 - #include <linux/export.h> 14 - #include <linux/proc_fs.h> 15 - #include "udp_impl.h" 16 - 17 - static int udplitev6_sk_init(struct sock *sk) 18 - { 19 - pr_warn_once("UDP-Lite is deprecated and scheduled to be removed in 2025, " 20 - "please contact the netdev mailing list\n"); 21 - return udpv6_init_sock(sk); 22 - } 23 - 24 - static int udplitev6_rcv(struct sk_buff *skb) 25 - { 26 - return __udp6_lib_rcv(skb, &udplite_table, IPPROTO_UDPLITE); 27 - } 28 - 29 - static int udplitev6_err(struct sk_buff *skb, 30 - struct inet6_skb_parm *opt, 31 - u8 type, u8 code, int offset, __be32 info) 32 - { 33 - return __udp6_lib_err(skb, opt, type, code, offset, info, 34 - &udplite_table); 35 - } 36 - 37 - static const struct inet6_protocol udplitev6_protocol = { 38 - .handler = udplitev6_rcv, 39 - .err_handler = udplitev6_err, 40 - .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL, 41 - }; 42 - 43 - struct proto udplitev6_prot = { 44 - .name = "UDPLITEv6", 45 - .owner = THIS_MODULE, 46 - .close = udp_lib_close, 47 - .connect = ip6_datagram_connect, 48 - .disconnect = udp_disconnect, 49 - .ioctl = udp_ioctl, 50 - .init = udplitev6_sk_init, 51 - .destroy = udpv6_destroy_sock, 52 - .setsockopt = udpv6_setsockopt, 53 - .getsockopt = udpv6_getsockopt, 54 - .sendmsg = udpv6_sendmsg, 55 - .recvmsg = udpv6_recvmsg, 56 - .hash = udp_lib_hash, 57 - .unhash = udp_lib_unhash, 58 - .rehash = udp_v6_rehash, 59 - .get_port = udp_v6_get_port, 60 - 61 - .memory_allocated = &net_aligned_data.udp_memory_allocated, 62 - .per_cpu_fw_alloc = &udp_memory_per_cpu_fw_alloc, 63 - 64 - .sysctl_mem = sysctl_udp_mem, 65 - .sysctl_wmem_offset = offsetof(struct net, ipv4.sysctl_udp_wmem_min), 66 - .sysctl_rmem_offset = offsetof(struct net, ipv4.sysctl_udp_rmem_min), 67 - .obj_size = sizeof(struct udp6_sock), 68 - .ipv6_pinfo_offset = offsetof(struct udp6_sock, inet6), 69 - .h.udp_table = &udplite_table, 70 - }; 71 - 72 - static struct inet_protosw udplite6_protosw = { 73 - .type = SOCK_DGRAM, 74 - .protocol = IPPROTO_UDPLITE, 75 - .prot = &udplitev6_prot, 76 - .ops = &inet6_dgram_ops, 77 - .flags = INET_PROTOSW_PERMANENT, 78 - }; 79 - 80 - int __init udplitev6_init(void) 81 - { 82 - int ret; 83 - 84 - ret = inet6_add_protocol(&udplitev6_protocol, IPPROTO_UDPLITE); 85 - if (ret) 86 - goto out; 87 - 88 - ret = inet6_register_protosw(&udplite6_protosw); 89 - if (ret) 90 - goto out_udplitev6_protocol; 91 - out: 92 - return ret; 93 - 94 - out_udplitev6_protocol: 95 - inet6_del_protocol(&udplitev6_protocol, IPPROTO_UDPLITE); 96 - goto out; 97 - } 98 - 99 - void udplitev6_exit(void) 100 - { 101 - inet6_unregister_protosw(&udplite6_protosw); 102 - inet6_del_protocol(&udplitev6_protocol, IPPROTO_UDPLITE); 103 - } 104 - 105 - #ifdef CONFIG_PROC_FS 106 - static struct udp_seq_afinfo udplite6_seq_afinfo = { 107 - .family = AF_INET6, 108 - .udp_table = &udplite_table, 109 - }; 110 - 111 - static int __net_init udplite6_proc_init_net(struct net *net) 112 - { 113 - if (!proc_create_net_data("udplite6", 0444, net->proc_net, 114 - &udp6_seq_ops, sizeof(struct udp_iter_state), 115 - &udplite6_seq_afinfo)) 116 - return -ENOMEM; 117 - return 0; 118 - } 119 - 120 - static void __net_exit udplite6_proc_exit_net(struct net *net) 121 - { 122 - remove_proc_entry("udplite6", net->proc_net); 123 - } 124 - 125 - static struct pernet_operations udplite6_net_ops = { 126 - .init = udplite6_proc_init_net, 127 - .exit = udplite6_proc_exit_net, 128 - }; 129 - 130 - int __init udplite6_proc_init(void) 131 - { 132 - return register_pernet_subsys(&udplite6_net_ops); 133 - } 134 - 135 - void udplite6_proc_exit(void) 136 - { 137 - unregister_pernet_subsys(&udplite6_net_ops); 138 - } 139 - #endif
-2
net/rxrpc/output.c
··· 16 16 #include <net/udp.h> 17 17 #include "ar-internal.h" 18 18 19 - extern int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len); 20 - 21 19 ssize_t do_udp_sendmsg(struct socket *socket, struct msghdr *msg, size_t len) 22 20 { 23 21 struct sockaddr *sa = msg->msg_name;
+1 -3
security/smack/smack_lsm.c
··· 4176 4176 sip->sin6_port = th->source; 4177 4177 break; 4178 4178 case IPPROTO_UDP: 4179 - case IPPROTO_UDPLITE: 4180 4179 uh = skb_header_pointer(skb, offset, sizeof(_udph), &_udph); 4181 4180 if (uh != NULL) 4182 4181 sip->sin6_port = uh->source; ··· 4300 4301 #if IS_ENABLED(CONFIG_IPV6) 4301 4302 case PF_INET6: 4302 4303 proto = smk_skb_to_addr_ipv6(skb, &sadd); 4303 - if (proto != IPPROTO_UDP && proto != IPPROTO_UDPLITE && 4304 - proto != IPPROTO_TCP) 4304 + if (proto != IPPROTO_UDP && proto != IPPROTO_TCP) 4305 4305 break; 4306 4306 #ifdef SMACK_IPV6_SECMARK_LABELING 4307 4307 skp = smack_from_skb(skb);