14 #include <linux/types.h>
15 #include <linux/kernel.h>
16 #include <linux/string.h>
17 #include <linux/errno.h>
19 #include <linux/rtnetlink.h>
20 #include <linux/module.h>
22 #include <linux/slab.h>
28 #include <linux/netfilter_ipv4/ip_tables.h>
31 #define IPT_TAB_MASK 15
33 static u32 ipt_idx_gen;
51 return PTR_ERR(target);
57 par.targinfo = t->
data;
63 module_put(t->
u.
kernel.target->me);
77 module_put(par.
target->me);
80 static int tcf_ipt_release(
struct tcf_ipt *ipt,
int bind)
87 if (ipt->tcf_bindcnt <= 0 && ipt->tcf_refcnt <= 0) {
88 ipt_destroy_target(ipt->
tcfi_t);
106 struct tc_action *
a,
int ovr,
int bind)
139 &ipt_idx_gen, &ipt_hash_info);
145 tcf_ipt_release(
to_ipt(pc), bind);
165 err = ipt_init_target(t, tname, hook);
169 spin_lock_bh(&ipt->tcf_lock);
170 if (ret != ACT_P_CREATED) {
171 ipt_destroy_target(ipt->
tcfi_t);
178 spin_unlock_bh(&ipt->tcf_lock);
179 if (ret == ACT_P_CREATED)
188 if (ret == ACT_P_CREATED) {
197 static int tcf_ipt_cleanup(
struct tc_action *a,
int bind)
200 return tcf_ipt_release(ipt, bind);
210 if (skb_cloned(skb)) {
215 spin_lock(&ipt->tcf_lock);
218 bstats_update(&ipt->tcf_bstats, skb);
229 ret = par.
target->target(skb, &par);
237 ipt->tcf_qstats.drops++;
248 spin_unlock(&ipt->tcf_lock);
253 static int tcf_ipt_dump(
struct sk_buff *skb,
struct tc_action *a,
int bind,
int ref)
255 unsigned char *
b = skb_tail_pointer(skb);
268 goto nla_put_failure;
270 c.bindcnt = ipt->tcf_bindcnt - bind;
271 c.refcnt = ipt->tcf_refcnt - ref;
272 strcpy(t->u.user.name, ipt->
tcfi_t->u.kernel.target->name);
274 if (
nla_put(skb, TCA_IPT_TARG, ipt->
tcfi_t->u.user.target_size, t) ||
278 nla_put_string(skb, TCA_IPT_TABLE, ipt->
tcfi_tname))
279 goto nla_put_failure;
284 goto nla_put_failure;
294 static struct tc_action_ops act_ipt_ops = {
296 .hinfo = &ipt_hash_info,
298 .capab = TCA_CAP_NONE,
301 .dump = tcf_ipt_dump,
302 .cleanup = tcf_ipt_cleanup,
304 .init = tcf_ipt_init,
312 static int __init ipt_init_module(
void)
317 static void __exit ipt_cleanup_module(
void)