blob: 33d03b648646ce04114c73c65853a0b19b548fa4 [file] [log] [blame]
Herbert Xuf8451722010-05-24 00:12:34 -07001/*
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
13#ifndef _NET_CLS_CGROUP_H
14#define _NET_CLS_CGROUP_H
15
16#include <linux/cgroup.h>
17#include <linux/hardirq.h>
18#include <linux/rcupdate.h>
19
Daniel Wagner8fb974c2012-09-12 16:12:02 +020020#if IS_ENABLED(CONFIG_NET_CLS_CGROUP)
Herbert Xuf8451722010-05-24 00:12:34 -070021struct cgroup_cls_state
22{
23 struct cgroup_subsys_state css;
24 u32 classid;
25};
26
Joe Perches37830722013-07-31 17:31:39 -070027void sock_update_classid(struct sock *sk);
Daniel Wagnerf3419802012-09-12 16:12:01 +020028
Daniel Wagner8fb974c2012-09-12 16:12:02 +020029#if IS_BUILTIN(CONFIG_NET_CLS_CGROUP)
Herbert Xuf8451722010-05-24 00:12:34 -070030static inline u32 task_cls_classid(struct task_struct *p)
31{
Daniel Wagner920750c2012-10-25 04:16:56 +000032 u32 classid;
Li Zefan3fb5a992010-09-02 15:42:43 +000033
Herbert Xuf8451722010-05-24 00:12:34 -070034 if (in_interrupt())
35 return 0;
36
Li Zefan3fb5a992010-09-02 15:42:43 +000037 rcu_read_lock();
Tejun Heo8af01f52013-08-08 20:11:22 -040038 classid = container_of(task_css(p, net_cls_subsys_id),
Li Zefan3fb5a992010-09-02 15:42:43 +000039 struct cgroup_cls_state, css)->classid;
40 rcu_read_unlock();
41
42 return classid;
Herbert Xuf8451722010-05-24 00:12:34 -070043}
Daniel Wagner8fb974c2012-09-12 16:12:02 +020044#elif IS_MODULE(CONFIG_NET_CLS_CGROUP)
Herbert Xuf8451722010-05-24 00:12:34 -070045static inline u32 task_cls_classid(struct task_struct *p)
46{
Daniel Wagner8a8e04d2012-09-12 16:12:07 +020047 struct cgroup_subsys_state *css;
Herbert Xuea16f912010-05-25 18:53:57 -070048 u32 classid = 0;
Herbert Xuf8451722010-05-24 00:12:34 -070049
50 if (in_interrupt())
51 return 0;
52
53 rcu_read_lock();
Tejun Heo8af01f52013-08-08 20:11:22 -040054 css = task_css(p, net_cls_subsys_id);
Daniel Wagner8a8e04d2012-09-12 16:12:07 +020055 if (css)
56 classid = container_of(css,
Herbert Xuf8451722010-05-24 00:12:34 -070057 struct cgroup_cls_state, css)->classid;
58 rcu_read_unlock();
59
60 return classid;
61}
62#endif
Daniel Wagner8fb974c2012-09-12 16:12:02 +020063#else /* !CGROUP_NET_CLS_CGROUP */
Zefan Li211d2f972013-04-08 20:03:35 +000064static inline void sock_update_classid(struct sock *sk)
Daniel Wagnerf3419802012-09-12 16:12:01 +020065{
66}
67
Herbert Xuf8451722010-05-24 00:12:34 -070068static inline u32 task_cls_classid(struct task_struct *p)
69{
70 return 0;
71}
Daniel Wagner8fb974c2012-09-12 16:12:02 +020072#endif /* CGROUP_NET_CLS_CGROUP */
Herbert Xuf8451722010-05-24 00:12:34 -070073#endif /* _NET_CLS_CGROUP_H */