cls_cgroup.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #ifdef CONFIG_CGROUPS
  18. struct cgroup_cls_state
  19. {
  20. struct cgroup_subsys_state css;
  21. u32 classid;
  22. };
  23. #ifdef CONFIG_NET_CLS_CGROUP
  24. static inline u32 task_cls_classid(struct task_struct *p)
  25. {
  26. int classid;
  27. if (in_interrupt())
  28. return 0;
  29. rcu_read_lock();
  30. classid = container_of(task_subsys_state(p, net_cls_subsys_id),
  31. struct cgroup_cls_state, css)->classid;
  32. rcu_read_unlock();
  33. return classid;
  34. }
  35. #else
  36. extern int net_cls_subsys_id;
  37. static inline u32 task_cls_classid(struct task_struct *p)
  38. {
  39. int id;
  40. u32 classid = 0;
  41. if (in_interrupt())
  42. return 0;
  43. rcu_read_lock();
  44. id = rcu_dereference_index_check(net_cls_subsys_id,
  45. rcu_read_lock_held());
  46. if (id >= 0)
  47. classid = container_of(task_subsys_state(p, id),
  48. struct cgroup_cls_state, css)->classid;
  49. rcu_read_unlock();
  50. return classid;
  51. }
  52. #endif
  53. #else
  54. static inline u32 task_cls_classid(struct task_struct *p)
  55. {
  56. return 0;
  57. }
  58. #endif
  59. #endif /* _NET_CLS_CGROUP_H */