em_u32.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * net/sched/em_u32.c U32 Ematch
  4. *
  5. * Authors: Thomas Graf <[email protected]>
  6. * Alexey Kuznetsov, <[email protected]>
  7. *
  8. * Based on net/sched/cls_u32.c
  9. */
  10. #include <linux/module.h>
  11. #include <linux/types.h>
  12. #include <linux/kernel.h>
  13. #include <linux/skbuff.h>
  14. #include <net/pkt_cls.h>
  15. static int em_u32_match(struct sk_buff *skb, struct tcf_ematch *em,
  16. struct tcf_pkt_info *info)
  17. {
  18. struct tc_u32_key *key = (struct tc_u32_key *) em->data;
  19. const unsigned char *ptr = skb_network_header(skb);
  20. if (info) {
  21. if (info->ptr)
  22. ptr = info->ptr;
  23. ptr += (info->nexthdr & key->offmask);
  24. }
  25. ptr += key->off;
  26. if (!tcf_valid_offset(skb, ptr, sizeof(u32)))
  27. return 0;
  28. return !(((*(__be32 *) ptr) ^ key->val) & key->mask);
  29. }
  30. static struct tcf_ematch_ops em_u32_ops = {
  31. .kind = TCF_EM_U32,
  32. .datalen = sizeof(struct tc_u32_key),
  33. .match = em_u32_match,
  34. .owner = THIS_MODULE,
  35. .link = LIST_HEAD_INIT(em_u32_ops.link)
  36. };
  37. static int __init init_em_u32(void)
  38. {
  39. return tcf_em_register(&em_u32_ops);
  40. }
  41. static void __exit exit_em_u32(void)
  42. {
  43. tcf_em_unregister(&em_u32_ops);
  44. }
  45. MODULE_LICENSE("GPL");
  46. module_init(init_em_u32);
  47. module_exit(exit_em_u32);
  48. MODULE_ALIAS_TCF_EMATCH(TCF_EM_U32);