blob: 9d446f136607e54cd041e57474e608f09d4278ef [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __NET_ACT_API_H
2#define __NET_ACT_API_H
3
4/*
5 * Public police action API for classifiers/qdiscs
6 */
7
8#include <net/sch_generic.h>
9#include <net/pkt_sched.h>
10
David S. Millere9ce1cd2006-08-21 23:54:55 -070011struct tcf_common {
WANG Cong89819dc2013-12-15 20:15:09 -080012 struct hlist_node tcfc_head;
David S. Millere9ce1cd2006-08-21 23:54:55 -070013 u32 tcfc_index;
14 int tcfc_refcnt;
15 int tcfc_bindcnt;
16 u32 tcfc_capab;
17 int tcfc_action;
18 struct tcf_t tcfc_tm;
Eric Dumazetc1a8f1f2009-08-16 09:36:49 +000019 struct gnet_stats_basic_packed tcfc_bstats;
David S. Millere9ce1cd2006-08-21 23:54:55 -070020 struct gnet_stats_queue tcfc_qstats;
Eric Dumazet45203a32013-06-06 08:43:22 -070021 struct gnet_stats_rate_est64 tcfc_rate_est;
David S. Millere9ce1cd2006-08-21 23:54:55 -070022 spinlock_t tcfc_lock;
Eric Dumazetc7de2cf2010-06-09 02:09:23 +000023 struct rcu_head tcfc_rcu;
Eric Dumazet519c8182015-07-06 05:18:04 -070024 struct gnet_stats_basic_cpu __percpu *cpu_bstats;
25 struct gnet_stats_queue __percpu *cpu_qstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026};
WANG Cong89819dc2013-12-15 20:15:09 -080027#define tcf_head common.tcfc_head
David S. Millere9ce1cd2006-08-21 23:54:55 -070028#define tcf_index common.tcfc_index
29#define tcf_refcnt common.tcfc_refcnt
30#define tcf_bindcnt common.tcfc_bindcnt
31#define tcf_capab common.tcfc_capab
32#define tcf_action common.tcfc_action
33#define tcf_tm common.tcfc_tm
34#define tcf_bstats common.tcfc_bstats
35#define tcf_qstats common.tcfc_qstats
36#define tcf_rate_est common.tcfc_rate_est
David S. Millere9ce1cd2006-08-21 23:54:55 -070037#define tcf_lock common.tcfc_lock
Eric Dumazetc7de2cf2010-06-09 02:09:23 +000038#define tcf_rcu common.tcfc_rcu
David S. Millere9ce1cd2006-08-21 23:54:55 -070039
David S. Millere9ce1cd2006-08-21 23:54:55 -070040struct tcf_hashinfo {
WANG Cong89819dc2013-12-15 20:15:09 -080041 struct hlist_head *htab;
David S. Millere9ce1cd2006-08-21 23:54:55 -070042 unsigned int hmask;
WANG Cong89819dc2013-12-15 20:15:09 -080043 spinlock_t lock;
WANG Congddafd342014-01-09 16:13:59 -080044 u32 index;
David S. Millere9ce1cd2006-08-21 23:54:55 -070045};
46
47static inline unsigned int tcf_hash(u32 index, unsigned int hmask)
48{
49 return index & hmask;
50}
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
WANG Cong369ba562013-12-15 20:15:08 -080052static inline int tcf_hashinfo_init(struct tcf_hashinfo *hf, unsigned int mask)
53{
WANG Cong89819dc2013-12-15 20:15:09 -080054 int i;
55
56 spin_lock_init(&hf->lock);
WANG Congddafd342014-01-09 16:13:59 -080057 hf->index = 0;
WANG Cong369ba562013-12-15 20:15:08 -080058 hf->hmask = mask;
WANG Cong89819dc2013-12-15 20:15:09 -080059 hf->htab = kzalloc((mask + 1) * sizeof(struct hlist_head),
WANG Cong369ba562013-12-15 20:15:08 -080060 GFP_KERNEL);
61 if (!hf->htab)
62 return -ENOMEM;
WANG Cong89819dc2013-12-15 20:15:09 -080063 for (i = 0; i < mask + 1; i++)
64 INIT_HLIST_HEAD(&hf->htab[i]);
WANG Cong369ba562013-12-15 20:15:08 -080065 return 0;
66}
67
68static inline void tcf_hashinfo_destroy(struct tcf_hashinfo *hf)
69{
70 kfree(hf->htab);
71}
72
Eric Dumazet56e5d1c2015-07-06 05:18:08 -070073/* Update lastuse only if needed, to avoid dirtying a cache line.
74 * We use a temp variable to avoid fetching jiffies twice.
75 */
76static inline void tcf_lastuse_update(struct tcf_t *tm)
77{
78 unsigned long now = jiffies;
79
80 if (tm->lastuse != now)
81 tm->lastuse = now;
82}
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#ifdef CONFIG_NET_CLS_ACT
85
86#define ACT_P_CREATED 1
87#define ACT_P_DELETED 1
88
David S. Millere9ce1cd2006-08-21 23:54:55 -070089struct tc_action {
90 void *priv;
Eric Dumazetdc7f9f62011-07-05 23:25:42 +000091 const struct tc_action_ops *ops;
David S. Millere9ce1cd2006-08-21 23:54:55 -070092 __u32 type; /* for backward compat(TCA_OLD_COMPAT) */
93 __u32 order;
WANG Cong33be6272013-12-15 20:15:05 -080094 struct list_head list;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095};
96
David S. Millere9ce1cd2006-08-21 23:54:55 -070097struct tc_action_ops {
WANG Cong1f747c22013-12-15 20:15:10 -080098 struct list_head head;
David S. Millere9ce1cd2006-08-21 23:54:55 -070099 struct tcf_hashinfo *hinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 char kind[IFNAMSIZ];
101 __u32 type; /* TBD to match kind */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 struct module *owner;
Eric Dumazetdc7f9f62011-07-05 23:25:42 +0000103 int (*act)(struct sk_buff *, const struct tc_action *, struct tcf_result *);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700104 int (*dump)(struct sk_buff *, struct tc_action *, int, int);
WANG Conga5b5c952014-02-11 17:07:32 -0800105 void (*cleanup)(struct tc_action *, int bind);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700106 int (*lookup)(struct tc_action *, u32);
Benjamin LaHaisec1b52732013-01-14 05:15:39 +0000107 int (*init)(struct net *net, struct nlattr *nla,
108 struct nlattr *est, struct tc_action *act, int ovr,
109 int bind);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700110 int (*walk)(struct sk_buff *, struct netlink_callback *, int, struct tc_action *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111};
112
WANG Cong6e6a50c2014-01-17 11:37:03 -0800113int tcf_hash_search(struct tc_action *a, u32 index);
WANG Congddafd342014-01-09 16:13:59 -0800114u32 tcf_hash_new_index(struct tcf_hashinfo *hinfo);
WANG Cong86062032014-02-11 17:07:31 -0800115int tcf_hash_check(u32 index, struct tc_action *a, int bind);
116int tcf_hash_create(u32 index, struct nlattr *est, struct tc_action *a,
Eric Dumazet519c8182015-07-06 05:18:04 -0700117 int size, int bind, bool cpustats);
WANG Cong86062032014-02-11 17:07:31 -0800118void tcf_hash_cleanup(struct tc_action *a, struct nlattr *est);
119void tcf_hash_insert(struct tc_action *a);
David S. Millere9ce1cd2006-08-21 23:54:55 -0700120
Daniel Borkmann28e6b672015-07-29 23:35:25 +0200121int __tcf_hash_release(struct tc_action *a, bool bind, bool strict);
122
123static inline int tcf_hash_release(struct tc_action *a, bool bind)
124{
125 return __tcf_hash_release(a, bind, false);
126}
127
WANG Cong4f1e9d82014-02-11 17:07:33 -0800128int tcf_register_action(struct tc_action_ops *a, unsigned int mask);
Joe Perches5c152572013-07-30 22:47:13 -0700129int tcf_unregister_action(struct tc_action_ops *a);
WANG Cong55334a52014-02-11 17:07:34 -0800130int tcf_action_destroy(struct list_head *actions, int bind);
WANG Cong33be6272013-12-15 20:15:05 -0800131int tcf_action_exec(struct sk_buff *skb, const struct list_head *actions,
Joe Perches5c152572013-07-30 22:47:13 -0700132 struct tcf_result *res);
WANG Cong33be6272013-12-15 20:15:05 -0800133int tcf_action_init(struct net *net, struct nlattr *nla,
Joe Perches5c152572013-07-30 22:47:13 -0700134 struct nlattr *est, char *n, int ovr,
WANG Cong33be6272013-12-15 20:15:05 -0800135 int bind, struct list_head *);
Joe Perches5c152572013-07-30 22:47:13 -0700136struct tc_action *tcf_action_init_1(struct net *net, struct nlattr *nla,
137 struct nlattr *est, char *n, int ovr,
138 int bind);
WANG Cong33be6272013-12-15 20:15:05 -0800139int tcf_action_dump(struct sk_buff *skb, struct list_head *, int, int);
Joe Perches5c152572013-07-30 22:47:13 -0700140int tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int, int);
141int tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int, int);
142int tcf_action_copy_stats(struct sk_buff *, struct tc_action *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143#endif /* CONFIG_NET_CLS_ACT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#endif