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/x_tables.h>
20 #include <linux/netfilter_ipv6/ip6_tables.h>
21 #include <linux/netfilter_ipv6/ip6t_rt.h>
23 MODULE_LICENSE("GPL");
24 MODULE_DESCRIPTION("IPv6 RT match");
25 MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
30 #define DEBUGP(format, args...)
33 /* Returns 1 if the id is matched by the range, 0 otherwise */
35 segsleft_match(u_int32_t min
, u_int32_t max
, u_int32_t id
, bool invert
)
38 DEBUGP("rt segsleft_match:%c 0x%x <= 0x%x <= 0x%x",
39 invert
? '!' : ' ', min
, id
, max
);
40 r
= (id
>= min
&& id
<= max
) ^ invert
;
41 DEBUGP(" result %s\n", r
? "PASS" : "FAILED");
46 match(const struct sk_buff
*skb
,
47 const struct net_device
*in
,
48 const struct net_device
*out
,
49 const struct xt_match
*match
,
50 const void *matchinfo
,
55 struct ipv6_rt_hdr _route
, *rh
;
56 const struct ip6t_rt
*rtinfo
= matchinfo
;
59 unsigned int hdrlen
= 0;
61 struct in6_addr
*ap
, _addr
;
64 err
= ipv6_find_hdr(skb
, &ptr
, NEXTHDR_ROUTING
, NULL
);
71 rh
= skb_header_pointer(skb
, ptr
, sizeof(_route
), &_route
);
77 hdrlen
= ipv6_optlen(rh
);
78 if (skb
->len
- ptr
< hdrlen
) {
79 /* Pcket smaller than its length field */
83 DEBUGP("IPv6 RT LEN %u %u ", hdrlen
, rh
->hdrlen
);
84 DEBUGP("TYPE %04X ", rh
->type
);
85 DEBUGP("SGS_LEFT %u %02X\n", rh
->segments_left
, rh
->segments_left
);
87 DEBUGP("IPv6 RT segsleft %02X ",
88 (segsleft_match(rtinfo
->segsleft
[0], rtinfo
->segsleft
[1],
90 !!(rtinfo
->invflags
& IP6T_RT_INV_SGS
))));
91 DEBUGP("type %02X %02X %02X ",
92 rtinfo
->rt_type
, rh
->type
,
93 (!(rtinfo
->flags
& IP6T_RT_TYP
) ||
94 ((rtinfo
->rt_type
== rh
->type
) ^
95 !!(rtinfo
->invflags
& IP6T_RT_INV_TYP
))));
96 DEBUGP("len %02X %04X %02X ",
97 rtinfo
->hdrlen
, hdrlen
,
98 (!(rtinfo
->flags
& IP6T_RT_LEN
) ||
99 ((rtinfo
->hdrlen
== hdrlen
) ^
100 !!(rtinfo
->invflags
& IP6T_RT_INV_LEN
))));
101 DEBUGP("res %02X %02X %02X ",
102 (rtinfo
->flags
& IP6T_RT_RES
),
103 ((struct rt0_hdr
*)rh
)->reserved
,
104 !((rtinfo
->flags
& IP6T_RT_RES
) &&
105 (((struct rt0_hdr
*)rh
)->reserved
)));
109 (segsleft_match(rtinfo
->segsleft
[0], rtinfo
->segsleft
[1],
111 !!(rtinfo
->invflags
& IP6T_RT_INV_SGS
)))
113 (!(rtinfo
->flags
& IP6T_RT_LEN
) ||
114 ((rtinfo
->hdrlen
== hdrlen
) ^
115 !!(rtinfo
->invflags
& IP6T_RT_INV_LEN
)))
117 (!(rtinfo
->flags
& IP6T_RT_TYP
) ||
118 ((rtinfo
->rt_type
== rh
->type
) ^
119 !!(rtinfo
->invflags
& IP6T_RT_INV_TYP
)));
121 if (ret
&& (rtinfo
->flags
& IP6T_RT_RES
)) {
122 u_int32_t
*rp
, _reserved
;
123 rp
= skb_header_pointer(skb
,
124 ptr
+ offsetof(struct rt0_hdr
,
132 DEBUGP("#%d ", rtinfo
->addrnr
);
133 if (!(rtinfo
->flags
& IP6T_RT_FST
)) {
135 } else if (rtinfo
->flags
& IP6T_RT_FST_NSTRICT
) {
136 DEBUGP("Not strict ");
137 if (rtinfo
->addrnr
> (unsigned int)((hdrlen
- 8) / 16)) {
138 DEBUGP("There isn't enough space\n");
143 DEBUGP("#%d ", rtinfo
->addrnr
);
145 temp
< (unsigned int)((hdrlen
- 8) / 16);
147 ap
= skb_header_pointer(skb
,
149 + sizeof(struct rt0_hdr
)
150 + temp
* sizeof(_addr
),
156 if (ipv6_addr_equal(ap
, &rtinfo
->addrs
[i
])) {
157 DEBUGP("i=%d temp=%d;\n", i
, temp
);
160 if (i
== rtinfo
->addrnr
)
163 DEBUGP("i=%d #%d\n", i
, rtinfo
->addrnr
);
164 if (i
== rtinfo
->addrnr
)
171 if (rtinfo
->addrnr
> (unsigned int)((hdrlen
- 8) / 16)) {
172 DEBUGP("There isn't enough space\n");
175 DEBUGP("#%d ", rtinfo
->addrnr
);
176 for (temp
= 0; temp
< rtinfo
->addrnr
; temp
++) {
177 ap
= skb_header_pointer(skb
,
179 + sizeof(struct rt0_hdr
)
180 + temp
* sizeof(_addr
),
185 if (!ipv6_addr_equal(ap
, &rtinfo
->addrs
[temp
]))
188 DEBUGP("temp=%d #%d\n", temp
, rtinfo
->addrnr
);
189 if ((temp
== rtinfo
->addrnr
) &&
190 (temp
== (unsigned int)((hdrlen
- 8) / 16)))
200 /* Called when user tries to insert an entry of this type. */
202 checkentry(const char *tablename
,
204 const struct xt_match
*match
,
206 unsigned int hook_mask
)
208 const struct ip6t_rt
*rtinfo
= matchinfo
;
210 if (rtinfo
->invflags
& ~IP6T_RT_INV_MASK
) {
211 DEBUGP("ip6t_rt: unknown flags %X\n", rtinfo
->invflags
);
214 if ((rtinfo
->flags
& (IP6T_RT_RES
| IP6T_RT_FST_MASK
)) &&
215 (!(rtinfo
->flags
& IP6T_RT_TYP
) ||
216 (rtinfo
->rt_type
!= 0) ||
217 (rtinfo
->invflags
& IP6T_RT_INV_TYP
))) {
218 DEBUGP("`--rt-type 0' required before `--rt-0-*'");
225 static struct xt_match rt_match
= {
229 .matchsize
= sizeof(struct ip6t_rt
),
230 .checkentry
= checkentry
,
234 static int __init
ip6t_rt_init(void)
236 return xt_register_match(&rt_match
);
239 static void __exit
ip6t_rt_fini(void)
241 xt_unregister_match(&rt_match
);
244 module_init(ip6t_rt_init
);
245 module_exit(ip6t_rt_fini
);
This page took 0.036062 seconds and 5 git commands to generate.