1 /* Kernel module to match ROUTING parameters. */
3 /* (C) 2001-2002 Andras Kis-Szabo <kisza@sch.bme.hu>
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.
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>
17 #include <asm/byteorder.h>
19 #include <linux/netfilter_ipv6/ip6_tables.h>
20 #include <linux/netfilter_ipv6/ip6t_rt.h>
22 MODULE_LICENSE("GPL");
23 MODULE_DESCRIPTION("IPv6 RT match");
24 MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
29 #define DEBUGP(format, args...)
32 /* Returns 1 if the id is matched by the range, 0 otherwise */
34 segsleft_match(u_int32_t min
, u_int32_t max
, u_int32_t id
, int invert
)
37 DEBUGP("rt segsleft_match:%c 0x%x <= 0x%x <= 0x%x",
38 invert
? '!' : ' ', min
, id
, max
);
39 r
= (id
>= min
&& id
<= max
) ^ invert
;
40 DEBUGP(" result %s\n", r
? "PASS" : "FAILED");
45 match(const struct sk_buff
*skb
,
46 const struct net_device
*in
,
47 const struct net_device
*out
,
48 const struct xt_match
*match
,
49 const void *matchinfo
,
54 struct ipv6_rt_hdr _route
, *rh
;
55 const struct ip6t_rt
*rtinfo
= matchinfo
;
58 unsigned int hdrlen
= 0;
60 struct in6_addr
*ap
, _addr
;
63 err
= ipv6_find_hdr(skb
, &ptr
, NEXTHDR_ROUTING
, NULL
);
70 rh
= skb_header_pointer(skb
, ptr
, sizeof(_route
), &_route
);
76 hdrlen
= ipv6_optlen(rh
);
77 if (skb
->len
- ptr
< hdrlen
) {
78 /* Pcket smaller than its length field */
82 DEBUGP("IPv6 RT LEN %u %u ", hdrlen
, rh
->hdrlen
);
83 DEBUGP("TYPE %04X ", rh
->type
);
84 DEBUGP("SGS_LEFT %u %02X\n", rh
->segments_left
, rh
->segments_left
);
86 DEBUGP("IPv6 RT segsleft %02X ",
87 (segsleft_match(rtinfo
->segsleft
[0], rtinfo
->segsleft
[1],
89 !!(rtinfo
->invflags
& IP6T_RT_INV_SGS
))));
90 DEBUGP("type %02X %02X %02X ",
91 rtinfo
->rt_type
, rh
->type
,
92 (!(rtinfo
->flags
& IP6T_RT_TYP
) ||
93 ((rtinfo
->rt_type
== rh
->type
) ^
94 !!(rtinfo
->invflags
& IP6T_RT_INV_TYP
))));
95 DEBUGP("len %02X %04X %02X ",
96 rtinfo
->hdrlen
, hdrlen
,
97 (!(rtinfo
->flags
& IP6T_RT_LEN
) ||
98 ((rtinfo
->hdrlen
== hdrlen
) ^
99 !!(rtinfo
->invflags
& IP6T_RT_INV_LEN
))));
100 DEBUGP("res %02X %02X %02X ",
101 (rtinfo
->flags
& IP6T_RT_RES
),
102 ((struct rt0_hdr
*)rh
)->reserved
,
103 !((rtinfo
->flags
& IP6T_RT_RES
) &&
104 (((struct rt0_hdr
*)rh
)->reserved
)));
108 (segsleft_match(rtinfo
->segsleft
[0], rtinfo
->segsleft
[1],
110 !!(rtinfo
->invflags
& IP6T_RT_INV_SGS
)))
112 (!(rtinfo
->flags
& IP6T_RT_LEN
) ||
113 ((rtinfo
->hdrlen
== hdrlen
) ^
114 !!(rtinfo
->invflags
& IP6T_RT_INV_LEN
)))
116 (!(rtinfo
->flags
& IP6T_RT_TYP
) ||
117 ((rtinfo
->rt_type
== rh
->type
) ^
118 !!(rtinfo
->invflags
& IP6T_RT_INV_TYP
)));
120 if (ret
&& (rtinfo
->flags
& IP6T_RT_RES
)) {
121 u_int32_t
*rp
, _reserved
;
122 rp
= skb_header_pointer(skb
,
123 ptr
+ offsetof(struct rt0_hdr
,
131 DEBUGP("#%d ", rtinfo
->addrnr
);
132 if (!(rtinfo
->flags
& IP6T_RT_FST
)) {
134 } else if (rtinfo
->flags
& IP6T_RT_FST_NSTRICT
) {
135 DEBUGP("Not strict ");
136 if (rtinfo
->addrnr
> (unsigned int)((hdrlen
- 8) / 16)) {
137 DEBUGP("There isn't enough space\n");
142 DEBUGP("#%d ", rtinfo
->addrnr
);
144 temp
< (unsigned int)((hdrlen
- 8) / 16);
146 ap
= skb_header_pointer(skb
,
148 + sizeof(struct rt0_hdr
)
149 + temp
* sizeof(_addr
),
155 if (ipv6_addr_equal(ap
, &rtinfo
->addrs
[i
])) {
156 DEBUGP("i=%d temp=%d;\n", i
, temp
);
159 if (i
== rtinfo
->addrnr
)
162 DEBUGP("i=%d #%d\n", i
, rtinfo
->addrnr
);
163 if (i
== rtinfo
->addrnr
)
170 if (rtinfo
->addrnr
> (unsigned int)((hdrlen
- 8) / 16)) {
171 DEBUGP("There isn't enough space\n");
174 DEBUGP("#%d ", rtinfo
->addrnr
);
175 for (temp
= 0; temp
< rtinfo
->addrnr
; temp
++) {
176 ap
= skb_header_pointer(skb
,
178 + sizeof(struct rt0_hdr
)
179 + temp
* sizeof(_addr
),
184 if (!ipv6_addr_equal(ap
, &rtinfo
->addrs
[temp
]))
187 DEBUGP("temp=%d #%d\n", temp
, rtinfo
->addrnr
);
188 if ((temp
== rtinfo
->addrnr
) &&
189 (temp
== (unsigned int)((hdrlen
- 8) / 16)))
199 /* Called when user tries to insert an entry of this type. */
201 checkentry(const char *tablename
,
203 const struct xt_match
*match
,
205 unsigned int hook_mask
)
207 const struct ip6t_rt
*rtinfo
= matchinfo
;
209 if (rtinfo
->invflags
& ~IP6T_RT_INV_MASK
) {
210 DEBUGP("ip6t_rt: unknown flags %X\n", rtinfo
->invflags
);
213 if ((rtinfo
->flags
& (IP6T_RT_RES
| IP6T_RT_FST_MASK
)) &&
214 (!(rtinfo
->flags
& IP6T_RT_TYP
) ||
215 (rtinfo
->rt_type
!= 0) ||
216 (rtinfo
->invflags
& IP6T_RT_INV_TYP
))) {
217 DEBUGP("`--rt-type 0' required before `--rt-0-*'");
224 static struct ip6t_match rt_match
= {
227 .matchsize
= sizeof(struct ip6t_rt
),
228 .checkentry
= checkentry
,
232 static int __init
ip6t_rt_init(void)
234 return ip6t_register_match(&rt_match
);
237 static void __exit
ip6t_rt_fini(void)
239 ip6t_unregister_match(&rt_match
);
242 module_init(ip6t_rt_init
);
243 module_exit(ip6t_rt_fini
);
This page took 0.038903 seconds and 6 git commands to generate.