2 * include/net/act_generic.h
7 static inline int tcf_defact_release(struct tcf_defact
*p
, int bind
)
15 if (p
->bindcnt
<= 0 && p
->refcnt
<= 0) {
25 alloc_defdata(struct tcf_defact
*p
, u32 datalen
, void *defdata
)
27 p
->defdata
= kmalloc(datalen
, GFP_KERNEL
);
28 if (p
->defdata
== NULL
)
31 memcpy(p
->defdata
, defdata
, datalen
);
36 realloc_defdata(struct tcf_defact
*p
, u32 datalen
, void *defdata
)
38 /* safer to be just brute force for now */
40 return alloc_defdata(p
, datalen
, defdata
);
44 tcf_defact_init(struct rtattr
*rta
, struct rtattr
*est
,
45 struct tc_action
*a
, int ovr
, int bind
)
47 struct rtattr
*tb
[TCA_DEF_MAX
];
48 struct tc_defact
*parm
;
54 if (rta
== NULL
|| rtattr_parse_nested(tb
, TCA_DEF_MAX
, rta
) < 0)
57 if (tb
[TCA_DEF_PARMS
- 1] == NULL
||
58 RTA_PAYLOAD(tb
[TCA_DEF_PARMS
- 1]) < sizeof(*parm
))
61 parm
= RTA_DATA(tb
[TCA_DEF_PARMS
- 1]);
62 defdata
= RTA_DATA(tb
[TCA_DEF_DATA
- 1]);
66 datalen
= RTA_PAYLOAD(tb
[TCA_DEF_DATA
- 1]);
70 p
= tcf_hash_check(parm
->index
, a
, ovr
, bind
);
72 p
= tcf_hash_create(parm
->index
, est
, a
, sizeof(*p
), ovr
, bind
);
76 ret
= alloc_defdata(p
, datalen
, defdata
);
84 tcf_defact_release(p
, bind
);
87 realloc_defdata(p
, datalen
, defdata
);
90 spin_lock_bh(&p
->lock
);
91 p
->action
= parm
->action
;
92 spin_unlock_bh(&p
->lock
);
93 if (ret
== ACT_P_CREATED
)
98 static inline int tcf_defact_cleanup(struct tc_action
*a
, int bind
)
100 struct tcf_defact
*p
= PRIV(a
, defact
);
103 return tcf_defact_release(p
, bind
);
108 tcf_defact_dump(struct sk_buff
*skb
, struct tc_action
*a
, int bind
, int ref
)
110 unsigned char *b
= skb
->tail
;
111 struct tc_defact opt
;
112 struct tcf_defact
*p
= PRIV(a
, defact
);
115 opt
.index
= p
->index
;
116 opt
.refcnt
= p
->refcnt
- ref
;
117 opt
.bindcnt
= p
->bindcnt
- bind
;
118 opt
.action
= p
->action
;
119 RTA_PUT(skb
, TCA_DEF_PARMS
, sizeof(opt
), &opt
);
120 RTA_PUT(skb
, TCA_DEF_DATA
, p
->datalen
, p
->defdata
);
121 t
.install
= jiffies_to_clock_t(jiffies
- p
->tm
.install
);
122 t
.lastuse
= jiffies_to_clock_t(jiffies
- p
->tm
.lastuse
);
123 t
.expires
= jiffies_to_clock_t(p
->tm
.expires
);
124 RTA_PUT(skb
, TCA_DEF_TM
, sizeof(t
), &t
);
128 skb_trim(skb
, b
- skb
->data
);
132 #define tca_use_default_ops \
133 .dump = tcf_defact_dump, \
134 .cleanup = tcf_defact_cleanup, \
135 .init = tcf_defact_init, \
136 .walk = tcf_generic_walker, \
138 #define tca_use_default_defines(name) \
139 static u32 idx_gen; \
140 static struct tcf_defact *tcf_##name_ht[MY_TAB_SIZE]; \
141 static DEFINE_RWLOCK(##name_lock);
142 #endif /* _NET_ACT_GENERIC_H */