cls_cgroup.h 1.4 KB

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