udplite.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #include <net/ip6_checksum.h>
  8. #include <net/udp.h>
  9. /* UDP-Lite socket options */
  10. #define UDPLITE_SEND_CSCOV 10 /* sender partial coverage (as sent) */
  11. #define UDPLITE_RECV_CSCOV 11 /* receiver partial coverage (threshold ) */
  12. extern struct proto udplite_prot;
  13. extern struct udp_table udplite_table;
  14. /*
  15. * Checksum computation is all in software, hence simpler getfrag.
  16. */
  17. static __inline__ int udplite_getfrag(void *from, char *to, int offset,
  18. int len, int odd, struct sk_buff *skb)
  19. {
  20. struct msghdr *msg = from;
  21. return copy_from_iter_full(to, len, &msg->msg_iter) ? 0 : -EFAULT;
  22. }
  23. /*
  24. * Checksumming routines
  25. */
  26. static inline int udplite_checksum_init(struct sk_buff *skb, struct udphdr *uh)
  27. {
  28. u16 cscov;
  29. /* In UDPv4 a zero checksum means that the transmitter generated no
  30. * checksum. UDP-Lite (like IPv6) mandates checksums, hence packets
  31. * with a zero checksum field are illegal. */
  32. if (uh->check == 0) {
  33. net_dbg_ratelimited("UDPLite: zeroed checksum field\n");
  34. return 1;
  35. }
  36. cscov = ntohs(uh->len);
  37. if (cscov == 0) /* Indicates that full coverage is required. */
  38. ;
  39. else if (cscov < 8 || cscov > skb->len) {
  40. /*
  41. * Coverage length violates RFC 3828: log and discard silently.
  42. */
  43. net_dbg_ratelimited("UDPLite: bad csum coverage %d/%d\n",
  44. cscov, skb->len);
  45. return 1;
  46. } else if (cscov < skb->len) {
  47. UDP_SKB_CB(skb)->partial_cov = 1;
  48. UDP_SKB_CB(skb)->cscov = cscov;
  49. if (skb->ip_summed == CHECKSUM_COMPLETE)
  50. skb->ip_summed = CHECKSUM_NONE;
  51. skb->csum_valid = 0;
  52. }
  53. return 0;
  54. }
  55. /* Fast-path computation of checksum. Socket may not be locked. */
  56. static inline __wsum udplite_csum(struct sk_buff *skb)
  57. {
  58. const struct udp_sock *up = udp_sk(skb->sk);
  59. const int off = skb_transport_offset(skb);
  60. int len = skb->len - off;
  61. if ((up->pcflag & UDPLITE_SEND_CC) && up->pcslen < len) {
  62. if (0 < up->pcslen)
  63. len = up->pcslen;
  64. udp_hdr(skb)->len = htons(up->pcslen);
  65. }
  66. skb->ip_summed = CHECKSUM_NONE; /* no HW support for checksumming */
  67. return skb_checksum(skb, off, len, 0);
  68. }
  69. void udplite4_register(void);
  70. int udplite_get_port(struct sock *sk, unsigned short snum,
  71. int (*scmp)(const struct sock *, const struct sock *));
  72. #endif /* _UDPLITE_H */