12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * INET An implementation of the TCP/IP protocol suite for the LINUX 41da177e4SLinus Torvalds * operating system. INET is implemented using the BSD Socket 51da177e4SLinus Torvalds * interface as the means of communication with the user level. 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * Definitions for the IP protocol. 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * Version: @(#)ip.h 1.0.2 04/28/93 101da177e4SLinus Torvalds * 111da177e4SLinus Torvalds * Authors: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> 121da177e4SLinus Torvalds */ 131da177e4SLinus Torvalds #ifndef _LINUX_IP_H 141da177e4SLinus Torvalds #define _LINUX_IP_H 151da177e4SLinus Torvalds 16eddc9ec5SArnaldo Carvalho de Melo #include <linux/skbuff.h> 17607ca46eSDavid Howells #include <uapi/linux/ip.h> 18eddc9ec5SArnaldo Carvalho de Melo ip_hdr(const struct sk_buff * skb)19eddc9ec5SArnaldo Carvalho de Melostatic inline struct iphdr *ip_hdr(const struct sk_buff *skb) 20eddc9ec5SArnaldo Carvalho de Melo { 21eddc9ec5SArnaldo Carvalho de Melo return (struct iphdr *)skb_network_header(skb); 22eddc9ec5SArnaldo Carvalho de Melo } 23b0061ce4SArnaldo Carvalho de Melo inner_ip_hdr(const struct sk_buff * skb)246a674e9cSJoseph Gasparakisstatic inline struct iphdr *inner_ip_hdr(const struct sk_buff *skb) 256a674e9cSJoseph Gasparakis { 266a674e9cSJoseph Gasparakis return (struct iphdr *)skb_inner_network_header(skb); 276a674e9cSJoseph Gasparakis } 286a674e9cSJoseph Gasparakis ipip_hdr(const struct sk_buff * skb)29b0061ce4SArnaldo Carvalho de Melostatic inline struct iphdr *ipip_hdr(const struct sk_buff *skb) 30b0061ce4SArnaldo Carvalho de Melo { 319c70220bSArnaldo Carvalho de Melo return (struct iphdr *)skb_transport_header(skb); 32b0061ce4SArnaldo Carvalho de Melo } 33ba5ea614SLinus Lüssing ip_transport_len(const struct sk_buff * skb)34ba5ea614SLinus Lüssingstatic inline unsigned int ip_transport_len(const struct sk_buff *skb) 35ba5ea614SLinus Lüssing { 36ba5ea614SLinus Lüssing return ntohs(ip_hdr(skb)->tot_len) - skb_network_header_len(skb); 37ba5ea614SLinus Lüssing } 38*058a8f7fSXin Long iph_totlen(const struct sk_buff * skb,const struct iphdr * iph)39*058a8f7fSXin Longstatic inline unsigned int iph_totlen(const struct sk_buff *skb, const struct iphdr *iph) 40*058a8f7fSXin Long { 41*058a8f7fSXin Long u32 len = ntohs(iph->tot_len); 42*058a8f7fSXin Long 43*058a8f7fSXin Long return (len || !skb_is_gso(skb) || !skb_is_gso_tcp(skb)) ? 44*058a8f7fSXin Long len : skb->len - skb_network_offset(skb); 45*058a8f7fSXin Long } 46*058a8f7fSXin Long skb_ip_totlen(const struct sk_buff * skb)47*058a8f7fSXin Longstatic inline unsigned int skb_ip_totlen(const struct sk_buff *skb) 48*058a8f7fSXin Long { 49*058a8f7fSXin Long return iph_totlen(skb, ip_hdr(skb)); 50*058a8f7fSXin Long } 51*058a8f7fSXin Long 52*058a8f7fSXin Long /* IPv4 datagram length is stored into 16bit field (tot_len) */ 53*058a8f7fSXin Long #define IP_MAX_MTU 0xFFFFU 54*058a8f7fSXin Long iph_set_totlen(struct iphdr * iph,unsigned int len)55*058a8f7fSXin Longstatic inline void iph_set_totlen(struct iphdr *iph, unsigned int len) 56*058a8f7fSXin Long { 57*058a8f7fSXin Long iph->tot_len = len <= IP_MAX_MTU ? htons(len) : 0; 58*058a8f7fSXin Long } 591da177e4SLinus Torvalds #endif /* _LINUX_IP_H */ 60