Blame view
net/netfilter/xt_esp.c
2.64 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 |
/* Kernel module to match ESP parameters. */ /* (C) 1999-2000 Yon Uriarte <yon@astaro.de> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ |
be91fd5e3 netfilter: xtable... |
9 |
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
1da177e4c Linux-2.6.12-rc2 |
10 11 |
#include <linux/module.h> #include <linux/skbuff.h> |
dc5ab2fae [NETFILTER]: x_ta... |
12 |
#include <linux/in.h> |
1da177e4c Linux-2.6.12-rc2 |
13 |
#include <linux/ip.h> |
dc5ab2fae [NETFILTER]: x_ta... |
14 15 |
#include <linux/netfilter/xt_esp.h> #include <linux/netfilter/x_tables.h> |
1da177e4c Linux-2.6.12-rc2 |
16 |
#include <linux/netfilter_ipv4/ip_tables.h> |
dc5ab2fae [NETFILTER]: x_ta... |
17 |
#include <linux/netfilter_ipv6/ip6_tables.h> |
1da177e4c Linux-2.6.12-rc2 |
18 19 20 |
MODULE_LICENSE("GPL"); MODULE_AUTHOR("Yon Uriarte <yon@astaro.de>"); |
2ae15b64e [NETFILTER]: Upda... |
21 |
MODULE_DESCRIPTION("Xtables: IPsec-ESP packet match"); |
dc5ab2fae [NETFILTER]: x_ta... |
22 23 |
MODULE_ALIAS("ipt_esp"); MODULE_ALIAS("ip6t_esp"); |
1da177e4c Linux-2.6.12-rc2 |
24 |
|
1da177e4c Linux-2.6.12-rc2 |
25 |
/* Returns 1 if the spi is matched by the range, 0 otherwise */ |
1d93a9cba [NETFILTER]: x_ta... |
26 27 |
static inline bool spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, bool invert) |
1da177e4c Linux-2.6.12-rc2 |
28 |
{ |
1d93a9cba [NETFILTER]: x_ta... |
29 |
bool r; |
ff67e4e42 netfilter: xt ext... |
30 31 |
pr_debug("spi_match:%c 0x%x <= 0x%x <= 0x%x ", |
be91fd5e3 netfilter: xtable... |
32 |
invert ? '!' : ' ', min, spi, max); |
dc5ab2fae [NETFILTER]: x_ta... |
33 |
r = (spi >= min && spi <= max) ^ invert; |
be91fd5e3 netfilter: xtable... |
34 35 |
pr_debug(" result %s ", r ? "PASS" : "FAILED"); |
1da177e4c Linux-2.6.12-rc2 |
36 37 |
return r; } |
62fc80510 netfilter: xtable... |
38 |
static bool esp_mt(const struct sk_buff *skb, struct xt_action_param *par) |
1da177e4c Linux-2.6.12-rc2 |
39 |
{ |
3cf93c96a [NETFILTER]: anno... |
40 41 |
const struct ip_esp_hdr *eh; struct ip_esp_hdr _esp; |
f7108a20d netfilter: xtable... |
42 |
const struct xt_esp *espinfo = par->matchinfo; |
1da177e4c Linux-2.6.12-rc2 |
43 44 |
/* Must not be a fragment. */ |
f7108a20d netfilter: xtable... |
45 |
if (par->fragoff != 0) |
1d93a9cba [NETFILTER]: x_ta... |
46 |
return false; |
1da177e4c Linux-2.6.12-rc2 |
47 |
|
f7108a20d netfilter: xtable... |
48 |
eh = skb_header_pointer(skb, par->thoff, sizeof(_esp), &_esp); |
1da177e4c Linux-2.6.12-rc2 |
49 50 51 52 |
if (eh == NULL) { /* We've been asked to examine this packet, and we * can't. Hence, no choice but to drop. */ |
be91fd5e3 netfilter: xtable... |
53 54 |
pr_debug("Dropping evil ESP tinygram. "); |
b4ba26119 netfilter: xtable... |
55 |
par->hotdrop = true; |
1d93a9cba [NETFILTER]: x_ta... |
56 |
return false; |
1da177e4c Linux-2.6.12-rc2 |
57 |
} |
dc5ab2fae [NETFILTER]: x_ta... |
58 59 |
return spi_match(espinfo->spis[0], espinfo->spis[1], ntohl(eh->spi), !!(espinfo->invflags & XT_ESP_INV_SPI)); |
1da177e4c Linux-2.6.12-rc2 |
60 |
} |
b0f38452f netfilter: xtable... |
61 |
static int esp_mt_check(const struct xt_mtchk_param *par) |
1da177e4c Linux-2.6.12-rc2 |
62 |
{ |
9b4fce7a3 netfilter: xtable... |
63 |
const struct xt_esp *espinfo = par->matchinfo; |
1da177e4c Linux-2.6.12-rc2 |
64 |
|
dc5ab2fae [NETFILTER]: x_ta... |
65 |
if (espinfo->invflags & ~XT_ESP_INV_MASK) { |
be91fd5e3 netfilter: xtable... |
66 67 |
pr_debug("unknown flags %X ", espinfo->invflags); |
bd414ee60 netfilter: xtable... |
68 |
return -EINVAL; |
1da177e4c Linux-2.6.12-rc2 |
69 |
} |
dc5ab2fae [NETFILTER]: x_ta... |
70 |
|
bd414ee60 netfilter: xtable... |
71 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
72 |
} |
d3c5ee6d5 [NETFILTER]: x_ta... |
73 |
static struct xt_match esp_mt_reg[] __read_mostly = { |
4470bbc74 [NETFILTER]: x_ta... |
74 75 |
{ .name = "esp", |
ee999d8b9 netfilter: x_tabl... |
76 |
.family = NFPROTO_IPV4, |
d3c5ee6d5 [NETFILTER]: x_ta... |
77 78 |
.checkentry = esp_mt_check, .match = esp_mt, |
4470bbc74 [NETFILTER]: x_ta... |
79 80 81 82 83 84 |
.matchsize = sizeof(struct xt_esp), .proto = IPPROTO_ESP, .me = THIS_MODULE, }, { .name = "esp", |
ee999d8b9 netfilter: x_tabl... |
85 |
.family = NFPROTO_IPV6, |
d3c5ee6d5 [NETFILTER]: x_ta... |
86 87 |
.checkentry = esp_mt_check, .match = esp_mt, |
4470bbc74 [NETFILTER]: x_ta... |
88 89 90 91 |
.matchsize = sizeof(struct xt_esp), .proto = IPPROTO_ESP, .me = THIS_MODULE, }, |
dc5ab2fae [NETFILTER]: x_ta... |
92 |
}; |
d3c5ee6d5 [NETFILTER]: x_ta... |
93 |
static int __init esp_mt_init(void) |
1da177e4c Linux-2.6.12-rc2 |
94 |
{ |
d3c5ee6d5 [NETFILTER]: x_ta... |
95 |
return xt_register_matches(esp_mt_reg, ARRAY_SIZE(esp_mt_reg)); |
1da177e4c Linux-2.6.12-rc2 |
96 |
} |
d3c5ee6d5 [NETFILTER]: x_ta... |
97 |
static void __exit esp_mt_exit(void) |
1da177e4c Linux-2.6.12-rc2 |
98 |
{ |
d3c5ee6d5 [NETFILTER]: x_ta... |
99 |
xt_unregister_matches(esp_mt_reg, ARRAY_SIZE(esp_mt_reg)); |
1da177e4c Linux-2.6.12-rc2 |
100 |
} |
d3c5ee6d5 [NETFILTER]: x_ta... |
101 102 |
module_init(esp_mt_init); module_exit(esp_mt_exit); |