act_meta_mark.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * net/sched/act_meta_mark.c IFE skb->mark 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 (2015)
  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 skbmark_encode(struct sk_buff *skb, void *skbdata,
  26. struct tcf_meta_info *e)
  27. {
  28. u32 ifemark = skb->mark;
  29. return ife_encode_meta_u32(ifemark, skbdata, e);
  30. }
  31. static int skbmark_decode(struct sk_buff *skb, void *data, u16 len)
  32. {
  33. u32 ifemark = *(u32 *)data;
  34. skb->mark = ntohl(ifemark);
  35. return 0;
  36. }
  37. static int skbmark_check(struct sk_buff *skb, struct tcf_meta_info *e)
  38. {
  39. return ife_check_meta_u32(skb->mark, e);
  40. }
  41. static struct tcf_meta_ops ife_skbmark_ops = {
  42. .metaid = IFE_META_SKBMARK,
  43. .metatype = NLA_U32,
  44. .name = "skbmark",
  45. .synopsis = "skb mark 32 bit metadata",
  46. .check_presence = skbmark_check,
  47. .encode = skbmark_encode,
  48. .decode = skbmark_decode,
  49. .get = ife_get_meta_u32,
  50. .alloc = ife_alloc_meta_u32,
  51. .release = ife_release_meta_gen,
  52. .validate = ife_validate_meta_u32,
  53. .owner = THIS_MODULE,
  54. };
  55. static int __init ifemark_init_module(void)
  56. {
  57. return register_ife_op(&ife_skbmark_ops);
  58. }
  59. static void __exit ifemark_cleanup_module(void)
  60. {
  61. unregister_ife_op(&ife_skbmark_ops);
  62. }
  63. module_init(ifemark_init_module);
  64. module_exit(ifemark_cleanup_module);
  65. MODULE_AUTHOR("Jamal Hadi Salim(2015)");
  66. MODULE_DESCRIPTION("Inter-FE skb mark metadata module");
  67. MODULE_LICENSE("GPL");
  68. MODULE_ALIAS_IFE_META(IFE_META_SKBMARK);