1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _NF_TABLES_IPV4_H_
3 #define _NF_TABLES_IPV4_H_
5 #include <net/netfilter/nf_tables.h>
8 static inline void nft_set_pktinfo_ipv4(struct nft_pktinfo *pkt,
13 ip = ip_hdr(pkt->skb);
14 pkt->tprot_set = true;
15 pkt->tprot = ip->protocol;
16 pkt->xt.thoff = ip_hdrlen(pkt->skb);
17 pkt->xt.fragoff = ntohs(ip->frag_off) & IP_OFFSET;
20 static inline int __nft_set_pktinfo_ipv4_validate(struct nft_pktinfo *pkt,
23 struct iphdr *iph, _iph;
26 iph = skb_header_pointer(skb, skb_network_offset(skb), sizeof(*iph),
31 if (iph->ihl < 5 || iph->version != 4)
34 len = ntohs(iph->tot_len);
41 pkt->tprot_set = true;
42 pkt->tprot = iph->protocol;
43 pkt->xt.thoff = thoff;
44 pkt->xt.fragoff = ntohs(iph->frag_off) & IP_OFFSET;
49 static inline void nft_set_pktinfo_ipv4_validate(struct nft_pktinfo *pkt,
52 if (__nft_set_pktinfo_ipv4_validate(pkt, skb) < 0)
53 nft_set_pktinfo_unspec(pkt, skb);
56 static inline int nft_set_pktinfo_ipv4_ingress(struct nft_pktinfo *pkt,
62 if (!pskb_may_pull(skb, sizeof(*iph)))
66 if (iph->ihl < 5 || iph->version != 4)
69 len = ntohs(iph->tot_len);
72 __IP_INC_STATS(nft_net(pkt), IPSTATS_MIB_INTRUNCATEDPKTS);
74 } else if (len < thoff) {
78 pkt->tprot_set = true;
79 pkt->tprot = iph->protocol;
80 pkt->xt.thoff = thoff;
81 pkt->xt.fragoff = ntohs(iph->frag_off) & IP_OFFSET;
86 __IP_INC_STATS(nft_net(pkt), IPSTATS_MIB_INHDRERRORS);