]> bbs.cooldavid.org Git - net-next-2.6.git/blame - net/ipv4/netfilter/ipt_ah.c
netfilter: xtables: move extension arguments into compound structure (1/6)
[net-next-2.6.git] / net / ipv4 / netfilter / ipt_ah.c
CommitLineData
1da177e4
LT
1/* Kernel module to match AH parameters. */
2/* (C) 1999-2000 Yon Uriarte <yon@astaro.de>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
6709dbbb 9#include <linux/in.h>
1da177e4
LT
10#include <linux/module.h>
11#include <linux/skbuff.h>
12#include <linux/ip.h>
13
14#include <linux/netfilter_ipv4/ipt_ah.h>
6709dbbb 15#include <linux/netfilter/x_tables.h>
1da177e4
LT
16
17MODULE_LICENSE("GPL");
18MODULE_AUTHOR("Yon Uriarte <yon@astaro.de>");
2ae15b64 19MODULE_DESCRIPTION("Xtables: IPv4 IPsec-AH SPI match");
1da177e4
LT
20
21#ifdef DEBUG_CONNTRACK
22#define duprintf(format, args...) printk(format , ## args)
23#else
24#define duprintf(format, args...)
25#endif
26
27/* Returns 1 if the spi is matched by the range, 0 otherwise */
1d93a9cb
JE
28static inline bool
29spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, bool invert)
1da177e4 30{
1d93a9cb 31 bool r;
e905a9ed
YH
32 duprintf("ah spi_match:%c 0x%x <= 0x%x <= 0x%x",invert? '!':' ',
33 min,spi,max);
1da177e4
LT
34 r=(spi >= min && spi <= max) ^ invert;
35 duprintf(" result %s\n",r? "PASS" : "FAILED");
36 return r;
37}
38
f7108a20 39static bool ah_mt(const struct sk_buff *skb, const struct xt_match_param *par)
1da177e4 40{
a47362a2
JE
41 struct ip_auth_hdr _ahdr;
42 const struct ip_auth_hdr *ah;
f7108a20 43 const struct ipt_ah *ahinfo = par->matchinfo;
1da177e4
LT
44
45 /* Must not be a fragment. */
f7108a20 46 if (par->fragoff != 0)
1d93a9cb 47 return false;
1da177e4 48
f7108a20 49 ah = skb_header_pointer(skb, par->thoff, sizeof(_ahdr), &_ahdr);
1da177e4
LT
50 if (ah == NULL) {
51 /* We've been asked to examine this packet, and we
52 * can't. Hence, no choice but to drop.
53 */
54 duprintf("Dropping evil AH tinygram.\n");
f7108a20 55 *par->hotdrop = true;
1da177e4
LT
56 return 0;
57 }
58
59 return spi_match(ahinfo->spis[0], ahinfo->spis[1],
60 ntohl(ah->spi),
61 !!(ahinfo->invflags & IPT_AH_INV_SPI));
62}
63
64/* Called when user tries to insert an entry of this type. */
ccb79bdc 65static bool
d3c5ee6d
JE
66ah_mt_check(const char *tablename, const void *ip_void,
67 const struct xt_match *match, void *matchinfo,
68 unsigned int hook_mask)
1da177e4
LT
69{
70 const struct ipt_ah *ahinfo = matchinfo;
71
1d5cd909 72 /* Must specify no unknown invflags */
1da177e4 73 if (ahinfo->invflags & ~IPT_AH_INV_MASK) {
1d5cd909 74 duprintf("ipt_ah: unknown flags %X\n", ahinfo->invflags);
ccb79bdc 75 return false;
1da177e4 76 }
ccb79bdc 77 return true;
1da177e4
LT
78}
79
d3c5ee6d 80static struct xt_match ah_mt_reg __read_mostly = {
1da177e4 81 .name = "ah",
ee999d8b 82 .family = NFPROTO_IPV4,
d3c5ee6d 83 .match = ah_mt,
1d5cd909
PM
84 .matchsize = sizeof(struct ipt_ah),
85 .proto = IPPROTO_AH,
d3c5ee6d 86 .checkentry = ah_mt_check,
1da177e4
LT
87 .me = THIS_MODULE,
88};
89
d3c5ee6d 90static int __init ah_mt_init(void)
1da177e4 91{
d3c5ee6d 92 return xt_register_match(&ah_mt_reg);
1da177e4
LT
93}
94
d3c5ee6d 95static void __exit ah_mt_exit(void)
1da177e4 96{
d3c5ee6d 97 xt_unregister_match(&ah_mt_reg);
1da177e4
LT
98}
99
d3c5ee6d
JE
100module_init(ah_mt_init);
101module_exit(ah_mt_exit);