OpenCores
URL https://opencores.org/ocsvn/or1k_soc_on_altera_embedded_dev_kit/or1k_soc_on_altera_embedded_dev_kit/trunk

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [tags/] [linux-2.6/] [linux-2.6.24_or32_unified_v2.3/] [net/] [ipv4/] [netfilter/] [ipt_ah.c] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 xianfeng
/* 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
 
9
#include <linux/in.h>
10
#include <linux/module.h>
11
#include <linux/skbuff.h>
12
#include <linux/ip.h>
13
 
14
#include <linux/netfilter_ipv4/ipt_ah.h>
15
#include <linux/netfilter/x_tables.h>
16
 
17
MODULE_LICENSE("GPL");
18
MODULE_AUTHOR("Yon Uriarte <yon@astaro.de>");
19
MODULE_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 */
28
static inline bool
29
spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, bool invert)
30
{
31
        bool r;
32
        duprintf("ah spi_match:%c 0x%x <= 0x%x <= 0x%x",invert? '!':' ',
33
                min,spi,max);
34
        r=(spi >= min && spi <= max) ^ invert;
35
        duprintf(" result %s\n",r? "PASS" : "FAILED");
36
        return r;
37
}
38
 
39
static bool
40
match(const struct sk_buff *skb,
41
      const struct net_device *in,
42
      const struct net_device *out,
43
      const struct xt_match *match,
44
      const void *matchinfo,
45
      int offset,
46
      unsigned int protoff,
47
      bool *hotdrop)
48
{
49
        struct ip_auth_hdr _ahdr;
50
        const struct ip_auth_hdr *ah;
51
        const struct ipt_ah *ahinfo = matchinfo;
52
 
53
        /* Must not be a fragment. */
54
        if (offset)
55
                return false;
56
 
57
        ah = skb_header_pointer(skb, protoff,
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");
64
                *hotdrop = true;
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. */
74
static bool
75
checkentry(const char *tablename,
76
           const void *ip_void,
77
           const struct xt_match *match,
78
           void *matchinfo,
79
           unsigned int hook_mask)
80
{
81
        const struct ipt_ah *ahinfo = matchinfo;
82
 
83
        /* Must specify no unknown invflags */
84
        if (ahinfo->invflags & ~IPT_AH_INV_MASK) {
85
                duprintf("ipt_ah: unknown flags %X\n", ahinfo->invflags);
86
                return false;
87
        }
88
        return true;
89
}
90
 
91
static struct xt_match ah_match __read_mostly = {
92
        .name           = "ah",
93
        .family         = AF_INET,
94
        .match          = match,
95
        .matchsize      = sizeof(struct ipt_ah),
96
        .proto          = IPPROTO_AH,
97
        .checkentry     = checkentry,
98
        .me             = THIS_MODULE,
99
};
100
 
101
static int __init ipt_ah_init(void)
102
{
103
        return xt_register_match(&ah_match);
104
}
105
 
106
static void __exit ipt_ah_fini(void)
107
{
108
        xt_unregister_match(&ah_match);
109
}
110
 
111
module_init(ipt_ah_init);
112
module_exit(ipt_ah_fini);

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.