em_u32.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  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. #include <linux/config.h>
  15. #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. static int em_u32_match(struct sk_buff *skb, struct tcf_ematch *em,
  21. struct tcf_pkt_info *info)
  22. {
  23. struct tc_u32_key *key = (struct tc_u32_key *) em->data;
  24. unsigned char *ptr = skb->nh.raw;
  25. if (info) {
  26. if (info->ptr)
  27. ptr = info->ptr;
  28. ptr += (info->nexthdr & key->offmask);
  29. }
  30. ptr += key->off;
  31. if (!tcf_valid_offset(skb, ptr, sizeof(u32)))
  32. return 0;
  33. return !(((*(u32*) ptr) ^ key->val) & key->mask);
  34. }
  35. static struct tcf_ematch_ops em_u32_ops = {
  36. .kind = TCF_EM_U32,
  37. .datalen = sizeof(struct tc_u32_key),
  38. .match = em_u32_match,
  39. .owner = THIS_MODULE,
  40. .link = LIST_HEAD_INIT(em_u32_ops.link)
  41. };
  42. static int __init init_em_u32(void)
  43. {
  44. return tcf_em_register(&em_u32_ops);
  45. }
  46. static void __exit exit_em_u32(void)
  47. {
  48. tcf_em_unregister(&em_u32_ops);
  49. }
  50. MODULE_LICENSE("GPL");
  51. module_init(init_em_u32);
  52. module_exit(exit_em_u32);