cls_cgroup.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. extern void sock_update_classid(struct sock *sk, struct task_struct *task);
  24. #ifdef 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. #else
  37. extern int net_cls_subsys_id;
  38. static inline u32 task_cls_classid(struct task_struct *p)
  39. {
  40. int id;
  41. u32 classid = 0;
  42. if (in_interrupt())
  43. return 0;
  44. rcu_read_lock();
  45. id = rcu_dereference_index_check(net_cls_subsys_id,
  46. rcu_read_lock_held());
  47. if (id >= 0)
  48. classid = container_of(task_subsys_state(p, id),
  49. struct cgroup_cls_state, css)->classid;
  50. rcu_read_unlock();
  51. return classid;
  52. }
  53. #endif
  54. #else
  55. static inline void sock_update_classid(struct sock *sk)
  56. {
  57. }
  58. static inline u32 task_cls_classid(struct task_struct *p)
  59. {
  60. return 0;
  61. }
  62. #endif
  63. #endif /* _NET_CLS_CGROUP_H */