1f8451725SHerbert Xu /* 2f8451725SHerbert Xu * cls_cgroup.h Control Group Classifier 3f8451725SHerbert Xu * 4f8451725SHerbert Xu * Authors: Thomas Graf <tgraf@suug.ch> 5f8451725SHerbert Xu * 6f8451725SHerbert Xu * This program is free software; you can redistribute it and/or modify it 7f8451725SHerbert Xu * under the terms of the GNU General Public License as published by the Free 8f8451725SHerbert Xu * Software Foundation; either version 2 of the License, or (at your option) 9f8451725SHerbert Xu * any later version. 10f8451725SHerbert Xu * 11f8451725SHerbert Xu */ 12f8451725SHerbert Xu 13f8451725SHerbert Xu #ifndef _NET_CLS_CGROUP_H 14f8451725SHerbert Xu #define _NET_CLS_CGROUP_H 15f8451725SHerbert Xu 16f8451725SHerbert Xu #include <linux/cgroup.h> 17f8451725SHerbert Xu #include <linux/hardirq.h> 18f8451725SHerbert Xu #include <linux/rcupdate.h> 19f8451725SHerbert Xu 20f8451725SHerbert Xu #ifdef CONFIG_CGROUPS 21f8451725SHerbert Xu struct cgroup_cls_state 22f8451725SHerbert Xu { 23f8451725SHerbert Xu struct cgroup_subsys_state css; 24f8451725SHerbert Xu u32 classid; 25f8451725SHerbert Xu }; 26f8451725SHerbert Xu 27*f3419807SDaniel Wagner extern void sock_update_classid(struct sock *sk); 28*f3419807SDaniel Wagner 29f8451725SHerbert Xu #ifdef CONFIG_NET_CLS_CGROUP 30f8451725SHerbert Xu static inline u32 task_cls_classid(struct task_struct *p) 31f8451725SHerbert Xu { 323fb5a991SLi Zefan int classid; 333fb5a991SLi Zefan 34f8451725SHerbert Xu if (in_interrupt()) 35f8451725SHerbert Xu return 0; 36f8451725SHerbert Xu 373fb5a991SLi Zefan rcu_read_lock(); 383fb5a991SLi Zefan classid = container_of(task_subsys_state(p, net_cls_subsys_id), 39937eada4SHerbert Xu struct cgroup_cls_state, css)->classid; 403fb5a991SLi Zefan rcu_read_unlock(); 413fb5a991SLi Zefan 423fb5a991SLi Zefan return classid; 43f8451725SHerbert Xu } 44f8451725SHerbert Xu #else 45f8451725SHerbert Xu extern int net_cls_subsys_id; 46f8451725SHerbert Xu 47f8451725SHerbert Xu static inline u32 task_cls_classid(struct task_struct *p) 48f8451725SHerbert Xu { 49f8451725SHerbert Xu int id; 50ea16f912SHerbert Xu u32 classid = 0; 51f8451725SHerbert Xu 52f8451725SHerbert Xu if (in_interrupt()) 53f8451725SHerbert Xu return 0; 54f8451725SHerbert Xu 55f8451725SHerbert Xu rcu_read_lock(); 56d34a1666SPaul E. McKenney id = rcu_dereference_index_check(net_cls_subsys_id, 57d34a1666SPaul E. McKenney rcu_read_lock_held()); 58f8451725SHerbert Xu if (id >= 0) 59f8451725SHerbert Xu classid = container_of(task_subsys_state(p, id), 60f8451725SHerbert Xu struct cgroup_cls_state, css)->classid; 61f8451725SHerbert Xu rcu_read_unlock(); 62f8451725SHerbert Xu 63f8451725SHerbert Xu return classid; 64f8451725SHerbert Xu } 65f8451725SHerbert Xu #endif 66f8451725SHerbert Xu #else 67*f3419807SDaniel Wagner static inline void sock_update_classid(struct sock *sk) 68*f3419807SDaniel Wagner { 69*f3419807SDaniel Wagner } 70*f3419807SDaniel Wagner 71f8451725SHerbert Xu static inline u32 task_cls_classid(struct task_struct *p) 72f8451725SHerbert Xu { 73f8451725SHerbert Xu return 0; 74f8451725SHerbert Xu } 75f8451725SHerbert Xu #endif 76f8451725SHerbert Xu #endif /* _NET_CLS_CGROUP_H */ 77