cls_cgroup.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. if (in_interrupt())
  27. return 0;
  28. return container_of(task_subsys_state(p, net_cls_subsys_id),
  29. struct cgroup_cls_state, css)->classid;
  30. }
  31. #else
  32. extern int net_cls_subsys_id;
  33. static inline u32 task_cls_classid(struct task_struct *p)
  34. {
  35. int id;
  36. u32 classid = 0;
  37. if (in_interrupt())
  38. return 0;
  39. rcu_read_lock();
  40. id = rcu_dereference_index_check(net_cls_subsys_id,
  41. rcu_read_lock_held());
  42. if (id >= 0)
  43. classid = container_of(task_subsys_state(p, id),
  44. struct cgroup_cls_state, css)->classid;
  45. rcu_read_unlock();
  46. return classid;
  47. }
  48. #endif
  49. #else
  50. static inline u32 task_cls_classid(struct task_struct *p)
  51. {
  52. return 0;
  53. }
  54. #endif
  55. #endif /* _NET_CLS_CGROUP_H */