]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - net/ipv6/netfilter/ip6t_ah.c
Merge branch 'drm-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/airlied...
[mirror_ubuntu-artful-kernel.git] / net / ipv6 / netfilter / ip6t_ah.c
1 /* Kernel module to match AH parameters. */
2
3 /* (C) 2001-2002 Andras Kis-Szabo <kisza@sch.bme.hu>
4 *
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.
8 */
9
10 #include <linux/module.h>
11 #include <linux/skbuff.h>
12 #include <linux/ip.h>
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_ah.h>
20
21 MODULE_LICENSE("GPL");
22 MODULE_DESCRIPTION("IPv6 AH 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("ah 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 {
52 struct ip_auth_hdr *ah, _ah;
53 const struct ip6t_ah *ahinfo = matchinfo;
54 unsigned int ptr;
55 unsigned int hdrlen = 0;
56
57 if (ipv6_find_hdr(skb, &ptr, NEXTHDR_AUTH, NULL) < 0)
58 return 0;
59
60 ah = skb_header_pointer(skb, ptr, sizeof(_ah), &_ah);
61 if (ah == NULL) {
62 *hotdrop = 1;
63 return 0;
64 }
65
66 hdrlen = (ah->hdrlen + 2) << 2;
67
68 DEBUGP("IPv6 AH LEN %u %u ", hdrlen, ah->hdrlen);
69 DEBUGP("RES %04X ", ah->reserved);
70 DEBUGP("SPI %u %08X\n", ntohl(ah->spi), ntohl(ah->spi));
71
72 DEBUGP("IPv6 AH spi %02X ",
73 (spi_match(ahinfo->spis[0], ahinfo->spis[1],
74 ntohl(ah->spi),
75 !!(ahinfo->invflags & IP6T_AH_INV_SPI))));
76 DEBUGP("len %02X %04X %02X ",
77 ahinfo->hdrlen, hdrlen,
78 (!ahinfo->hdrlen ||
79 (ahinfo->hdrlen == hdrlen) ^
80 !!(ahinfo->invflags & IP6T_AH_INV_LEN)));
81 DEBUGP("res %02X %04X %02X\n",
82 ahinfo->hdrres, ah->reserved,
83 !(ahinfo->hdrres && ah->reserved));
84
85 return (ah != NULL)
86 &&
87 (spi_match(ahinfo->spis[0], ahinfo->spis[1],
88 ntohl(ah->spi),
89 !!(ahinfo->invflags & IP6T_AH_INV_SPI)))
90 &&
91 (!ahinfo->hdrlen ||
92 (ahinfo->hdrlen == hdrlen) ^
93 !!(ahinfo->invflags & IP6T_AH_INV_LEN))
94 &&
95 !(ahinfo->hdrres && ah->reserved);
96 }
97
98 /* Called when user tries to insert an entry of this type. */
99 static int
100 checkentry(const char *tablename,
101 const void *entry,
102 void *matchinfo,
103 unsigned int matchinfosize,
104 unsigned int hook_mask)
105 {
106 const struct ip6t_ah *ahinfo = matchinfo;
107
108 if (matchinfosize != IP6T_ALIGN(sizeof(struct ip6t_ah))) {
109 DEBUGP("ip6t_ah: matchsize %u != %u\n",
110 matchinfosize, IP6T_ALIGN(sizeof(struct ip6t_ah)));
111 return 0;
112 }
113 if (ahinfo->invflags & ~IP6T_AH_INV_MASK) {
114 DEBUGP("ip6t_ah: unknown flags %X\n", ahinfo->invflags);
115 return 0;
116 }
117 return 1;
118 }
119
120 static struct ip6t_match ah_match = {
121 .name = "ah",
122 .match = &match,
123 .checkentry = &checkentry,
124 .me = THIS_MODULE,
125 };
126
127 static int __init init(void)
128 {
129 return ip6t_register_match(&ah_match);
130 }
131
132 static void __exit cleanup(void)
133 {
134 ip6t_unregister_match(&ah_match);
135 }
136
137 module_init(init);
138 module_exit(cleanup);