[PARISC] fix build for WARN_ON() when CONFIG_DEBUG_BUGVERBOSE=y
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / ipv4 / netfilter / ipt_ah.c
blob1798f86bc534ff68c5b80691262c9535c6d7b206
1 /* Kernel module to match AH parameters. */
2 /* (C) 1999-2000 Yon Uriarte <yon@astaro.de>
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 */
9 #include <linux/module.h>
10 #include <linux/skbuff.h>
11 #include <linux/ip.h>
13 #include <linux/netfilter_ipv4/ipt_ah.h>
14 #include <linux/netfilter_ipv4/ip_tables.h>
16 MODULE_LICENSE("GPL");
17 MODULE_AUTHOR("Yon Uriarte <yon@astaro.de>");
18 MODULE_DESCRIPTION("iptables AH SPI match module");
20 #ifdef DEBUG_CONNTRACK
21 #define duprintf(format, args...) printk(format , ## args)
22 #else
23 #define duprintf(format, args...)
24 #endif
26 /* Returns 1 if the spi is matched by the range, 0 otherwise */
27 static inline int
28 spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, int invert)
30 int r=0;
31 duprintf("ah spi_match:%c 0x%x <= 0x%x <= 0x%x",invert? '!':' ',
32 min,spi,max);
33 r=(spi >= min && spi <= max) ^ invert;
34 duprintf(" result %s\n",r? "PASS" : "FAILED");
35 return r;
38 static int
39 match(const struct sk_buff *skb,
40 const struct net_device *in,
41 const struct net_device *out,
42 const struct xt_match *match,
43 const void *matchinfo,
44 int offset,
45 unsigned int protoff,
46 int *hotdrop)
48 struct ip_auth_hdr _ahdr, *ah;
49 const struct ipt_ah *ahinfo = matchinfo;
51 /* Must not be a fragment. */
52 if (offset)
53 return 0;
55 ah = skb_header_pointer(skb, protoff,
56 sizeof(_ahdr), &_ahdr);
57 if (ah == NULL) {
58 /* We've been asked to examine this packet, and we
59 * can't. Hence, no choice but to drop.
61 duprintf("Dropping evil AH tinygram.\n");
62 *hotdrop = 1;
63 return 0;
66 return spi_match(ahinfo->spis[0], ahinfo->spis[1],
67 ntohl(ah->spi),
68 !!(ahinfo->invflags & IPT_AH_INV_SPI));
71 /* Called when user tries to insert an entry of this type. */
72 static int
73 checkentry(const char *tablename,
74 const void *ip_void,
75 const struct xt_match *match,
76 void *matchinfo,
77 unsigned int hook_mask)
79 const struct ipt_ah *ahinfo = matchinfo;
81 /* Must specify no unknown invflags */
82 if (ahinfo->invflags & ~IPT_AH_INV_MASK) {
83 duprintf("ipt_ah: unknown flags %X\n", ahinfo->invflags);
84 return 0;
86 return 1;
89 static struct ipt_match ah_match = {
90 .name = "ah",
91 .match = match,
92 .matchsize = sizeof(struct ipt_ah),
93 .proto = IPPROTO_AH,
94 .checkentry = checkentry,
95 .me = THIS_MODULE,
98 static int __init ipt_ah_init(void)
100 return ipt_register_match(&ah_match);
103 static void __exit ipt_ah_fini(void)
105 ipt_unregister_match(&ah_match);
108 module_init(ipt_ah_init);
109 module_exit(ipt_ah_fini);