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.
10 #include <linux/module.h>
11 #include <linux/skbuff.h>
14 #include <linux/netfilter_ipv4/ipt_ah.h>
15 #include <linux/netfilter/x_tables.h>
17 MODULE_LICENSE("GPL");
18 MODULE_AUTHOR("Yon Uriarte <yon@astaro.de>");
19 MODULE_DESCRIPTION("iptables AH SPI match module");
21 #ifdef DEBUG_CONNTRACK
22 #define duprintf(format, args...) printk(format , ## args)
24 #define duprintf(format, args...)
27 /* Returns 1 if the spi is matched by the range, 0 otherwise */
29 spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, bool invert)
32 duprintf("ah spi_match:%c 0x%x <= 0x%x <= 0x%x",invert? '!':' ',
34 r=(spi >= min && spi <= max) ^ invert;
35 duprintf(" result %s\n",r? "PASS" : "FAILED");
40 match(const struct sk_buff *skb,
41 const struct net_device *in,
42 const struct net_device *out,
43 const struct xt_match *match,
44 const void *matchinfo,
49 struct ip_auth_hdr _ahdr;
50 const struct ip_auth_hdr *ah;
51 const struct ipt_ah *ahinfo = matchinfo;
53 /* Must not be a fragment. */
57 ah = skb_header_pointer(skb, protoff,
58 sizeof(_ahdr), &_ahdr);
60 /* We've been asked to examine this packet, and we
61 * can't. Hence, no choice but to drop.
63 duprintf("Dropping evil AH tinygram.\n");
68 return spi_match(ahinfo->spis[0], ahinfo->spis[1],
70 !!(ahinfo->invflags & IPT_AH_INV_SPI));
73 /* Called when user tries to insert an entry of this type. */
75 checkentry(const char *tablename,
77 const struct xt_match *match,
79 unsigned int hook_mask)
81 const struct ipt_ah *ahinfo = matchinfo;
83 /* Must specify no unknown invflags */
84 if (ahinfo->invflags & ~IPT_AH_INV_MASK) {
85 duprintf("ipt_ah: unknown flags %X\n", ahinfo->invflags);
91 static struct xt_match ah_match __read_mostly = {
95 .matchsize = sizeof(struct ipt_ah),
97 .checkentry = checkentry,
101 static int __init ipt_ah_init(void)
103 return xt_register_match(&ah_match);
106 static void __exit ipt_ah_fini(void)
108 xt_unregister_match(&ah_match);
111 module_init(ipt_ah_init);
112 module_exit(ipt_ah_fini);