12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/types.h>
15 #include <linux/kernel.h>
16 #include <linux/string.h>
17 #include <linux/errno.h>
60 #define ROUTE4_FAILURE ((struct route4_filter *)(-1L))
67 static inline int route4_fastmap_hash(
u32 id,
int iif)
75 spinlock_t *root_lock = qdisc_root_sleeping_lock(q);
77 spin_lock_bh(root_lock);
79 spin_unlock_bh(root_lock);
86 int h = route4_fastmap_hash(
id, iif);
93 static inline int route4_hash_to(
u32 id)
98 static inline int route4_hash_from(
u32 id)
100 return (
id >> 16) & 0xF;
103 static inline int route4_hash_iif(
int iif)
105 return 16 + ((iif >> 16) & 0xF);
108 static inline int route4_hash_wild(
void)
113 #define ROUTE4_APPLY_RESULT() \
116 if (tcf_exts_is_available(&f->exts)) { \
117 int r = tcf_exts_exec(skb, &f->exts, res); \
123 } else if (!dont_cache) \
124 route4_set_fastmap(head, id, iif, f); \
136 int iif, dont_cache = 0;
148 h = route4_fastmap_hash(
id, iif);
159 h = route4_hash_to(
id);
164 for (
f =
b->ht[route4_hash_from(
id)];
f;
f =
f->next)
168 for (
f =
b->ht[route4_hash_iif(iif)];
f;
f =
f->next)
172 for (
f =
b->ht[route4_hash_wild()];
f;
f =
f->next)
197 static inline u32 to_hash(
u32 id)
206 static inline u32 from_hash(
u32 id)
211 if (!(
id & 0x8000)) {
216 return 16 + (
id & 0xF);
229 h1 = to_hash(handle);
233 h2 = from_hash(handle >> 16);
239 for (
f =
b->ht[h2];
f;
f =
f->next)
240 if (
f->handle == handle)
241 return (
unsigned long)
f;
246 static void route4_put(
struct tcf_proto *tp,
unsigned long f)
250 static int route4_init(
struct tcf_proto *tp)
258 tcf_unbind_filter(tp, &f->
res);
263 static void route4_destroy(
struct tcf_proto *tp)
271 for (h1 = 0; h1 <= 256; h1++) {
276 for (h2 = 0; h2 <= 32; h2++) {
279 while ((f = b->
ht[h2]) !=
NULL) {
281 route4_delete_filter(tp, f);
290 static int route4_delete(
struct tcf_proto *tp,
unsigned long arg)
304 for (fp = &b->
ht[from_hash(h >> 16)]; *
fp; fp = &(*fp)->
next) {
310 route4_reset_fastmap(tp->
q, head,
f->id);
311 route4_delete_filter(tp,
f);
315 for (i = 0; i <= 32; i++)
338 static int route4_set_parms(
struct tcf_proto *tp,
unsigned long base,
343 u32 id = 0, to = 0, nhandle = 0x8000;
355 if (
new && handle & 0x8000)
357 to = nla_get_u32(tb[TCA_ROUTE4_TO]);
366 id = nla_get_u32(tb[TCA_ROUTE4_FROM]);
370 }
else if (tb[TCA_ROUTE4_IIF]) {
371 id = nla_get_u32(tb[TCA_ROUTE4_IIF]);
374 nhandle |= (
id | 0x8000) << 16;
376 nhandle |= 0xFFFF << 16;
379 nhandle |= handle & 0x7F00;
380 if (nhandle != handle)
384 h1 = to_hash(nhandle);
396 unsigned int h2 = from_hash(nhandle >> 16);
399 for (fp = b->
ht[h2]; fp; fp = fp->
next)
405 if (tb[TCA_ROUTE4_TO])
408 if (tb[TCA_ROUTE4_FROM])
410 else if (tb[TCA_ROUTE4_IIF])
418 f->
res.classid = nla_get_u32(tb[TCA_ROUTE4_CLASSID]);
419 tcf_bind_filter(tp, &f->
res, base);
430 static int route4_change(
struct sk_buff *in_skb,
431 struct tcf_proto *tp,
unsigned long base,
446 return handle ? -
EINVAL : 0;
454 if (f->
handle != handle && handle)
460 err = route4_set_parms(tp, base, f, handle, head, tb,
483 err = route4_set_parms(tp, base, f, handle, head, tb,
489 h = from_hash(f->
handle >> 16);
490 for (fp = &f->
bkt->ht[h]; (f1 = *fp) !=
NULL; fp = &f1->
next)
498 if (old_handle && f->
handle != old_handle) {
499 th = to_hash(old_handle);
500 h = from_hash(old_handle >> 16);
503 for (fp = &b->
ht[h]; *fp; fp = &(*fp)->
next) {
513 route4_reset_fastmap(tp->
q, head, f->
id);
514 *arg = (
unsigned long)f;
533 for (h = 0; h <= 256; h++) {
537 for (h1 = 0; h1 <= 32; h1++) {
540 for (f = b->
ht[h1]; f; f = f->
next) {
545 if (arg->
fn(tp, (
unsigned long)f, arg) < 0) {
556 static int route4_dump(
struct tcf_proto *tp,
unsigned long fh,
560 unsigned char *b = skb_tail_pointer(skb);
571 goto nla_put_failure;
573 if (!(f->
handle & 0x8000)) {
575 if (nla_put_u32(skb, TCA_ROUTE4_TO,
id))
576 goto nla_put_failure;
578 if (f->
handle & 0x80000000) {
579 if ((f->
handle >> 16) != 0xFFFF &&
580 nla_put_u32(skb, TCA_ROUTE4_IIF, f->
iif))
581 goto nla_put_failure;
584 if (nla_put_u32(skb, TCA_ROUTE4_FROM,
id))
585 goto nla_put_failure;
587 if (f->
res.classid &&
589 goto nla_put_failure;
592 goto nla_put_failure;
594 nla_nest_end(skb, nest);
597 goto nla_put_failure;
608 .classify = route4_classify,
610 .destroy = route4_destroy,
613 .change = route4_change,
614 .delete = route4_delete,
620 static int __init init_route4(
void)
625 static void __exit exit_route4(
void)