1 #ifndef __NET_PKT_ACT_H
2 #define __NET_PKT_ACT_H
4 #include <asm/uaccess.h>
5 #include <asm/system.h>
6 #include <linux/bitops.h>
7 #include <linux/config.h>
8 #include <linux/types.h>
9 #include <linux/kernel.h>
10 #include <linux/sched.h>
11 #include <linux/string.h>
13 #include <linux/socket.h>
14 #include <linux/sockios.h>
16 #include <linux/errno.h>
17 #include <linux/interrupt.h>
18 #include <linux/skbuff.h>
19 #include <linux/rtnetlink.h>
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/proc_fs.h>
24 #include <net/pkt_sched.h>
26 #define tca_st(val) (struct tcf_##val *)
27 #define PRIV(a,name) ( tca_st(name) (a)->priv)
30 #define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
32 #define DPRINTK(format,args...)
36 #define D2PRINTK(format,args...) printk(KERN_DEBUG format,##args)
38 #define D2PRINTK(format,args...)
41 static __inline__ unsigned
44 return index & MY_TAB_MASK;
47 /* probably move this from being inline
48 * and put into act_generic
51 tcf_hash_destroy(struct tcf_st *p)
53 unsigned h = tcf_hash(p->index);
56 for (p1p = &tcf_ht[h]; *p1p; p1p = &(*p1p)->next) {
58 write_lock_bh(&tcf_t_lock);
60 write_unlock_bh(&tcf_t_lock);
61 #ifdef CONFIG_NET_ESTIMATOR
62 gen_kill_estimator(&p->bstats, &p->rate_est);
72 tcf_hash_release(struct tcf_st *p, int bind )
80 if(p->bindcnt <=0 && p->refcnt <= 0) {
89 tcf_dump_walker(struct sk_buff *skb, struct netlink_callback *cb,
93 int err =0, index = -1,i= 0, s_i = 0, n_i = 0;
96 read_lock(&tcf_t_lock);
100 for (i = 0; i < MY_TAB_SIZE; i++) {
101 p = tcf_ht[tcf_hash(i)];
103 for (; p; p = p->next) {
109 r = (struct rtattr*) skb->tail;
110 RTA_PUT(skb, a->order, 0, NULL);
111 err = tcf_action_dump_1(skb, a, 0, 0);
114 skb_trim(skb, (u8*)r - skb->data);
117 r->rta_len = skb->tail - (u8*)r;
119 if (n_i >= TCA_ACT_MAX_PRIO) {
125 read_unlock(&tcf_t_lock);
131 skb_trim(skb, (u8*)r - skb->data);
135 static __inline__ int
136 tcf_del_walker(struct sk_buff *skb, struct tc_action *a)
138 struct tcf_st *p, *s_p;
142 r = (struct rtattr*) skb->tail;
143 RTA_PUT(skb, a->order, 0, NULL);
144 RTA_PUT(skb, TCA_KIND, IFNAMSIZ, a->ops->kind);
145 for (i = 0; i < MY_TAB_SIZE; i++) {
146 p = tcf_ht[tcf_hash(i)];
150 if (ACT_P_DELETED == tcf_hash_release(p, 0)) {
151 module_put(a->ops->owner);
157 RTA_PUT(skb, TCA_FCNT, 4, &n_i);
158 r->rta_len = skb->tail - (u8*)r;
162 skb_trim(skb, (u8*)r - skb->data);
166 static __inline__ int
167 tcf_generic_walker(struct sk_buff *skb, struct netlink_callback *cb, int type,
170 if (type == RTM_DELACTION) {
171 return tcf_del_walker(skb,a);
172 } else if (type == RTM_GETACTION) {
173 return tcf_dump_walker(skb,cb,a);
175 printk("tcf_generic_walker: unknown action %d\n",type);
180 static __inline__ struct tcf_st *
181 tcf_hash_lookup(u32 index)
185 read_lock(&tcf_t_lock);
186 for (p = tcf_ht[tcf_hash(index)]; p; p = p->next) {
187 if (p->index == index)
190 read_unlock(&tcf_t_lock);
194 static __inline__ u32
195 tcf_hash_new_index(void)
200 } while (tcf_hash_lookup(idx_gen));
207 tcf_hash_search(struct tc_action *a, u32 index)
209 struct tcf_st *p = tcf_hash_lookup(index);
218 #ifdef CONFIG_NET_ACT_INIT
219 static inline struct tcf_st *
220 tcf_hash_check(u32 index, struct tc_action *a, int ovr, int bind)
222 struct tcf_st *p = NULL;
223 if (index && (p = tcf_hash_lookup(index)) != NULL) {
233 static inline struct tcf_st *
234 tcf_hash_create(u32 index, struct rtattr *est, struct tc_action *a, int size, int ovr, int bind)
236 struct tcf_st *p = NULL;
238 p = kmalloc(size, GFP_KERNEL);
249 spin_lock_init(&p->lock);
250 p->stats_lock = &p->lock;
251 p->index = index ? : tcf_hash_new_index();
252 p->tm.install = jiffies;
253 p->tm.lastuse = jiffies;
254 #ifdef CONFIG_NET_ESTIMATOR
256 gen_new_estimator(&p->bstats, &p->rate_est, p->stats_lock, est);
258 a->priv = (void *) p;
262 static inline void tcf_hash_insert(struct tcf_st *p)
264 unsigned h = tcf_hash(p->index);
266 write_lock_bh(&tcf_t_lock);
269 write_unlock_bh(&tcf_t_lock);