cls_cgroup.h 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * cls_cgroup.h			Control Group Classifier
 *
 * Authors:	Thomas Graf <tgraf@suug.ch>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 */

#ifndef _NET_CLS_CGROUP_H
#define _NET_CLS_CGROUP_H

#include <linux/cgroup.h>
#include <linux/hardirq.h>
#include <linux/rcupdate.h>

20
#if IS_ENABLED(CONFIG_NET_CLS_CGROUP)
21 22 23 24 25 26
struct cgroup_cls_state
{
	struct cgroup_subsys_state css;
	u32 classid;
};

27
extern void sock_update_classid(struct sock *sk, struct task_struct *task);
28

29
#if IS_BUILTIN(CONFIG_NET_CLS_CGROUP)
30 31
static inline u32 task_cls_classid(struct task_struct *p)
{
32
	u32 classid;
L
Li Zefan 已提交
33

34 35 36
	if (in_interrupt())
		return 0;

L
Li Zefan 已提交
37 38 39 40 41 42
	rcu_read_lock();
	classid = container_of(task_subsys_state(p, net_cls_subsys_id),
			       struct cgroup_cls_state, css)->classid;
	rcu_read_unlock();

	return classid;
43
}
44
#elif IS_MODULE(CONFIG_NET_CLS_CGROUP)
45 46
static inline u32 task_cls_classid(struct task_struct *p)
{
47
	struct cgroup_subsys_state *css;
48
	u32 classid = 0;
49 50 51 52 53

	if (in_interrupt())
		return 0;

	rcu_read_lock();
54 55 56
	css = task_subsys_state(p, net_cls_subsys_id);
	if (css)
		classid = container_of(css,
57 58 59 60 61 62
				       struct cgroup_cls_state, css)->classid;
	rcu_read_unlock();

	return classid;
}
#endif
63
#else /* !CGROUP_NET_CLS_CGROUP */
64 65 66 67
static inline void sock_update_classid(struct sock *sk)
{
}

68 69 70 71
static inline u32 task_cls_classid(struct task_struct *p)
{
	return 0;
}
72
#endif /* CGROUP_NET_CLS_CGROUP */
73
#endif  /* _NET_CLS_CGROUP_H */