cls_cgroup.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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(net_cls_subsys_id);
  41. if (id >= 0)
  42. classid = container_of(task_subsys_state(p, id),
  43. struct cgroup_cls_state, css)->classid;
  44. rcu_read_unlock();
  45. return classid;
  46. }
  47. #endif
  48. #else
  49. static inline u32 task_cls_classid(struct task_struct *p)
  50. {
  51. return 0;
  52. }
  53. #endif
  54. #endif /* _NET_CLS_CGROUP_H */