[NETFILTER]: Remove incorrect inline markers
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / net / ipv6 / netfilter / ip6t_ah.c
CommitLineData
1da177e4
LT
1/* Kernel module to match AH parameters. */
2
3/* (C) 2001-2002 Andras Kis-Szabo <kisza@sch.bme.hu>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/module.h>
11#include <linux/skbuff.h>
14c85021 12#include <linux/ip.h>
1da177e4
LT
13#include <linux/ipv6.h>
14#include <linux/types.h>
15#include <net/checksum.h>
16#include <net/ipv6.h>
17
6709dbbb 18#include <linux/netfilter/x_tables.h>
1da177e4
LT
19#include <linux/netfilter_ipv6/ip6_tables.h>
20#include <linux/netfilter_ipv6/ip6t_ah.h>
21
22MODULE_LICENSE("GPL");
23MODULE_DESCRIPTION("IPv6 AH match");
24MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
25
26#if 0
27#define DEBUGP printk
28#else
29#define DEBUGP(format, args...)
30#endif
31
32/* Returns 1 if the spi is matched by the range, 0 otherwise */
1d93a9cb
JE
33static inline bool
34spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, bool invert)
1da177e4 35{
1d93a9cb 36 bool r;
1da177e4
LT
37 DEBUGP("ah spi_match:%c 0x%x <= 0x%x <= 0x%x",invert? '!':' ',
38 min,spi,max);
39 r = (spi >= min && spi <= max) ^ invert;
40 DEBUGP(" result %s\n",r? "PASS\n" : "FAILED\n");
41 return r;
42}
43
1d93a9cb 44static bool
1da177e4
LT
45match(const struct sk_buff *skb,
46 const struct net_device *in,
47 const struct net_device *out,
c4986734 48 const struct xt_match *match,
1da177e4
LT
49 const void *matchinfo,
50 int offset,
51 unsigned int protoff,
cff533ac 52 bool *hotdrop)
1da177e4 53{
a47362a2
JE
54 struct ip_auth_hdr _ah;
55 const struct ip_auth_hdr *ah;
1da177e4 56 const struct ip6t_ah *ahinfo = matchinfo;
1da177e4
LT
57 unsigned int ptr;
58 unsigned int hdrlen = 0;
6d381634 59 int err;
1da177e4 60
6d381634
PM
61 err = ipv6_find_hdr(skb, &ptr, NEXTHDR_AUTH, NULL);
62 if (err < 0) {
63 if (err != -ENOENT)
cff533ac 64 *hotdrop = true;
1d93a9cb 65 return false;
6d381634 66 }
1da177e4 67
e674d0f3
YK
68 ah = skb_header_pointer(skb, ptr, sizeof(_ah), &_ah);
69 if (ah == NULL) {
cff533ac 70 *hotdrop = true;
1d93a9cb 71 return false;
1da177e4
LT
72 }
73
e674d0f3 74 hdrlen = (ah->hdrlen + 2) << 2;
1da177e4
LT
75
76 DEBUGP("IPv6 AH LEN %u %u ", hdrlen, ah->hdrlen);
77 DEBUGP("RES %04X ", ah->reserved);
78 DEBUGP("SPI %u %08X\n", ntohl(ah->spi), ntohl(ah->spi));
79
80 DEBUGP("IPv6 AH spi %02X ",
81 (spi_match(ahinfo->spis[0], ahinfo->spis[1],
1ab1457c
YH
82 ntohl(ah->spi),
83 !!(ahinfo->invflags & IP6T_AH_INV_SPI))));
1da177e4
LT
84 DEBUGP("len %02X %04X %02X ",
85 ahinfo->hdrlen, hdrlen,
86 (!ahinfo->hdrlen ||
1ab1457c
YH
87 (ahinfo->hdrlen == hdrlen) ^
88 !!(ahinfo->invflags & IP6T_AH_INV_LEN)));
1da177e4
LT
89 DEBUGP("res %02X %04X %02X\n",
90 ahinfo->hdrres, ah->reserved,
91 !(ahinfo->hdrres && ah->reserved));
92
93 return (ah != NULL)
94 &&
95 (spi_match(ahinfo->spis[0], ahinfo->spis[1],
1ab1457c
YH
96 ntohl(ah->spi),
97 !!(ahinfo->invflags & IP6T_AH_INV_SPI)))
1da177e4
LT
98 &&
99 (!ahinfo->hdrlen ||
1ab1457c
YH
100 (ahinfo->hdrlen == hdrlen) ^
101 !!(ahinfo->invflags & IP6T_AH_INV_LEN))
1da177e4
LT
102 &&
103 !(ahinfo->hdrres && ah->reserved);
104}
105
106/* Called when user tries to insert an entry of this type. */
ccb79bdc 107static bool
1da177e4 108checkentry(const char *tablename,
1ab1457c 109 const void *entry,
c4986734 110 const struct xt_match *match,
1ab1457c
YH
111 void *matchinfo,
112 unsigned int hook_mask)
1da177e4
LT
113{
114 const struct ip6t_ah *ahinfo = matchinfo;
115
1da177e4
LT
116 if (ahinfo->invflags & ~IP6T_AH_INV_MASK) {
117 DEBUGP("ip6t_ah: unknown flags %X\n", ahinfo->invflags);
ccb79bdc 118 return false;
1da177e4 119 }
ccb79bdc 120 return true;
1da177e4
LT
121}
122
6709dbbb 123static struct xt_match ah_match = {
1da177e4 124 .name = "ah",
6709dbbb 125 .family = AF_INET6,
7f939713
PM
126 .match = match,
127 .matchsize = sizeof(struct ip6t_ah),
128 .checkentry = checkentry,
1da177e4
LT
129 .me = THIS_MODULE,
130};
131
65b4b4e8 132static int __init ip6t_ah_init(void)
1da177e4 133{
6709dbbb 134 return xt_register_match(&ah_match);
1da177e4
LT
135}
136
65b4b4e8 137static void __exit ip6t_ah_fini(void)
1da177e4 138{
6709dbbb 139 xt_unregister_match(&ah_match);
1da177e4
LT
140}
141
65b4b4e8
AM
142module_init(ip6t_ah_init);
143module_exit(ip6t_ah_fini);