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

net: add a couple of helpers for iph tot_len

This patch adds three APIs to replace the iph->tot_len setting
and getting in all places where IPv4 BIG TCP packets may reach,
they will be used in the following patches.

Note that iph_totlen() will be used when iph is not in linear
data of the skb.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Xin Long and committed by
Jakub Kicinski
058a8f7f d8673afb

+21 -3
+21
include/linux/ip.h
··· 35 35 { 36 36 return ntohs(ip_hdr(skb)->tot_len) - skb_network_header_len(skb); 37 37 } 38 + 39 + static inline unsigned int iph_totlen(const struct sk_buff *skb, const struct iphdr *iph) 40 + { 41 + u32 len = ntohs(iph->tot_len); 42 + 43 + return (len || !skb_is_gso(skb) || !skb_is_gso_tcp(skb)) ? 44 + len : skb->len - skb_network_offset(skb); 45 + } 46 + 47 + static inline unsigned int skb_ip_totlen(const struct sk_buff *skb) 48 + { 49 + return iph_totlen(skb, ip_hdr(skb)); 50 + } 51 + 52 + /* IPv4 datagram length is stored into 16bit field (tot_len) */ 53 + #define IP_MAX_MTU 0xFFFFU 54 + 55 + static inline void iph_set_totlen(struct iphdr *iph, unsigned int len) 56 + { 57 + iph->tot_len = len <= IP_MAX_MTU ? htons(len) : 0; 58 + } 38 59 #endif /* _LINUX_IP_H */
-3
include/net/route.h
··· 35 35 #include <linux/cache.h> 36 36 #include <linux/security.h> 37 37 38 - /* IPv4 datagram length is stored into 16bit field (tot_len) */ 39 - #define IP_MAX_MTU 0xFFFFU 40 - 41 38 #define RTO_ONLINK 0x01 42 39 43 40 #define RT_CONN_FLAGS(sk) (RT_TOS(inet_sk(sk)->tos) | sock_flag(sk, SOCK_LOCALROUTE))