]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - net/ipv6/netfilter/ip6t_esp.c
Merge branch 'upstream-fixes'
[linux-2.6-omap-h63xx.git] / net / ipv6 / netfilter / ip6t_esp.c
1 /* Kernel module to match ESP parameters. */
2 /* (C) 2001-2002 Andras Kis-Szabo <kisza@sch.bme.hu>
3  *
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  */
8
9
10 #include <linux/module.h>
11 #include <linux/skbuff.h>
12 #include <linux/ipv6.h>
13 #include <linux/types.h>
14 #include <net/checksum.h>
15 #include <net/ipv6.h>
16
17 #include <linux/netfilter_ipv6/ip6_tables.h>
18 #include <linux/netfilter_ipv6/ip6t_esp.h>
19
20 MODULE_LICENSE("GPL");
21 MODULE_DESCRIPTION("IPv6 ESP match");
22 MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
23
24 #if 0
25 #define DEBUGP printk
26 #else
27 #define DEBUGP(format, args...)
28 #endif
29
30 /* Returns 1 if the spi is matched by the range, 0 otherwise */
31 static inline int
32 spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, int invert)
33 {
34         int r=0;
35         DEBUGP("esp spi_match:%c 0x%x <= 0x%x <= 0x%x",invert? '!':' ',
36                min,spi,max);
37         r=(spi >= min && spi <= max) ^ invert;
38         DEBUGP(" result %s\n",r? "PASS\n" : "FAILED\n");
39         return r;
40 }
41
42 static int
43 match(const struct sk_buff *skb,
44       const struct net_device *in,
45       const struct net_device *out,
46       const void *matchinfo,
47       int offset,
48       unsigned int protoff,
49       int *hotdrop)
50 {
51         struct ip_esp_hdr _esp, *eh;
52         const struct ip6t_esp *espinfo = matchinfo;
53         unsigned int ptr;
54
55         /* Make sure this isn't an evil packet */
56         /*DEBUGP("ipv6_esp entered \n");*/
57
58         if (ipv6_find_hdr(skb, &ptr, NEXTHDR_ESP) < 0)
59                 return 0;
60
61         eh = skb_header_pointer(skb, ptr, sizeof(_esp), &_esp);
62         if (eh == NULL) {
63                 *hotdrop = 1;
64                 return 0;
65         }
66
67         DEBUGP("IPv6 ESP SPI %u %08X\n", ntohl(eh->spi), ntohl(eh->spi));
68
69         return (eh != NULL)
70                 && spi_match(espinfo->spis[0], espinfo->spis[1],
71                               ntohl(eh->spi),
72                               !!(espinfo->invflags & IP6T_ESP_INV_SPI));
73 }
74
75 /* Called when user tries to insert an entry of this type. */
76 static int
77 checkentry(const char *tablename,
78            const struct ip6t_ip6 *ip,
79            void *matchinfo,
80            unsigned int matchinfosize,
81            unsigned int hook_mask)
82 {
83         const struct ip6t_esp *espinfo = matchinfo;
84
85         if (matchinfosize != IP6T_ALIGN(sizeof(struct ip6t_esp))) {
86                 DEBUGP("ip6t_esp: matchsize %u != %u\n",
87                          matchinfosize, IP6T_ALIGN(sizeof(struct ip6t_esp)));
88                 return 0;
89         }
90         if (espinfo->invflags & ~IP6T_ESP_INV_MASK) {
91                 DEBUGP("ip6t_esp: unknown flags %X\n",
92                          espinfo->invflags);
93                 return 0;
94         }
95         return 1;
96 }
97
98 static struct ip6t_match esp_match = {
99         .name           = "esp",
100         .match          = &match,
101         .checkentry     = &checkentry,
102         .me             = THIS_MODULE,
103 };
104
105 static int __init init(void)
106 {
107         return ip6t_register_match(&esp_match);
108 }
109
110 static void __exit cleanup(void)
111 {
112         ip6t_unregister_match(&esp_match);
113 }
114
115 module_init(init);
116 module_exit(cleanup);