cls_cgroup.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * cls_cgroup.h Control Group Classifier
  3. *
  4. * Authors: Thomas Graf <tgraf@suug.ch>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. *
  11. */
  12. #ifndef _NET_CLS_CGROUP_H
  13. #define _NET_CLS_CGROUP_H
  14. #include <linux/cgroup.h>
  15. #include <linux/hardirq.h>
  16. #include <linux/rcupdate.h>
  17. #if IS_ENABLED(CONFIG_NET_CLS_CGROUP)
  18. struct cgroup_cls_state
  19. {
  20. struct cgroup_subsys_state css;
  21. u32 classid;
  22. };
  23. extern void sock_update_classid(struct sock *sk);
  24. #if IS_BUILTIN(CONFIG_NET_CLS_CGROUP)
  25. static inline u32 task_cls_classid(struct task_struct *p)
  26. {
  27. int classid;
  28. if (in_interrupt())
  29. return 0;
  30. rcu_read_lock();
  31. classid = container_of(task_subsys_state(p, net_cls_subsys_id),
  32. struct cgroup_cls_state, css)->classid;
  33. rcu_read_unlock();
  34. return classid;
  35. }
  36. #elif IS_MODULE(CONFIG_NET_CLS_CGROUP)
  37. static inline u32 task_cls_classid(struct task_struct *p)
  38. {
  39. struct cgroup_subsys_state *css;
  40. u32 classid = 0;
  41. if (in_interrupt())
  42. return 0;
  43. rcu_read_lock();
  44. css = task_subsys_state(p, net_cls_subsys_id);
  45. if (css)
  46. classid = container_of(css,
  47. struct cgroup_cls_state, css)->classid;
  48. rcu_read_unlock();
  49. return classid;
  50. }
  51. #endif
  52. #else /* !CGROUP_NET_CLS_CGROUP */
  53. static inline void sock_update_classid(struct sock *sk)
  54. {
  55. }
  56. static inline u32 task_cls_classid(struct task_struct *p)
  57. {
  58. return 0;
  59. }
  60. #endif /* CGROUP_NET_CLS_CGROUP */
  61. #endif /* _NET_CLS_CGROUP_H */