Merge remote-tracking branch 'iommu/next'
[deliverable/linux.git] / include / net / netfilter / nf_tables_ipv6.h
CommitLineData
0ca743a5
PNA
1#ifndef _NF_TABLES_IPV6_H_
2#define _NF_TABLES_IPV6_H_
3
4#include <linux/netfilter_ipv6/ip6_tables.h>
5#include <net/ipv6.h>
6
71212c9b 7static inline void
0ca743a5 8nft_set_pktinfo_ipv6(struct nft_pktinfo *pkt,
0ca743a5 9 struct sk_buff *skb,
073bfd56 10 const struct nf_hook_state *state)
0ca743a5
PNA
11{
12 int protohdr, thoff = 0;
13 unsigned short frag_off;
14
6aa187f2 15 nft_set_pktinfo(pkt, skb, state);
0ca743a5
PNA
16
17 protohdr = ipv6_find_hdr(pkt->skb, &thoff, -1, &frag_off, NULL);
8df9e32e
PNA
18 if (protohdr < 0) {
19 nft_set_pktinfo_proto_unspec(pkt, skb);
71212c9b 20 return;
8df9e32e 21 }
0ca743a5 22
beac5afa 23 pkt->tprot_set = true;
4566bf27 24 pkt->tprot = protohdr;
0ca743a5
PNA
25 pkt->xt.thoff = thoff;
26 pkt->xt.fragoff = frag_off;
0ca743a5
PNA
27}
28
ddc8b602
PNA
29static inline int
30__nft_set_pktinfo_ipv6_validate(struct nft_pktinfo *pkt,
31 struct sk_buff *skb,
32 const struct nf_hook_state *state)
33{
34#if IS_ENABLED(CONFIG_IPV6)
35 struct ipv6hdr *ip6h, _ip6h;
36 unsigned int thoff = 0;
37 unsigned short frag_off;
38 int protohdr;
39 u32 pkt_len;
40
41 ip6h = skb_header_pointer(skb, skb_network_offset(skb), sizeof(*ip6h),
42 &_ip6h);
43 if (!ip6h)
44 return -1;
45
46 if (ip6h->version != 6)
47 return -1;
48
49 pkt_len = ntohs(ip6h->payload_len);
50 if (pkt_len + sizeof(*ip6h) > skb->len)
51 return -1;
52
53 protohdr = ipv6_find_hdr(pkt->skb, &thoff, -1, &frag_off, NULL);
54 if (protohdr < 0)
55 return -1;
56
57 pkt->tprot_set = true;
58 pkt->tprot = protohdr;
59 pkt->xt.thoff = thoff;
60 pkt->xt.fragoff = frag_off;
61
62 return 0;
63#else
64 return -1;
65#endif
66}
67
68static inline void
69nft_set_pktinfo_ipv6_validate(struct nft_pktinfo *pkt,
70 struct sk_buff *skb,
71 const struct nf_hook_state *state)
72{
73 nft_set_pktinfo(pkt, skb, state);
74 if (__nft_set_pktinfo_ipv6_validate(pkt, skb, state) < 0)
75 nft_set_pktinfo_proto_unspec(pkt, skb);
76}
77
1d49144c
PM
78extern struct nft_af_info nft_af_ipv6;
79
0ca743a5 80#endif
This page took 0.173583 seconds and 5 git commands to generate.