act_meta_skbtcindex.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #include <linux/rtnetlink.h>
  25. static int skbtcindex_encode(struct sk_buff *skb, void *skbdata,
  26. struct tcf_meta_info *e)
  27. {
  28. u32 ifetc_index = skb->tc_index;
  29. return ife_encode_meta_u16(ifetc_index, skbdata, e);
  30. }
  31. static int skbtcindex_decode(struct sk_buff *skb, void *data, u16 len)
  32. {
  33. u16 ifetc_index = *(u16 *)data;
  34. skb->tc_index = ntohs(ifetc_index);
  35. return 0;
  36. }
  37. static int skbtcindex_check(struct sk_buff *skb, struct tcf_meta_info *e)
  38. {
  39. return ife_check_meta_u16(skb->tc_index, e);
  40. }
  41. static struct tcf_meta_ops ife_skbtcindex_ops = {
  42. .metaid = IFE_META_TCINDEX,
  43. .metatype = NLA_U16,
  44. .name = "tc_index",
  45. .synopsis = "skb tc_index 16 bit metadata",
  46. .check_presence = skbtcindex_check,
  47. .encode = skbtcindex_encode,
  48. .decode = skbtcindex_decode,
  49. .get = ife_get_meta_u16,
  50. .alloc = ife_alloc_meta_u16,
  51. .release = ife_release_meta_gen,
  52. .validate = ife_validate_meta_u16,
  53. .owner = THIS_MODULE,
  54. };
  55. static int __init ifetc_index_init_module(void)
  56. {
  57. return register_ife_op(&ife_skbtcindex_ops);
  58. }
  59. static void __exit ifetc_index_cleanup_module(void)
  60. {
  61. unregister_ife_op(&ife_skbtcindex_ops);
  62. }
  63. module_init(ifetc_index_init_module);
  64. module_exit(ifetc_index_cleanup_module);
  65. MODULE_AUTHOR("Jamal Hadi Salim(2016)");
  66. MODULE_DESCRIPTION("Inter-FE skb tc_index metadata module");
  67. MODULE_LICENSE("GPL");
  68. MODULE_ALIAS_IFE_META(IFE_META_SKBTCINDEX);