cls_cgroup.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #include <net/sock.h>
  18. #ifdef CONFIG_CGROUP_NET_CLASSID
  19. struct cgroup_cls_state {
  20. struct cgroup_subsys_state css;
  21. u32 classid;
  22. };
  23. struct cgroup_cls_state *task_cls_state(struct task_struct *p);
  24. static inline u32 task_cls_classid(struct task_struct *p)
  25. {
  26. u32 classid;
  27. if (in_interrupt())
  28. return 0;
  29. rcu_read_lock();
  30. classid = container_of(task_css(p, net_cls_cgrp_id),
  31. struct cgroup_cls_state, css)->classid;
  32. rcu_read_unlock();
  33. return classid;
  34. }
  35. static inline void sock_update_classid(struct sock *sk)
  36. {
  37. u32 classid;
  38. classid = task_cls_classid(current);
  39. if (classid != sk->sk_classid)
  40. sk->sk_classid = classid;
  41. }
  42. #else /* !CONFIG_CGROUP_NET_CLASSID */
  43. static inline void sock_update_classid(struct sock *sk)
  44. {
  45. }
  46. #endif /* CONFIG_CGROUP_NET_CLASSID */
  47. #endif /* _NET_CLS_CGROUP_H */