blob: 953f1479f7da2d4af4015440fc708ffda9d81670 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * net/sched/em_u32.c U32 Ematch
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Authors: Thomas Graf <tgraf@suug.ch>
10 * Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
11 *
12 * Based on net/sched/cls_u32.c
13 */
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/module.h>
16#include <linux/types.h>
17#include <linux/kernel.h>
18#include <linux/skbuff.h>
19#include <net/pkt_cls.h>
20
21static int em_u32_match(struct sk_buff *skb, struct tcf_ematch *em,
22 struct tcf_pkt_info *info)
23{
24 struct tc_u32_key *key = (struct tc_u32_key *) em->data;
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -070025 const unsigned char *ptr = skb_network_header(skb);
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +090026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 if (info) {
28 if (info->ptr)
29 ptr = info->ptr;
30 ptr += (info->nexthdr & key->offmask);
31 }
32
33 ptr += key->off;
34
35 if (!tcf_valid_offset(skb, ptr, sizeof(u32)))
36 return 0;
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +090037
Al Viro0382b9c2008-03-17 22:46:46 -070038 return !(((*(__be32*) ptr) ^ key->val) & key->mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039}
40
41static struct tcf_ematch_ops em_u32_ops = {
42 .kind = TCF_EM_U32,
43 .datalen = sizeof(struct tc_u32_key),
44 .match = em_u32_match,
45 .owner = THIS_MODULE,
46 .link = LIST_HEAD_INIT(em_u32_ops.link)
47};
48
49static int __init init_em_u32(void)
50{
51 return tcf_em_register(&em_u32_ops);
52}
53
YOSHIFUJI Hideaki10297b92007-02-09 23:25:16 +090054static void __exit exit_em_u32(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
56 tcf_em_unregister(&em_u32_ops);
57}
58
59MODULE_LICENSE("GPL");
60
61module_init(init_em_u32);
62module_exit(exit_em_u32);
Patrick McHardydb3d99c2007-07-11 19:46:26 -070063
64MODULE_ALIAS_TCF_EMATCH(TCF_EM_U32);