em_u32.c 1.4 KB

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