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>
14 #include <linux/netfilter_ipv4/ipt_esp.h>
15 #include <linux/netfilter_ipv4/ip_tables.h>
17 MODULE_LICENSE("GPL");
18 MODULE_AUTHOR("Yon Uriarte <yon@astaro.de>");
19 MODULE_DESCRIPTION("iptables ESP 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, int invert)
32 duprintf("esp 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 void *matchinfo,
47 struct ip_esp_hdr esp;
48 const struct ipt_esp *espinfo = matchinfo;
50 /* Must not be a fragment. */
54 if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &esp, sizeof(esp)) < 0) {
55 /* We've been asked to examine this packet, and we
56 can't. Hence, no choice but to drop. */
57 duprintf("Dropping evil ESP tinygram.\n");
62 return spi_match(espinfo->spis[0], espinfo->spis[1],
64 !!(espinfo->invflags & IPT_ESP_INV_SPI));
67 /* Called when user tries to insert an entry of this type. */
69 checkentry(const char *tablename,
70 const struct ipt_ip *ip,
72 unsigned int matchinfosize,
73 unsigned int hook_mask)
75 const struct ipt_esp *espinfo = matchinfo;
77 /* Must specify proto == ESP, and no unknown invflags */
78 if (ip->proto != IPPROTO_ESP || (ip->invflags & IPT_INV_PROTO)) {
79 duprintf("ipt_esp: Protocol %u != %u\n", ip->proto,
83 if (matchinfosize != IPT_ALIGN(sizeof(struct ipt_esp))) {
84 duprintf("ipt_esp: matchsize %u != %u\n",
85 matchinfosize, IPT_ALIGN(sizeof(struct ipt_esp)));
88 if (espinfo->invflags & ~IPT_ESP_INV_MASK) {
89 duprintf("ipt_esp: unknown flags %X\n",
97 static struct ipt_match esp_match = {
100 .checkentry = &checkentry,
104 static int __init init(void)
106 return ipt_register_match(&esp_match);
109 static void __exit cleanup(void)
111 ipt_unregister_match(&esp_match);
115 module_exit(cleanup);