[NETFILTER]: Convert DEBUGP to pr_debug
[deliverable/linux.git] / net / ipv6 / netfilter / ip6t_ah.c
CommitLineData
1da177e4
LT
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>
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
6709dbbb 18#include <linux/netfilter/x_tables.h>
1da177e4
LT
19#include <linux/netfilter_ipv6/ip6_tables.h>
20#include <linux/netfilter_ipv6/ip6t_ah.h>
21
22MODULE_LICENSE("GPL");
23MODULE_DESCRIPTION("IPv6 AH match");
24MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
25
1da177e4 26/* Returns 1 if the spi is matched by the range, 0 otherwise */
1d93a9cb
JE
27static inline bool
28spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, bool invert)
1da177e4 29{
1d93a9cb 30 bool r;
0d53778e
PM
31
32 pr_debug("ah spi_match:%c 0x%x <= 0x%x <= 0x%x",
33 invert ? '!' : ' ', min, spi, max);
1da177e4 34 r = (spi >= min && spi <= max) ^ invert;
0d53778e 35 pr_debug(" result %s\n", r ? "PASS" : "FAILED");
1da177e4
LT
36 return r;
37}
38
1d93a9cb 39static bool
1da177e4
LT
40match(const struct sk_buff *skb,
41 const struct net_device *in,
42 const struct net_device *out,
c4986734 43 const struct xt_match *match,
1da177e4
LT
44 const void *matchinfo,
45 int offset,
46 unsigned int protoff,
cff533ac 47 bool *hotdrop)
1da177e4 48{
a47362a2
JE
49 struct ip_auth_hdr _ah;
50 const struct ip_auth_hdr *ah;
1da177e4 51 const struct ip6t_ah *ahinfo = matchinfo;
1da177e4
LT
52 unsigned int ptr;
53 unsigned int hdrlen = 0;
6d381634 54 int err;
1da177e4 55
6d381634
PM
56 err = ipv6_find_hdr(skb, &ptr, NEXTHDR_AUTH, NULL);
57 if (err < 0) {
58 if (err != -ENOENT)
cff533ac 59 *hotdrop = true;
1d93a9cb 60 return false;
6d381634 61 }
1da177e4 62
e674d0f3
YK
63 ah = skb_header_pointer(skb, ptr, sizeof(_ah), &_ah);
64 if (ah == NULL) {
cff533ac 65 *hotdrop = true;
1d93a9cb 66 return false;
1da177e4
LT
67 }
68
e674d0f3 69 hdrlen = (ah->hdrlen + 2) << 2;
1da177e4 70
0d53778e
PM
71 pr_debug("IPv6 AH LEN %u %u ", hdrlen, ah->hdrlen);
72 pr_debug("RES %04X ", ah->reserved);
73 pr_debug("SPI %u %08X\n", ntohl(ah->spi), ntohl(ah->spi));
74
75 pr_debug("IPv6 AH spi %02X ",
76 spi_match(ahinfo->spis[0], ahinfo->spis[1],
77 ntohl(ah->spi),
78 !!(ahinfo->invflags & IP6T_AH_INV_SPI)));
79 pr_debug("len %02X %04X %02X ",
80 ahinfo->hdrlen, hdrlen,
81 (!ahinfo->hdrlen ||
82 (ahinfo->hdrlen == hdrlen) ^
83 !!(ahinfo->invflags & IP6T_AH_INV_LEN)));
84 pr_debug("res %02X %04X %02X\n",
85 ahinfo->hdrres, ah->reserved,
86 !(ahinfo->hdrres && ah->reserved));
1da177e4
LT
87
88 return (ah != NULL)
89 &&
7c4e36bc
JE
90 spi_match(ahinfo->spis[0], ahinfo->spis[1],
91 ntohl(ah->spi),
92 !!(ahinfo->invflags & IP6T_AH_INV_SPI))
1da177e4
LT
93 &&
94 (!ahinfo->hdrlen ||
1ab1457c
YH
95 (ahinfo->hdrlen == hdrlen) ^
96 !!(ahinfo->invflags & IP6T_AH_INV_LEN))
1da177e4
LT
97 &&
98 !(ahinfo->hdrres && ah->reserved);
99}
100
101/* Called when user tries to insert an entry of this type. */
ccb79bdc 102static bool
1da177e4 103checkentry(const char *tablename,
1ab1457c 104 const void *entry,
c4986734 105 const struct xt_match *match,
1ab1457c
YH
106 void *matchinfo,
107 unsigned int hook_mask)
1da177e4
LT
108{
109 const struct ip6t_ah *ahinfo = matchinfo;
110
1da177e4 111 if (ahinfo->invflags & ~IP6T_AH_INV_MASK) {
0d53778e 112 pr_debug("ip6t_ah: unknown flags %X\n", ahinfo->invflags);
ccb79bdc 113 return false;
1da177e4 114 }
ccb79bdc 115 return true;
1da177e4
LT
116}
117
9f15c530 118static struct xt_match ah_match __read_mostly = {
1da177e4 119 .name = "ah",
6709dbbb 120 .family = AF_INET6,
7f939713
PM
121 .match = match,
122 .matchsize = sizeof(struct ip6t_ah),
123 .checkentry = checkentry,
1da177e4
LT
124 .me = THIS_MODULE,
125};
126
65b4b4e8 127static int __init ip6t_ah_init(void)
1da177e4 128{
6709dbbb 129 return xt_register_match(&ah_match);
1da177e4
LT
130}
131
65b4b4e8 132static void __exit ip6t_ah_fini(void)
1da177e4 133{
6709dbbb 134 xt_unregister_match(&ah_match);
1da177e4
LT
135}
136
65b4b4e8
AM
137module_init(ip6t_ah_init);
138module_exit(ip6t_ah_fini);
This page took 0.402007 seconds and 5 git commands to generate.