1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 3 * INET An implementation of the TCP/IP protocol suite for the LINUX 4 * operating system. INET is implemented using the BSD Socket 5 * interface as the means of communication with the user level. 6 * 7 * Definitions for the UDP module. 8 * 9 * Version: @(#)udp.h 1.0.2 05/07/93 10 * 11 * Authors: Ross Biro 12 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> 13 * 14 * Fixes: 15 * Alan Cox : Turned on udp checksums. I don't want to 16 * chase 'memory corruption' bugs that aren't! 17 */ 18 #ifndef _UDP_H 19 #define _UDP_H 20 21 #include <linux/list.h> 22 #include <linux/bug.h> 23 #include <net/inet_sock.h> 24 #include <net/gso.h> 25 #include <net/sock.h> 26 #include <net/snmp.h> 27 #include <net/ip.h> 28 #include <linux/ipv6.h> 29 #include <linux/seq_file.h> 30 #include <linux/poll.h> 31 #include <linux/indirect_call_wrapper.h> 32 33 /** 34 * struct udp_skb_cb - UDP(-Lite) private variables 35 * 36 * @header: private variables used by IPv4/IPv6 37 * @cscov: checksum coverage length (UDP-Lite only) 38 * @partial_cov: if set indicates partial csum coverage 39 */ 40 struct udp_skb_cb { 41 union { 42 struct inet_skb_parm h4; 43 #if IS_ENABLED(CONFIG_IPV6) 44 struct inet6_skb_parm h6; 45 #endif 46 } header; 47 __u16 cscov; 48 __u8 partial_cov; 49 }; 50 #define UDP_SKB_CB(__skb) ((struct udp_skb_cb *)((__skb)->cb)) 51 52 /** 53 * struct udp_hslot - UDP hash slot used by udp_table.hash/hash4 54 * 55 * @head: head of list of sockets 56 * @nulls_head: head of list of sockets, only used by hash4 57 * @count: number of sockets in 'head' list 58 * @lock: spinlock protecting changes to head/count 59 */ 60 struct udp_hslot { 61 union { 62 struct hlist_head head; 63 /* hash4 uses hlist_nulls to avoid moving wrongly onto another 64 * hlist, because rehash() can happen with lookup(). 65 */ 66 struct hlist_nulls_head nulls_head; 67 }; 68 int count; 69 spinlock_t lock; 70 } __aligned(2 * sizeof(long)); 71 72 /** 73 * struct udp_hslot_main - UDP hash slot used by udp_table.hash2 74 * 75 * @hslot: basic hash slot 76 * @hash4_cnt: number of sockets in hslot4 of the same 77 * (local port, local address) 78 */ 79 struct udp_hslot_main { 80 struct udp_hslot hslot; /* must be the first member */ 81 #if !IS_ENABLED(CONFIG_BASE_SMALL) 82 u32 hash4_cnt; 83 #endif 84 } __aligned(2 * sizeof(long)); 85 #define UDP_HSLOT_MAIN(__hslot) ((struct udp_hslot_main *)(__hslot)) 86 87 /** 88 * struct udp_table - UDP table 89 * 90 * @hash: hash table, sockets are hashed on (local port) 91 * @hash2: hash table, sockets are hashed on (local port, local address) 92 * @hash4: hash table, connected sockets are hashed on 93 * (local port, local address, remote port, remote address) 94 * @mask: number of slots in hash tables, minus 1 95 * @log: log2(number of slots in hash table) 96 */ 97 struct udp_table { 98 struct udp_hslot *hash; 99 struct udp_hslot_main *hash2; 100 #if !IS_ENABLED(CONFIG_BASE_SMALL) 101 struct udp_hslot *hash4; 102 #endif 103 unsigned int mask; 104 unsigned int log; 105 }; 106 extern struct udp_table udp_table; 107 void udp_table_init(struct udp_table *, const char *); 108 static inline struct udp_hslot *udp_hashslot(struct udp_table *table, 109 const struct net *net, 110 unsigned int num) 111 { 112 return &table->hash[udp_hashfn(net, num, table->mask)]; 113 } 114 115 /* 116 * For secondary hash, net_hash_mix() is performed before calling 117 * udp_hashslot2(), this explains difference with udp_hashslot() 118 */ 119 static inline struct udp_hslot *udp_hashslot2(struct udp_table *table, 120 unsigned int hash) 121 { 122 return &table->hash2[hash & table->mask].hslot; 123 } 124 125 #if IS_ENABLED(CONFIG_BASE_SMALL) 126 static inline void udp_table_hash4_init(struct udp_table *table) 127 { 128 } 129 130 static inline struct udp_hslot *udp_hashslot4(struct udp_table *table, 131 unsigned int hash) 132 { 133 BUILD_BUG(); 134 return NULL; 135 } 136 137 static inline bool udp_hashed4(const struct sock *sk) 138 { 139 return false; 140 } 141 142 static inline unsigned int udp_hash4_slot_size(void) 143 { 144 return 0; 145 } 146 147 static inline bool udp_has_hash4(const struct udp_hslot *hslot2) 148 { 149 return false; 150 } 151 152 static inline void udp_hash4_inc(struct udp_hslot *hslot2) 153 { 154 } 155 156 static inline void udp_hash4_dec(struct udp_hslot *hslot2) 157 { 158 } 159 #else /* !CONFIG_BASE_SMALL */ 160 161 /* Must be called with table->hash2 initialized */ 162 static inline void udp_table_hash4_init(struct udp_table *table) 163 { 164 table->hash4 = (void *)(table->hash2 + (table->mask + 1)); 165 for (int i = 0; i <= table->mask; i++) { 166 table->hash2[i].hash4_cnt = 0; 167 168 INIT_HLIST_NULLS_HEAD(&table->hash4[i].nulls_head, i); 169 table->hash4[i].count = 0; 170 spin_lock_init(&table->hash4[i].lock); 171 } 172 } 173 174 static inline struct udp_hslot *udp_hashslot4(struct udp_table *table, 175 unsigned int hash) 176 { 177 return &table->hash4[hash & table->mask]; 178 } 179 180 static inline bool udp_hashed4(const struct sock *sk) 181 { 182 return !hlist_nulls_unhashed(&udp_sk(sk)->udp_lrpa_node); 183 } 184 185 static inline unsigned int udp_hash4_slot_size(void) 186 { 187 return sizeof(struct udp_hslot); 188 } 189 190 static inline bool udp_has_hash4(const struct udp_hslot *hslot2) 191 { 192 return UDP_HSLOT_MAIN(hslot2)->hash4_cnt; 193 } 194 195 static inline void udp_hash4_inc(struct udp_hslot *hslot2) 196 { 197 UDP_HSLOT_MAIN(hslot2)->hash4_cnt++; 198 } 199 200 static inline void udp_hash4_dec(struct udp_hslot *hslot2) 201 { 202 UDP_HSLOT_MAIN(hslot2)->hash4_cnt--; 203 } 204 #endif /* CONFIG_BASE_SMALL */ 205 206 extern struct proto udp_prot; 207 208 DECLARE_PER_CPU(int, udp_memory_per_cpu_fw_alloc); 209 210 /* sysctl variables for udp */ 211 extern long sysctl_udp_mem[3]; 212 extern int sysctl_udp_rmem_min; 213 extern int sysctl_udp_wmem_min; 214 215 struct sk_buff; 216 217 /* 218 * Generic checksumming routines for UDP(-Lite) v4 and v6 219 */ 220 static inline __sum16 __udp_lib_checksum_complete(struct sk_buff *skb) 221 { 222 return (UDP_SKB_CB(skb)->cscov == skb->len ? 223 __skb_checksum_complete(skb) : 224 __skb_checksum_complete_head(skb, UDP_SKB_CB(skb)->cscov)); 225 } 226 227 static inline int udp_lib_checksum_complete(struct sk_buff *skb) 228 { 229 return !skb_csum_unnecessary(skb) && 230 __udp_lib_checksum_complete(skb); 231 } 232 233 /** 234 * udp_csum_outgoing - compute UDPv4/v6 checksum over fragments 235 * @sk: socket we are writing to 236 * @skb: sk_buff containing the filled-in UDP header 237 * (checksum field must be zeroed out) 238 */ 239 static inline __wsum udp_csum_outgoing(struct sock *sk, struct sk_buff *skb) 240 { 241 __wsum csum = csum_partial(skb_transport_header(skb), 242 sizeof(struct udphdr), 0); 243 skb_queue_walk(&sk->sk_write_queue, skb) { 244 csum = csum_add(csum, skb->csum); 245 } 246 return csum; 247 } 248 249 static inline __wsum udp_csum(struct sk_buff *skb) 250 { 251 __wsum csum = csum_partial(skb_transport_header(skb), 252 sizeof(struct udphdr), skb->csum); 253 254 for (skb = skb_shinfo(skb)->frag_list; skb; skb = skb->next) { 255 csum = csum_add(csum, skb->csum); 256 } 257 return csum; 258 } 259 260 static inline __sum16 udp_v4_check(int len, __be32 saddr, 261 __be32 daddr, __wsum base) 262 { 263 return csum_tcpudp_magic(saddr, daddr, len, IPPROTO_UDP, base); 264 } 265 266 void udp_set_csum(bool nocheck, struct sk_buff *skb, 267 __be32 saddr, __be32 daddr, int len); 268 269 static inline void udp_csum_pull_header(struct sk_buff *skb) 270 { 271 if (!skb->csum_valid && skb->ip_summed == CHECKSUM_NONE) 272 skb->csum = csum_partial(skb->data, sizeof(struct udphdr), 273 skb->csum); 274 skb_pull_rcsum(skb, sizeof(struct udphdr)); 275 UDP_SKB_CB(skb)->cscov -= sizeof(struct udphdr); 276 } 277 278 typedef struct sock *(*udp_lookup_t)(const struct sk_buff *skb, __be16 sport, 279 __be16 dport); 280 281 void udp_v6_early_demux(struct sk_buff *skb); 282 INDIRECT_CALLABLE_DECLARE(int udpv6_rcv(struct sk_buff *)); 283 284 struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, 285 netdev_features_t features, bool is_ipv6); 286 287 static inline void udp_lib_init_sock(struct sock *sk) 288 { 289 struct udp_sock *up = udp_sk(sk); 290 291 sk->sk_drop_counters = &up->drop_counters; 292 spin_lock_init(&up->busylock); 293 skb_queue_head_init(&up->reader_queue); 294 INIT_HLIST_NODE(&up->tunnel_list); 295 up->forward_threshold = sk->sk_rcvbuf >> 2; 296 set_bit(SOCK_CUSTOM_SOCKOPT, &sk->sk_socket->flags); 297 } 298 299 static inline void udp_drops_inc(struct sock *sk) 300 { 301 numa_drop_add(&udp_sk(sk)->drop_counters, 1); 302 } 303 304 /* hash routines shared between UDPv4/6 and UDP-Litev4/6 */ 305 static inline int udp_lib_hash(struct sock *sk) 306 { 307 BUG(); 308 return 0; 309 } 310 311 void udp_lib_unhash(struct sock *sk); 312 void udp_lib_rehash(struct sock *sk, u16 new_hash, u16 new_hash4); 313 u32 udp_ehashfn(const struct net *net, const __be32 laddr, const __u16 lport, 314 const __be32 faddr, const __be16 fport); 315 316 static inline void udp_lib_close(struct sock *sk, long timeout) 317 { 318 sk_common_release(sk); 319 } 320 321 /* hash4 routines shared between UDPv4/6 */ 322 #if IS_ENABLED(CONFIG_BASE_SMALL) 323 static inline void udp_lib_hash4(struct sock *sk, u16 hash) 324 { 325 } 326 327 static inline void udp4_hash4(struct sock *sk) 328 { 329 } 330 #else /* !CONFIG_BASE_SMALL */ 331 void udp_lib_hash4(struct sock *sk, u16 hash); 332 void udp4_hash4(struct sock *sk); 333 #endif /* CONFIG_BASE_SMALL */ 334 335 int udp_lib_get_port(struct sock *sk, unsigned short snum, 336 unsigned int hash2_nulladdr); 337 338 u32 udp_flow_hashrnd(void); 339 340 static inline __be16 udp_flow_src_port(struct net *net, struct sk_buff *skb, 341 int min, int max, bool use_eth) 342 { 343 u32 hash; 344 345 if (min >= max) { 346 /* Use default range */ 347 inet_get_local_port_range(net, &min, &max); 348 } 349 350 hash = skb_get_hash(skb); 351 if (unlikely(!hash)) { 352 if (use_eth) { 353 /* Can't find a normal hash, caller has indicated an 354 * Ethernet packet so use that to compute a hash. 355 */ 356 hash = jhash(skb->data, 2 * ETH_ALEN, 357 (__force u32) skb->protocol); 358 } else { 359 /* Can't derive any sort of hash for the packet, set 360 * to some consistent random value. 361 */ 362 hash = udp_flow_hashrnd(); 363 } 364 } 365 366 /* Since this is being sent on the wire obfuscate hash a bit 367 * to minimize possibility that any useful information to an 368 * attacker is leaked. Only upper 16 bits are relevant in the 369 * computation for 16 bit port value. 370 */ 371 hash ^= hash << 16; 372 373 return htons((((u64) hash * (max - min)) >> 32) + min); 374 } 375 376 static inline int udp_rqueue_get(struct sock *sk) 377 { 378 return sk_rmem_alloc_get(sk) - READ_ONCE(udp_sk(sk)->forward_deficit); 379 } 380 381 static inline bool udp_sk_bound_dev_eq(const struct net *net, int bound_dev_if, 382 int dif, int sdif) 383 { 384 #if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV) 385 return inet_bound_dev_eq(!!READ_ONCE(net->ipv4.sysctl_udp_l3mdev_accept), 386 bound_dev_if, dif, sdif); 387 #else 388 return inet_bound_dev_eq(true, bound_dev_if, dif, sdif); 389 #endif 390 } 391 392 /* net/ipv4/udp.c */ 393 void udp_destruct_common(struct sock *sk); 394 void skb_consume_udp(struct sock *sk, struct sk_buff *skb, int len); 395 int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb); 396 void udp_skb_destructor(struct sock *sk, struct sk_buff *skb); 397 struct sk_buff *__skb_recv_udp(struct sock *sk, unsigned int flags, int *off, 398 int *err); 399 static inline struct sk_buff *skb_recv_udp(struct sock *sk, unsigned int flags, 400 int *err) 401 { 402 int off = 0; 403 404 return __skb_recv_udp(sk, flags, &off, err); 405 } 406 407 int udp_v4_early_demux(struct sk_buff *skb); 408 bool udp_sk_rx_dst_set(struct sock *sk, struct dst_entry *dst); 409 int udp_err(struct sk_buff *, u32); 410 int udp_abort(struct sock *sk, int err); 411 int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len); 412 void udp_splice_eof(struct socket *sock); 413 int udp_push_pending_frames(struct sock *sk); 414 void udp_flush_pending_frames(struct sock *sk); 415 int udp_cmsg_send(struct sock *sk, struct msghdr *msg, u16 *gso_size); 416 void udp4_hwcsum(struct sk_buff *skb, __be32 src, __be32 dst); 417 int udp_rcv(struct sk_buff *skb); 418 int udp_ioctl(struct sock *sk, int cmd, int *karg); 419 int udp_init_sock(struct sock *sk); 420 int udp_pre_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len); 421 int __udp_disconnect(struct sock *sk, int flags); 422 int udp_disconnect(struct sock *sk, int flags); 423 __poll_t udp_poll(struct file *file, struct socket *sock, poll_table *wait); 424 struct sk_buff *skb_udp_tunnel_segment(struct sk_buff *skb, 425 netdev_features_t features, 426 bool is_ipv6); 427 int udp_lib_getsockopt(struct sock *sk, int level, int optname, 428 char __user *optval, int __user *optlen); 429 int udp_lib_setsockopt(struct sock *sk, int level, int optname, 430 sockptr_t optval, unsigned int optlen, 431 int (*push_pending_frames)(struct sock *)); 432 struct sock *udp4_lib_lookup(const struct net *net, __be32 saddr, __be16 sport, 433 __be32 daddr, __be16 dport, int dif); 434 struct sock *__udp4_lib_lookup(const struct net *net, __be32 saddr, 435 __be16 sport, 436 __be32 daddr, __be16 dport, int dif, int sdif, 437 struct udp_table *tbl, struct sk_buff *skb); 438 struct sock *udp4_lib_lookup_skb(const struct sk_buff *skb, 439 __be16 sport, __be16 dport); 440 struct sock *udp6_lib_lookup(const struct net *net, 441 const struct in6_addr *saddr, __be16 sport, 442 const struct in6_addr *daddr, __be16 dport, 443 int dif); 444 struct sock *__udp6_lib_lookup(const struct net *net, 445 const struct in6_addr *saddr, __be16 sport, 446 const struct in6_addr *daddr, __be16 dport, 447 int dif, int sdif, struct udp_table *tbl, 448 struct sk_buff *skb); 449 struct sock *udp6_lib_lookup_skb(const struct sk_buff *skb, 450 __be16 sport, __be16 dport); 451 int udp_read_skb(struct sock *sk, skb_read_actor_t recv_actor); 452 453 /* UDP uses skb->dev_scratch to cache as much information as possible and avoid 454 * possibly multiple cache miss on dequeue() 455 */ 456 struct udp_dev_scratch { 457 /* skb->truesize and the stateless bit are embedded in a single field; 458 * do not use a bitfield since the compiler emits better/smaller code 459 * this way 460 */ 461 u32 _tsize_state; 462 463 #if BITS_PER_LONG == 64 464 /* len and the bit needed to compute skb_csum_unnecessary 465 * will be on cold cache lines at recvmsg time. 466 * skb->len can be stored on 16 bits since the udp header has been 467 * already validated and pulled. 468 */ 469 u16 len; 470 bool is_linear; 471 bool csum_unnecessary; 472 #endif 473 }; 474 475 static inline struct udp_dev_scratch *udp_skb_scratch(struct sk_buff *skb) 476 { 477 return (struct udp_dev_scratch *)&skb->dev_scratch; 478 } 479 480 #if BITS_PER_LONG == 64 481 static inline unsigned int udp_skb_len(struct sk_buff *skb) 482 { 483 return udp_skb_scratch(skb)->len; 484 } 485 486 static inline bool udp_skb_csum_unnecessary(struct sk_buff *skb) 487 { 488 return udp_skb_scratch(skb)->csum_unnecessary; 489 } 490 491 static inline bool udp_skb_is_linear(struct sk_buff *skb) 492 { 493 return udp_skb_scratch(skb)->is_linear; 494 } 495 496 #else 497 static inline unsigned int udp_skb_len(struct sk_buff *skb) 498 { 499 return skb->len; 500 } 501 502 static inline bool udp_skb_csum_unnecessary(struct sk_buff *skb) 503 { 504 return skb_csum_unnecessary(skb); 505 } 506 507 static inline bool udp_skb_is_linear(struct sk_buff *skb) 508 { 509 return !skb_is_nonlinear(skb); 510 } 511 #endif 512 513 static inline int copy_linear_skb(struct sk_buff *skb, int len, int off, 514 struct iov_iter *to) 515 { 516 return copy_to_iter_full(skb->data + off, len, to) ? 0 : -EFAULT; 517 } 518 519 /* 520 * SNMP statistics for UDP and UDP-Lite 521 */ 522 #define UDP_INC_STATS(net, field, is_udplite) do { \ 523 if (is_udplite) SNMP_INC_STATS((net)->mib.udplite_statistics, field); \ 524 else SNMP_INC_STATS((net)->mib.udp_statistics, field); } while(0) 525 #define __UDP_INC_STATS(net, field, is_udplite) do { \ 526 if (is_udplite) __SNMP_INC_STATS((net)->mib.udplite_statistics, field); \ 527 else __SNMP_INC_STATS((net)->mib.udp_statistics, field); } while(0) 528 529 #define __UDP6_INC_STATS(net, field, is_udplite) do { \ 530 if (is_udplite) __SNMP_INC_STATS((net)->mib.udplite_stats_in6, field);\ 531 else __SNMP_INC_STATS((net)->mib.udp_stats_in6, field); \ 532 } while(0) 533 #define UDP6_INC_STATS(net, field, __lite) do { \ 534 if (__lite) SNMP_INC_STATS((net)->mib.udplite_stats_in6, field); \ 535 else SNMP_INC_STATS((net)->mib.udp_stats_in6, field); \ 536 } while(0) 537 538 #if IS_ENABLED(CONFIG_IPV6) 539 #define __UDPX_MIB(sk, ipv4) \ 540 ({ \ 541 ipv4 ? (IS_UDPLITE(sk) ? sock_net(sk)->mib.udplite_statistics : \ 542 sock_net(sk)->mib.udp_statistics) : \ 543 (IS_UDPLITE(sk) ? sock_net(sk)->mib.udplite_stats_in6 : \ 544 sock_net(sk)->mib.udp_stats_in6); \ 545 }) 546 #else 547 #define __UDPX_MIB(sk, ipv4) \ 548 ({ \ 549 IS_UDPLITE(sk) ? sock_net(sk)->mib.udplite_statistics : \ 550 sock_net(sk)->mib.udp_statistics; \ 551 }) 552 #endif 553 554 #define __UDPX_INC_STATS(sk, field) \ 555 __SNMP_INC_STATS(__UDPX_MIB(sk, (sk)->sk_family == AF_INET), field) 556 557 #ifdef CONFIG_PROC_FS 558 struct udp_seq_afinfo { 559 sa_family_t family; 560 struct udp_table *udp_table; 561 }; 562 563 struct udp_iter_state { 564 struct seq_net_private p; 565 int bucket; 566 }; 567 568 void *udp_seq_start(struct seq_file *seq, loff_t *pos); 569 void *udp_seq_next(struct seq_file *seq, void *v, loff_t *pos); 570 void udp_seq_stop(struct seq_file *seq, void *v); 571 572 extern const struct seq_operations udp_seq_ops; 573 extern const struct seq_operations udp6_seq_ops; 574 575 int udp4_proc_init(void); 576 void udp4_proc_exit(void); 577 #endif /* CONFIG_PROC_FS */ 578 579 int udpv4_offload_init(void); 580 581 void udp_init(void); 582 583 DECLARE_STATIC_KEY_FALSE(udp_encap_needed_key); 584 void udp_encap_enable(void); 585 void udp_encap_disable(void); 586 #if IS_ENABLED(CONFIG_IPV6) 587 DECLARE_STATIC_KEY_FALSE(udpv6_encap_needed_key); 588 void udpv6_encap_enable(void); 589 #endif 590 591 static inline struct sk_buff *udp_rcv_segment(struct sock *sk, 592 struct sk_buff *skb, bool ipv4) 593 { 594 netdev_features_t features = NETIF_F_SG; 595 struct sk_buff *segs; 596 int drop_count; 597 598 /* 599 * Segmentation in UDP receive path is only for UDP GRO, drop udp 600 * fragmentation offload (UFO) packets. 601 */ 602 if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP) { 603 drop_count = 1; 604 goto drop; 605 } 606 607 /* Avoid csum recalculation by skb_segment unless userspace explicitly 608 * asks for the final checksum values 609 */ 610 if (!inet_get_convert_csum(sk)) 611 features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; 612 613 /* UDP segmentation expects packets of type CHECKSUM_PARTIAL or 614 * CHECKSUM_NONE in __udp_gso_segment. UDP GRO indeed builds partial 615 * packets in udp_gro_complete_segment. As does UDP GSO, verified by 616 * udp_send_skb. But when those packets are looped in dev_loopback_xmit 617 * their ip_summed CHECKSUM_NONE is changed to CHECKSUM_UNNECESSARY. 618 * Reset in this specific case, where PARTIAL is both correct and 619 * required. 620 */ 621 if (skb->pkt_type == PACKET_LOOPBACK) 622 skb->ip_summed = CHECKSUM_PARTIAL; 623 624 /* the GSO CB lays after the UDP one, no need to save and restore any 625 * CB fragment 626 */ 627 segs = __skb_gso_segment(skb, features, false); 628 if (IS_ERR_OR_NULL(segs)) { 629 drop_count = skb_shinfo(skb)->gso_segs; 630 goto drop; 631 } 632 633 consume_skb(skb); 634 return segs; 635 636 drop: 637 sk_drops_add(sk, drop_count); 638 SNMP_ADD_STATS(__UDPX_MIB(sk, ipv4), UDP_MIB_INERRORS, drop_count); 639 kfree_skb(skb); 640 return NULL; 641 } 642 643 static inline void udp_post_segment_fix_csum(struct sk_buff *skb) 644 { 645 /* UDP-lite can't land here - no GRO */ 646 WARN_ON_ONCE(UDP_SKB_CB(skb)->partial_cov); 647 648 /* UDP packets generated with UDP_SEGMENT and traversing: 649 * 650 * UDP tunnel(xmit) -> veth (segmentation) -> veth (gro) -> UDP tunnel (rx) 651 * 652 * can reach an UDP socket with CHECKSUM_NONE, because 653 * __iptunnel_pull_header() converts CHECKSUM_PARTIAL into NONE. 654 * SKB_GSO_UDP_L4 or SKB_GSO_FRAGLIST packets with no UDP tunnel will 655 * have a valid checksum, as the GRO engine validates the UDP csum 656 * before the aggregation and nobody strips such info in between. 657 * Instead of adding another check in the tunnel fastpath, we can force 658 * a valid csum after the segmentation. 659 * Additionally fixup the UDP CB. 660 */ 661 UDP_SKB_CB(skb)->cscov = skb->len; 662 if (skb->ip_summed == CHECKSUM_NONE && !skb->csum_valid) 663 skb->csum_valid = 1; 664 } 665 666 #ifdef CONFIG_BPF_SYSCALL 667 struct sk_psock; 668 int udp_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore); 669 #endif 670 671 #endif /* _UDP_H */ 672