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