act_meta_skbprio.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * net/sched/act_meta_prio.c IFE skb->priority 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. static int skbprio_check(struct sk_buff *skb, struct tcf_meta_info *e)
  25. {
  26. return ife_check_meta_u32(skb->priority, e);
  27. }
  28. static int skbprio_encode(struct sk_buff *skb, void *skbdata,
  29. struct tcf_meta_info *e)
  30. {
  31. u32 ifeprio = skb->priority; /* avoid having to cast skb->priority*/
  32. return ife_encode_meta_u32(ifeprio, skbdata, e);
  33. }
  34. static int skbprio_decode(struct sk_buff *skb, void *data, u16 len)
  35. {
  36. u32 ifeprio = *(u32 *)data;
  37. skb->priority = ntohl(ifeprio);
  38. return 0;
  39. }
  40. static struct tcf_meta_ops ife_prio_ops = {
  41. .metaid = IFE_META_PRIO,
  42. .metatype = NLA_U32,
  43. .name = "skbprio",
  44. .synopsis = "skb prio metadata",
  45. .check_presence = skbprio_check,
  46. .encode = skbprio_encode,
  47. .decode = skbprio_decode,
  48. .get = ife_get_meta_u32,
  49. .alloc = ife_alloc_meta_u32,
  50. .owner = THIS_MODULE,
  51. };
  52. static int __init ifeprio_init_module(void)
  53. {
  54. return register_ife_op(&ife_prio_ops);
  55. }
  56. static void __exit ifeprio_cleanup_module(void)
  57. {
  58. unregister_ife_op(&ife_prio_ops);
  59. }
  60. module_init(ifeprio_init_module);
  61. module_exit(ifeprio_cleanup_module);
  62. MODULE_AUTHOR("Jamal Hadi Salim(2015)");
  63. MODULE_DESCRIPTION("Inter-FE skb prio metadata action");
  64. MODULE_LICENSE("GPL");
  65. MODULE_ALIAS_IFE_META("skbprio");