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/] [trunk/] [linux-2.6/] [linux-2.6.24/] [net/] [ipv6/] [netfilter/] [ip6t_rt.c] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 xianfeng
/* Kernel module to match ROUTING 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/ipv6.h>
13
#include <linux/types.h>
14
#include <net/checksum.h>
15
#include <net/ipv6.h>
16
 
17
#include <asm/byteorder.h>
18
 
19
#include <linux/netfilter/x_tables.h>
20
#include <linux/netfilter_ipv6/ip6_tables.h>
21
#include <linux/netfilter_ipv6/ip6t_rt.h>
22
 
23
MODULE_LICENSE("GPL");
24
MODULE_DESCRIPTION("IPv6 RT match");
25
MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
26
 
27
/* Returns 1 if the id is matched by the range, 0 otherwise */
28
static inline bool
29
segsleft_match(u_int32_t min, u_int32_t max, u_int32_t id, bool invert)
30
{
31
        bool r;
32
        pr_debug("rt segsleft_match:%c 0x%x <= 0x%x <= 0x%x",
33
                 invert ? '!' : ' ', min, id, max);
34
        r = (id >= min && id <= max) ^ invert;
35
        pr_debug(" 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 ipv6_rt_hdr _route;
50
        const struct ipv6_rt_hdr *rh;
51
        const struct ip6t_rt *rtinfo = matchinfo;
52
        unsigned int temp;
53
        unsigned int ptr;
54
        unsigned int hdrlen = 0;
55
        bool ret = false;
56
        struct in6_addr _addr;
57
        const struct in6_addr *ap;
58
        int err;
59
 
60
        err = ipv6_find_hdr(skb, &ptr, NEXTHDR_ROUTING, NULL);
61
        if (err < 0) {
62
                if (err != -ENOENT)
63
                        *hotdrop = true;
64
                return false;
65
        }
66
 
67
        rh = skb_header_pointer(skb, ptr, sizeof(_route), &_route);
68
        if (rh == NULL) {
69
                *hotdrop = true;
70
                return false;
71
        }
72
 
73
        hdrlen = ipv6_optlen(rh);
74
        if (skb->len - ptr < hdrlen) {
75
                /* Pcket smaller than its length field */
76
                return false;
77
        }
78
 
79
        pr_debug("IPv6 RT LEN %u %u ", hdrlen, rh->hdrlen);
80
        pr_debug("TYPE %04X ", rh->type);
81
        pr_debug("SGS_LEFT %u %02X\n", rh->segments_left, rh->segments_left);
82
 
83
        pr_debug("IPv6 RT segsleft %02X ",
84
                 segsleft_match(rtinfo->segsleft[0], rtinfo->segsleft[1],
85
                                rh->segments_left,
86
                                !!(rtinfo->invflags & IP6T_RT_INV_SGS)));
87
        pr_debug("type %02X %02X %02X ",
88
                 rtinfo->rt_type, rh->type,
89
                 (!(rtinfo->flags & IP6T_RT_TYP) ||
90
                  ((rtinfo->rt_type == rh->type) ^
91
                   !!(rtinfo->invflags & IP6T_RT_INV_TYP))));
92
        pr_debug("len %02X %04X %02X ",
93
                 rtinfo->hdrlen, hdrlen,
94
                 !(rtinfo->flags & IP6T_RT_LEN) ||
95
                  ((rtinfo->hdrlen == hdrlen) ^
96
                   !!(rtinfo->invflags & IP6T_RT_INV_LEN)));
97
        pr_debug("res %02X %02X %02X ",
98
                 rtinfo->flags & IP6T_RT_RES,
99
                 ((const struct rt0_hdr *)rh)->reserved,
100
                 !((rtinfo->flags & IP6T_RT_RES) &&
101
                   (((const struct rt0_hdr *)rh)->reserved)));
102
 
103
        ret = (rh != NULL)
104
              &&
105
              (segsleft_match(rtinfo->segsleft[0], rtinfo->segsleft[1],
106
                              rh->segments_left,
107
                              !!(rtinfo->invflags & IP6T_RT_INV_SGS)))
108
              &&
109
              (!(rtinfo->flags & IP6T_RT_LEN) ||
110
               ((rtinfo->hdrlen == hdrlen) ^
111
                !!(rtinfo->invflags & IP6T_RT_INV_LEN)))
112
              &&
113
              (!(rtinfo->flags & IP6T_RT_TYP) ||
114
               ((rtinfo->rt_type == rh->type) ^
115
                !!(rtinfo->invflags & IP6T_RT_INV_TYP)));
116
 
117
        if (ret && (rtinfo->flags & IP6T_RT_RES)) {
118
                u_int32_t *rp, _reserved;
119
                rp = skb_header_pointer(skb,
120
                                        ptr + offsetof(struct rt0_hdr,
121
                                                       reserved),
122
                                        sizeof(_reserved),
123
                                        &_reserved);
124
 
125
                ret = (*rp == 0);
126
        }
127
 
128
        pr_debug("#%d ", rtinfo->addrnr);
129
        if (!(rtinfo->flags & IP6T_RT_FST)) {
130
                return ret;
131
        } else if (rtinfo->flags & IP6T_RT_FST_NSTRICT) {
132
                pr_debug("Not strict ");
133
                if (rtinfo->addrnr > (unsigned int)((hdrlen - 8) / 16)) {
134
                        pr_debug("There isn't enough space\n");
135
                        return false;
136
                } else {
137
                        unsigned int i = 0;
138
 
139
                        pr_debug("#%d ", rtinfo->addrnr);
140
                        for (temp = 0;
141
                             temp < (unsigned int)((hdrlen - 8) / 16);
142
                             temp++) {
143
                                ap = skb_header_pointer(skb,
144
                                                        ptr
145
                                                        + sizeof(struct rt0_hdr)
146
                                                        + temp * sizeof(_addr),
147
                                                        sizeof(_addr),
148
                                                        &_addr);
149
 
150
                                BUG_ON(ap == NULL);
151
 
152
                                if (ipv6_addr_equal(ap, &rtinfo->addrs[i])) {
153
                                        pr_debug("i=%d temp=%d;\n", i, temp);
154
                                        i++;
155
                                }
156
                                if (i == rtinfo->addrnr)
157
                                        break;
158
                        }
159
                        pr_debug("i=%d #%d\n", i, rtinfo->addrnr);
160
                        if (i == rtinfo->addrnr)
161
                                return ret;
162
                        else
163
                                return false;
164
                }
165
        } else {
166
                pr_debug("Strict ");
167
                if (rtinfo->addrnr > (unsigned int)((hdrlen - 8) / 16)) {
168
                        pr_debug("There isn't enough space\n");
169
                        return false;
170
                } else {
171
                        pr_debug("#%d ", rtinfo->addrnr);
172
                        for (temp = 0; temp < rtinfo->addrnr; temp++) {
173
                                ap = skb_header_pointer(skb,
174
                                                        ptr
175
                                                        + sizeof(struct rt0_hdr)
176
                                                        + temp * sizeof(_addr),
177
                                                        sizeof(_addr),
178
                                                        &_addr);
179
                                BUG_ON(ap == NULL);
180
 
181
                                if (!ipv6_addr_equal(ap, &rtinfo->addrs[temp]))
182
                                        break;
183
                        }
184
                        pr_debug("temp=%d #%d\n", temp, rtinfo->addrnr);
185
                        if (temp == rtinfo->addrnr &&
186
                            temp == (unsigned int)((hdrlen - 8) / 16))
187
                                return ret;
188
                        else
189
                                return false;
190
                }
191
        }
192
 
193
        return false;
194
}
195
 
196
/* Called when user tries to insert an entry of this type. */
197
static bool
198
checkentry(const char *tablename,
199
           const void *entry,
200
           const struct xt_match *match,
201
           void *matchinfo,
202
           unsigned int hook_mask)
203
{
204
        const struct ip6t_rt *rtinfo = matchinfo;
205
 
206
        if (rtinfo->invflags & ~IP6T_RT_INV_MASK) {
207
                pr_debug("ip6t_rt: unknown flags %X\n", rtinfo->invflags);
208
                return false;
209
        }
210
        if ((rtinfo->flags & (IP6T_RT_RES | IP6T_RT_FST_MASK)) &&
211
            (!(rtinfo->flags & IP6T_RT_TYP) ||
212
             (rtinfo->rt_type != 0) ||
213
             (rtinfo->invflags & IP6T_RT_INV_TYP))) {
214
                pr_debug("`--rt-type 0' required before `--rt-0-*'");
215
                return false;
216
        }
217
 
218
        return true;
219
}
220
 
221
static struct xt_match rt_match __read_mostly = {
222
        .name           = "rt",
223
        .family         = AF_INET6,
224
        .match          = match,
225
        .matchsize      = sizeof(struct ip6t_rt),
226
        .checkentry     = checkentry,
227
        .me             = THIS_MODULE,
228
};
229
 
230
static int __init ip6t_rt_init(void)
231
{
232
        return xt_register_match(&rt_match);
233
}
234
 
235
static void __exit ip6t_rt_fini(void)
236
{
237
        xt_unregister_match(&rt_match);
238
}
239
 
240
module_init(ip6t_rt_init);
241
module_exit(ip6t_rt_fini);

powered by: WebSVN 2.1.0

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