1 /* Kernel module to match ESP parameters. */
3 /* (C) 1999-2000 Yon Uriarte <yon@astaro.de>
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.
10 #include <linux/module.h>
11 #include <linux/skbuff.h>
15 #include <linux/netfilter/xt_esp.h>
16 #include <linux/netfilter/x_tables.h>
18 #include <linux/netfilter_ipv4/ip_tables.h>
19 #include <linux/netfilter_ipv6/ip6_tables.h>
21 MODULE_LICENSE("GPL");
22 MODULE_AUTHOR("Yon Uriarte <yon@astaro.de>");
23 MODULE_DESCRIPTION("x_tables ESP SPI match module");
24 MODULE_ALIAS("ipt_esp");
25 MODULE_ALIAS("ip6t_esp");
28 #define duprintf(format, args...) printk(format , ## args)
30 #define duprintf(format, args...)
33 /* Returns 1 if the spi is matched by the range, 0 otherwise */
35 spi_match(u_int32_t min
, u_int32_t max
, u_int32_t spi
, int invert
)
38 duprintf("esp spi_match:%c 0x%x <= 0x%x <= 0x%x", invert
? '!' : ' ',
40 r
= (spi
>= min
&& spi
<= max
) ^ invert
;
41 duprintf(" result %s\n", r
? "PASS" : "FAILED");
46 match(const struct sk_buff
*skb
,
47 const struct net_device
*in
,
48 const struct net_device
*out
,
49 const struct xt_match
*match
,
50 const void *matchinfo
,
55 struct ip_esp_hdr _esp
, *eh
;
56 const struct xt_esp
*espinfo
= matchinfo
;
58 /* Must not be a fragment. */
62 eh
= skb_header_pointer(skb
, protoff
, sizeof(_esp
), &_esp
);
64 /* We've been asked to examine this packet, and we
65 * can't. Hence, no choice but to drop.
67 duprintf("Dropping evil ESP tinygram.\n");
72 return spi_match(espinfo
->spis
[0], espinfo
->spis
[1], ntohl(eh
->spi
),
73 !!(espinfo
->invflags
& XT_ESP_INV_SPI
));
76 /* Called when user tries to insert an entry of this type. */
78 checkentry(const char *tablename
,
80 const struct xt_match
*match
,
82 unsigned int matchinfosize
,
83 unsigned int hook_mask
)
85 const struct xt_esp
*espinfo
= matchinfo
;
87 if (espinfo
->invflags
& ~XT_ESP_INV_MASK
) {
88 duprintf("xt_esp: unknown flags %X\n", espinfo
->invflags
);
95 static struct xt_match esp_match
= {
100 .matchsize
= sizeof(struct xt_esp
),
101 .checkentry
= &checkentry
,
105 static struct xt_match esp6_match
= {
108 .proto
= IPPROTO_ESP
,
110 .matchsize
= sizeof(struct xt_esp
),
111 .checkentry
= &checkentry
,
115 static int __init
xt_esp_init(void)
118 ret
= xt_register_match(&esp_match
);
122 ret
= xt_register_match(&esp6_match
);
124 xt_unregister_match(&esp_match
);
129 static void __exit
xt_esp_cleanup(void)
131 xt_unregister_match(&esp_match
);
132 xt_unregister_match(&esp6_match
);
135 module_init(xt_esp_init
);
136 module_exit(xt_esp_cleanup
);