]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/net/netfilter/nf_tables_ipv4.h
ipv6: constify rt6_nexthop()
[mirror_ubuntu-bionic-kernel.git] / include / net / netfilter / nf_tables_ipv4.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _NF_TABLES_IPV4_H_
3 #define _NF_TABLES_IPV4_H_
4
5 #include <net/netfilter/nf_tables.h>
6 #include <net/ip.h>
7
8 static inline void
9 nft_set_pktinfo_ipv4(struct nft_pktinfo *pkt,
10 struct sk_buff *skb,
11 const struct nf_hook_state *state)
12 {
13 struct iphdr *ip;
14
15 nft_set_pktinfo(pkt, skb, state);
16
17 ip = ip_hdr(pkt->skb);
18 pkt->tprot_set = true;
19 pkt->tprot = ip->protocol;
20 pkt->xt.thoff = ip_hdrlen(pkt->skb);
21 pkt->xt.fragoff = ntohs(ip->frag_off) & IP_OFFSET;
22 }
23
24 static inline int
25 __nft_set_pktinfo_ipv4_validate(struct nft_pktinfo *pkt,
26 struct sk_buff *skb,
27 const struct nf_hook_state *state)
28 {
29 struct iphdr *iph, _iph;
30 u32 len, thoff;
31
32 iph = skb_header_pointer(skb, skb_network_offset(skb), sizeof(*iph),
33 &_iph);
34 if (!iph)
35 return -1;
36
37 if (iph->ihl < 5 || iph->version != 4)
38 return -1;
39
40 len = ntohs(iph->tot_len);
41 thoff = iph->ihl * 4;
42 if (skb->len < len)
43 return -1;
44 else if (len < thoff)
45 return -1;
46
47 pkt->tprot_set = true;
48 pkt->tprot = iph->protocol;
49 pkt->xt.thoff = thoff;
50 pkt->xt.fragoff = ntohs(iph->frag_off) & IP_OFFSET;
51
52 return 0;
53 }
54
55 static inline void
56 nft_set_pktinfo_ipv4_validate(struct nft_pktinfo *pkt,
57 struct sk_buff *skb,
58 const struct nf_hook_state *state)
59 {
60 nft_set_pktinfo(pkt, skb, state);
61 if (__nft_set_pktinfo_ipv4_validate(pkt, skb, state) < 0)
62 nft_set_pktinfo_proto_unspec(pkt, skb);
63 }
64
65 extern struct nft_af_info nft_af_ipv4;
66
67 #endif