[NETFILTER]: Rename init functions.
[linux-2.6.22.y-op.git] / net / ipv6 / netfilter / ip6t_ah.c
blob2f7bb20c758b6b32a74ed027cf0a6f5707ab609a
1 /* Kernel module to match AH parameters. */
3 /* (C) 2001-2002 Andras Kis-Szabo <kisza@sch.bme.hu>
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 */
10 #include <linux/module.h>
11 #include <linux/skbuff.h>
12 #include <linux/ip.h>
13 #include <linux/ipv6.h>
14 #include <linux/types.h>
15 #include <net/checksum.h>
16 #include <net/ipv6.h>
18 #include <linux/netfilter_ipv6/ip6_tables.h>
19 #include <linux/netfilter_ipv6/ip6t_ah.h>
21 MODULE_LICENSE("GPL");
22 MODULE_DESCRIPTION("IPv6 AH match");
23 MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
25 #if 0
26 #define DEBUGP printk
27 #else
28 #define DEBUGP(format, args...)
29 #endif
31 /* Returns 1 if the spi is matched by the range, 0 otherwise */
32 static inline int
33 spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, int invert)
35 int r=0;
36 DEBUGP("ah spi_match:%c 0x%x <= 0x%x <= 0x%x",invert? '!':' ',
37 min,spi,max);
38 r = (spi >= min && spi <= max) ^ invert;
39 DEBUGP(" result %s\n",r? "PASS\n" : "FAILED\n");
40 return r;
43 static int
44 match(const struct sk_buff *skb,
45 const struct net_device *in,
46 const struct net_device *out,
47 const struct xt_match *match,
48 const void *matchinfo,
49 int offset,
50 unsigned int protoff,
51 int *hotdrop)
53 struct ip_auth_hdr *ah, _ah;
54 const struct ip6t_ah *ahinfo = matchinfo;
55 unsigned int ptr;
56 unsigned int hdrlen = 0;
58 if (ipv6_find_hdr(skb, &ptr, NEXTHDR_AUTH, NULL) < 0)
59 return 0;
61 ah = skb_header_pointer(skb, ptr, sizeof(_ah), &_ah);
62 if (ah == NULL) {
63 *hotdrop = 1;
64 return 0;
67 hdrlen = (ah->hdrlen + 2) << 2;
69 DEBUGP("IPv6 AH LEN %u %u ", hdrlen, ah->hdrlen);
70 DEBUGP("RES %04X ", ah->reserved);
71 DEBUGP("SPI %u %08X\n", ntohl(ah->spi), ntohl(ah->spi));
73 DEBUGP("IPv6 AH spi %02X ",
74 (spi_match(ahinfo->spis[0], ahinfo->spis[1],
75 ntohl(ah->spi),
76 !!(ahinfo->invflags & IP6T_AH_INV_SPI))));
77 DEBUGP("len %02X %04X %02X ",
78 ahinfo->hdrlen, hdrlen,
79 (!ahinfo->hdrlen ||
80 (ahinfo->hdrlen == hdrlen) ^
81 !!(ahinfo->invflags & IP6T_AH_INV_LEN)));
82 DEBUGP("res %02X %04X %02X\n",
83 ahinfo->hdrres, ah->reserved,
84 !(ahinfo->hdrres && ah->reserved));
86 return (ah != NULL)
88 (spi_match(ahinfo->spis[0], ahinfo->spis[1],
89 ntohl(ah->spi),
90 !!(ahinfo->invflags & IP6T_AH_INV_SPI)))
92 (!ahinfo->hdrlen ||
93 (ahinfo->hdrlen == hdrlen) ^
94 !!(ahinfo->invflags & IP6T_AH_INV_LEN))
96 !(ahinfo->hdrres && ah->reserved);
99 /* Called when user tries to insert an entry of this type. */
100 static int
101 checkentry(const char *tablename,
102 const void *entry,
103 const struct xt_match *match,
104 void *matchinfo,
105 unsigned int matchinfosize,
106 unsigned int hook_mask)
108 const struct ip6t_ah *ahinfo = matchinfo;
110 if (ahinfo->invflags & ~IP6T_AH_INV_MASK) {
111 DEBUGP("ip6t_ah: unknown flags %X\n", ahinfo->invflags);
112 return 0;
114 return 1;
117 static struct ip6t_match ah_match = {
118 .name = "ah",
119 .match = match,
120 .matchsize = sizeof(struct ip6t_ah),
121 .checkentry = checkentry,
122 .me = THIS_MODULE,
125 static int __init ip6t_ah_init(void)
127 return ip6t_register_match(&ah_match);
130 static void __exit ip6t_ah_fini(void)
132 ip6t_unregister_match(&ah_match);
135 module_init(ip6t_ah_init);
136 module_exit(ip6t_ah_fini);