act_meta_skbtcindex.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * net/sched/act_meta_tc_index.c IFE skb->tc_index metadata module
  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. * copyright Jamal Hadi Salim (2016)
  10. *
  11. */
  12. #include <linux/types.h>
  13. #include <linux/kernel.h>
  14. #include <linux/string.h>
  15. #include <linux/errno.h>
  16. #include <linux/skbuff.h>
  17. #include <linux/rtnetlink.h>
  18. #include <linux/module.h>
  19. #include <linux/init.h>
  20. #include <net/netlink.h>
  21. #include <net/pkt_sched.h>
  22. #include <uapi/linux/tc_act/tc_ife.h>
  23. #include <net/tc_act/tc_ife.h>
  24. static int skbtcindex_encode(struct sk_buff *skb, void *skbdata,
  25. struct tcf_meta_info *e)
  26. {
  27. u32 ifetc_index = skb->tc_index;
  28. return ife_encode_meta_u16(ifetc_index, skbdata, e);
  29. }
  30. static int skbtcindex_decode(struct sk_buff *skb, void *data, u16 len)
  31. {
  32. u16 ifetc_index = *(u16 *)data;
  33. skb->tc_index = ntohs(ifetc_index);
  34. return 0;
  35. }
  36. static int skbtcindex_check(struct sk_buff *skb, struct tcf_meta_info *e)
  37. {
  38. return ife_check_meta_u16(skb->tc_index, e);
  39. }
  40. static struct tcf_meta_ops ife_skbtcindex_ops = {
  41. .metaid = IFE_META_TCINDEX,
  42. .metatype = NLA_U16,
  43. .name = "tc_index",
  44. .synopsis = "skb tc_index 16 bit metadata",
  45. .check_presence = skbtcindex_check,
  46. .encode = skbtcindex_encode,
  47. .decode = skbtcindex_decode,
  48. .get = ife_get_meta_u16,
  49. .alloc = ife_alloc_meta_u16,
  50. .release = ife_release_meta_gen,
  51. .validate = ife_validate_meta_u16,
  52. .owner = THIS_MODULE,
  53. };
  54. static int __init ifetc_index_init_module(void)
  55. {
  56. return register_ife_op(&ife_skbtcindex_ops);
  57. }
  58. static void __exit ifetc_index_cleanup_module(void)
  59. {
  60. unregister_ife_op(&ife_skbtcindex_ops);
  61. }
  62. module_init(ifetc_index_init_module);
  63. module_exit(ifetc_index_cleanup_module);
  64. MODULE_AUTHOR("Jamal Hadi Salim(2016)");
  65. MODULE_DESCRIPTION("Inter-FE skb tc_index metadata module");
  66. MODULE_LICENSE("GPL");
  67. MODULE_ALIAS_IFE_META("tcindex");