[NETFILTER]: add some consts, remove some casts
[deliverable/linux.git] / net / ipv4 / netfilter / ipt_ah.c
CommitLineData
1da177e4
LT
1/* Kernel module to match AH parameters. */
2/* (C) 1999-2000 Yon Uriarte <yon@astaro.de>
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
6709dbbb 9#include <linux/in.h>
1da177e4
LT
10#include <linux/module.h>
11#include <linux/skbuff.h>
12#include <linux/ip.h>
13
14#include <linux/netfilter_ipv4/ipt_ah.h>
6709dbbb 15#include <linux/netfilter/x_tables.h>
1da177e4
LT
16
17MODULE_LICENSE("GPL");
18MODULE_AUTHOR("Yon Uriarte <yon@astaro.de>");
19MODULE_DESCRIPTION("iptables AH SPI match module");
20
21#ifdef DEBUG_CONNTRACK
22#define duprintf(format, args...) printk(format , ## args)
23#else
24#define duprintf(format, args...)
25#endif
26
27/* Returns 1 if the spi is matched by the range, 0 otherwise */
1d93a9cb
JE
28static inline bool
29spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, bool invert)
1da177e4 30{
1d93a9cb 31 bool r;
e905a9ed
YH
32 duprintf("ah spi_match:%c 0x%x <= 0x%x <= 0x%x",invert? '!':' ',
33 min,spi,max);
1da177e4
LT
34 r=(spi >= min && spi <= max) ^ invert;
35 duprintf(" result %s\n",r? "PASS" : "FAILED");
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,
2e4e6a17 46 unsigned int protoff,
cff533ac 47 bool *hotdrop)
1da177e4 48{
a47362a2
JE
49 struct ip_auth_hdr _ahdr;
50 const struct ip_auth_hdr *ah;
1da177e4
LT
51 const struct ipt_ah *ahinfo = matchinfo;
52
53 /* Must not be a fragment. */
54 if (offset)
1d93a9cb 55 return false;
1da177e4 56
2e4e6a17 57 ah = skb_header_pointer(skb, protoff,
1da177e4
LT
58 sizeof(_ahdr), &_ahdr);
59 if (ah == NULL) {
60 /* We've been asked to examine this packet, and we
61 * can't. Hence, no choice but to drop.
62 */
63 duprintf("Dropping evil AH tinygram.\n");
cff533ac 64 *hotdrop = true;
1da177e4
LT
65 return 0;
66 }
67
68 return spi_match(ahinfo->spis[0], ahinfo->spis[1],
69 ntohl(ah->spi),
70 !!(ahinfo->invflags & IPT_AH_INV_SPI));
71}
72
73/* Called when user tries to insert an entry of this type. */
ccb79bdc 74static bool
1da177e4 75checkentry(const char *tablename,
2e4e6a17 76 const void *ip_void,
c4986734 77 const struct xt_match *match,
1da177e4 78 void *matchinfo,
1da177e4
LT
79 unsigned int hook_mask)
80{
81 const struct ipt_ah *ahinfo = matchinfo;
82
1d5cd909 83 /* Must specify no unknown invflags */
1da177e4 84 if (ahinfo->invflags & ~IPT_AH_INV_MASK) {
1d5cd909 85 duprintf("ipt_ah: unknown flags %X\n", ahinfo->invflags);
ccb79bdc 86 return false;
1da177e4 87 }
ccb79bdc 88 return true;
1da177e4
LT
89}
90
6709dbbb 91static struct xt_match ah_match = {
1da177e4 92 .name = "ah",
6709dbbb 93 .family = AF_INET,
1d5cd909
PM
94 .match = match,
95 .matchsize = sizeof(struct ipt_ah),
96 .proto = IPPROTO_AH,
97 .checkentry = checkentry,
1da177e4
LT
98 .me = THIS_MODULE,
99};
100
65b4b4e8 101static int __init ipt_ah_init(void)
1da177e4 102{
6709dbbb 103 return xt_register_match(&ah_match);
1da177e4
LT
104}
105
65b4b4e8 106static void __exit ipt_ah_fini(void)
1da177e4 107{
6709dbbb 108 xt_unregister_match(&ah_match);
1da177e4
LT
109}
110
65b4b4e8
AM
111module_init(ipt_ah_init);
112module_exit(ipt_ah_fini);
This page took 0.252163 seconds and 5 git commands to generate.