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("Xtables: IPv4 IPsec-AH SPI match");
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");
39 static bool ah_mt(const struct sk_buff
*skb
, const struct xt_match_param
*par
)
41 struct ip_auth_hdr _ahdr
;
42 const struct ip_auth_hdr
*ah
;
43 const struct ipt_ah
*ahinfo
= par
->matchinfo
;
45 /* Must not be a fragment. */
46 if (par
->fragoff
!= 0)
49 ah
= skb_header_pointer(skb
, par
->thoff
, sizeof(_ahdr
), &_ahdr
);
51 /* We've been asked to examine this packet, and we
52 * can't. Hence, no choice but to drop.
54 duprintf("Dropping evil AH tinygram.\n");
59 return spi_match(ahinfo
->spis
[0], ahinfo
->spis
[1],
61 !!(ahinfo
->invflags
& IPT_AH_INV_SPI
));
64 static bool ah_mt_check(const struct xt_mtchk_param
*par
)
66 const struct ipt_ah
*ahinfo
= par
->matchinfo
;
68 /* Must specify no unknown invflags */
69 if (ahinfo
->invflags
& ~IPT_AH_INV_MASK
) {
70 duprintf("ipt_ah: unknown flags %X\n", ahinfo
->invflags
);
76 static struct xt_match ah_mt_reg __read_mostly
= {
78 .family
= NFPROTO_IPV4
,
80 .matchsize
= sizeof(struct ipt_ah
),
82 .checkentry
= ah_mt_check
,
86 static int __init
ah_mt_init(void)
88 return xt_register_match(&ah_mt_reg
);
91 static void __exit
ah_mt_exit(void)
93 xt_unregister_match(&ah_mt_reg
);
96 module_init(ah_mt_init
);
97 module_exit(ah_mt_exit
);