0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef _LINUX_UDP_H
0014 #define _LINUX_UDP_H
0015
0016 #include <net/inet_sock.h>
0017 #include <linux/skbuff.h>
0018 #include <net/netns/hash.h>
0019 #include <uapi/linux/udp.h>
0020
0021 static inline struct udphdr *udp_hdr(const struct sk_buff *skb)
0022 {
0023 return (struct udphdr *)skb_transport_header(skb);
0024 }
0025
0026 #define UDP_HTABLE_SIZE_MIN (CONFIG_BASE_SMALL ? 128 : 256)
0027
0028 static inline u32 udp_hashfn(const struct net *net, u32 num, u32 mask)
0029 {
0030 return (num + net_hash_mix(net)) & mask;
0031 }
0032
0033 struct udp_sock {
0034
0035 struct inet_sock inet;
0036 #define udp_port_hash inet.sk.__sk_common.skc_u16hashes[0]
0037 #define udp_portaddr_hash inet.sk.__sk_common.skc_u16hashes[1]
0038 #define udp_portaddr_node inet.sk.__sk_common.skc_portaddr_node
0039 int pending;
0040 unsigned int corkflag;
0041 __u8 encap_type;
0042 unsigned char no_check6_tx:1,
0043 no_check6_rx:1,
0044 encap_enabled:1,
0045
0046
0047
0048
0049 gro_enabled:1,
0050 accept_udp_l4:1,
0051 accept_udp_fraglist:1;
0052
0053
0054
0055
0056 __u16 len;
0057 __u16 gso_size;
0058
0059
0060
0061 __u16 pcslen;
0062 __u16 pcrlen;
0063
0064 #define UDPLITE_BIT 0x1
0065 #define UDPLITE_SEND_CC 0x2
0066 #define UDPLITE_RECV_CC 0x4
0067 __u8 pcflag;
0068 __u8 unused[3];
0069
0070
0071
0072 int (*encap_rcv)(struct sock *sk, struct sk_buff *skb);
0073 void (*encap_err_rcv)(struct sock *sk, struct sk_buff *skb, unsigned int udp_offset);
0074 int (*encap_err_lookup)(struct sock *sk, struct sk_buff *skb);
0075 void (*encap_destroy)(struct sock *sk);
0076
0077
0078 struct sk_buff * (*gro_receive)(struct sock *sk,
0079 struct list_head *head,
0080 struct sk_buff *skb);
0081 int (*gro_complete)(struct sock *sk,
0082 struct sk_buff *skb,
0083 int nhoff);
0084
0085
0086 struct sk_buff_head reader_queue ____cacheline_aligned_in_smp;
0087
0088
0089 int forward_deficit;
0090 };
0091
0092 #define UDP_MAX_SEGMENTS (1 << 6UL)
0093
0094 static inline struct udp_sock *udp_sk(const struct sock *sk)
0095 {
0096 return (struct udp_sock *)sk;
0097 }
0098
0099 static inline void udp_set_no_check6_tx(struct sock *sk, bool val)
0100 {
0101 udp_sk(sk)->no_check6_tx = val;
0102 }
0103
0104 static inline void udp_set_no_check6_rx(struct sock *sk, bool val)
0105 {
0106 udp_sk(sk)->no_check6_rx = val;
0107 }
0108
0109 static inline bool udp_get_no_check6_tx(struct sock *sk)
0110 {
0111 return udp_sk(sk)->no_check6_tx;
0112 }
0113
0114 static inline bool udp_get_no_check6_rx(struct sock *sk)
0115 {
0116 return udp_sk(sk)->no_check6_rx;
0117 }
0118
0119 static inline void udp_cmsg_recv(struct msghdr *msg, struct sock *sk,
0120 struct sk_buff *skb)
0121 {
0122 int gso_size;
0123
0124 if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4) {
0125 gso_size = skb_shinfo(skb)->gso_size;
0126 put_cmsg(msg, SOL_UDP, UDP_GRO, sizeof(gso_size), &gso_size);
0127 }
0128 }
0129
0130 static inline bool udp_unexpected_gso(struct sock *sk, struct sk_buff *skb)
0131 {
0132 if (!skb_is_gso(skb))
0133 return false;
0134
0135 if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4 && !udp_sk(sk)->accept_udp_l4)
0136 return true;
0137
0138 if (skb_shinfo(skb)->gso_type & SKB_GSO_FRAGLIST && !udp_sk(sk)->accept_udp_fraglist)
0139 return true;
0140
0141 return false;
0142 }
0143
0144 static inline void udp_allow_gso(struct sock *sk)
0145 {
0146 udp_sk(sk)->accept_udp_l4 = 1;
0147 udp_sk(sk)->accept_udp_fraglist = 1;
0148 }
0149
0150 #define udp_portaddr_for_each_entry(__sk, list) \
0151 hlist_for_each_entry(__sk, list, __sk_common.skc_portaddr_node)
0152
0153 #define udp_portaddr_for_each_entry_rcu(__sk, list) \
0154 hlist_for_each_entry_rcu(__sk, list, __sk_common.skc_portaddr_node)
0155
0156 #define IS_UDPLITE(__sk) (__sk->sk_protocol == IPPROTO_UDPLITE)
0157
0158 #endif