Skip to content

Commit

Permalink
net_sched: act: hide struct tcf_common from API
Browse files Browse the repository at this point in the history
Now we can totally hide it from modules. tcf_hash_*() API's
will operate on struct tc_action, modules don't need to care about
the details.

Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
WANG Cong authored and David S. Miller committed Feb 13, 2014
1 parent 7282ec8 commit 8606203
Show file tree
Hide file tree
Showing 19 changed files with 135 additions and 206 deletions.
16 changes: 7 additions & 9 deletions include/net/act_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,14 @@ struct tc_action_ops {
};

int tcf_hash_search(struct tc_action *a, u32 index);
void tcf_hash_destroy(struct tcf_common *p, struct tcf_hashinfo *hinfo);
int tcf_hash_release(struct tcf_common *p, int bind,
struct tcf_hashinfo *hinfo);
void tcf_hash_destroy(struct tc_action *a);
int tcf_hash_release(struct tc_action *a, int bind);
u32 tcf_hash_new_index(struct tcf_hashinfo *hinfo);
struct tcf_common *tcf_hash_check(u32 index, struct tc_action *a,
int bind);
struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est,
struct tc_action *a, int size,
int bind);
void tcf_hash_insert(struct tcf_common *p, struct tcf_hashinfo *hinfo);
int tcf_hash_check(u32 index, struct tc_action *a, int bind);
int tcf_hash_create(u32 index, struct nlattr *est, struct tc_action *a,
int size, int bind);
void tcf_hash_cleanup(struct tc_action *a, struct nlattr *est);
void tcf_hash_insert(struct tc_action *a);

int tcf_register_action(struct tc_action_ops *a);
int tcf_unregister_action(struct tc_action_ops *a);
Expand Down
4 changes: 2 additions & 2 deletions include/net/tc_act/tc_csum.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct tcf_csum {

u32 update_flags;
};
#define to_tcf_csum(pc) \
container_of(pc,struct tcf_csum,common)
#define to_tcf_csum(a) \
container_of(a->priv,struct tcf_csum,common)

#endif /* __NET_TC_CSUM_H */
4 changes: 2 additions & 2 deletions include/net/tc_act/tc_defact.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct tcf_defact {
u32 tcfd_datalen;
void *tcfd_defdata;
};
#define to_defact(pc) \
container_of(pc, struct tcf_defact, common)
#define to_defact(a) \
container_of(a->priv, struct tcf_defact, common)

#endif /* __NET_TC_DEF_H */
4 changes: 2 additions & 2 deletions include/net/tc_act/tc_gact.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct tcf_gact {
int tcfg_paction;
#endif
};
#define to_gact(pc) \
container_of(pc, struct tcf_gact, common)
#define to_gact(a) \
container_of(a->priv, struct tcf_gact, common)

#endif /* __NET_TC_GACT_H */
4 changes: 2 additions & 2 deletions include/net/tc_act/tc_ipt.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct tcf_ipt {
char *tcfi_tname;
struct xt_entry_target *tcfi_t;
};
#define to_ipt(pc) \
container_of(pc, struct tcf_ipt, common)
#define to_ipt(a) \
container_of(a->priv, struct tcf_ipt, common)

#endif /* __NET_TC_IPT_H */
4 changes: 2 additions & 2 deletions include/net/tc_act/tc_mirred.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct tcf_mirred {
struct net_device *tcfm_dev;
struct list_head tcfm_list;
};
#define to_mirred(pc) \
container_of(pc, struct tcf_mirred, common)
#define to_mirred(a) \
container_of(a->priv, struct tcf_mirred, common)

#endif /* __NET_TC_MIR_H */
4 changes: 2 additions & 2 deletions include/net/tc_act/tc_nat.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ struct tcf_nat {
u32 flags;
};

static inline struct tcf_nat *to_tcf_nat(struct tcf_common *pc)
static inline struct tcf_nat *to_tcf_nat(struct tc_action *a)
{
return container_of(pc, struct tcf_nat, common);
return container_of(a->priv, struct tcf_nat, common);
}

#endif /* __NET_TC_NAT_H */
4 changes: 2 additions & 2 deletions include/net/tc_act/tc_pedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct tcf_pedit {
unsigned char tcfp_flags;
struct tc_pedit_key *tcfp_keys;
};
#define to_pedit(pc) \
container_of(pc, struct tcf_pedit, common)
#define to_pedit(a) \
container_of(a->priv, struct tcf_pedit, common)

#endif /* __NET_TC_PED_H */
4 changes: 2 additions & 2 deletions include/net/tc_act/tc_skbedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct tcf_skbedit {
u16 queue_mapping;
/* XXX: 16-bit pad here? */
};
#define to_skbedit(pc) \
container_of(pc, struct tcf_skbedit, common)
#define to_skbedit(a) \
container_of(a->priv, struct tcf_skbedit, common)

#endif /* __NET_TC_SKBEDIT_H */
43 changes: 30 additions & 13 deletions net/sched/act_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
#include <net/act_api.h>
#include <net/netlink.h>

void tcf_hash_destroy(struct tcf_common *p, struct tcf_hashinfo *hinfo)
void tcf_hash_destroy(struct tc_action *a)
{
struct tcf_common *p = a->priv;
struct tcf_hashinfo *hinfo = a->ops->hinfo;

spin_lock_bh(&hinfo->lock);
hlist_del(&p->tcfc_head);
spin_unlock_bh(&hinfo->lock);
Expand All @@ -42,9 +45,9 @@ void tcf_hash_destroy(struct tcf_common *p, struct tcf_hashinfo *hinfo)
}
EXPORT_SYMBOL(tcf_hash_destroy);

int tcf_hash_release(struct tcf_common *p, int bind,
struct tcf_hashinfo *hinfo)
int tcf_hash_release(struct tc_action *a, int bind)
{
struct tcf_common *p = a->priv;
int ret = 0;

if (p) {
Expand All @@ -53,7 +56,7 @@ int tcf_hash_release(struct tcf_common *p, int bind,

p->tcfc_refcnt--;
if (p->tcfc_bindcnt <= 0 && p->tcfc_refcnt <= 0) {
tcf_hash_destroy(p, hinfo);
tcf_hash_destroy(a);
ret = 1;
}
}
Expand Down Expand Up @@ -127,7 +130,8 @@ static int tcf_del_walker(struct sk_buff *skb, struct tc_action *a)
for (i = 0; i < (hinfo->hmask + 1); i++) {
head = &hinfo->htab[tcf_hash(i, hinfo->hmask)];
hlist_for_each_entry_safe(p, n, head, tcfc_head) {
if (ACT_P_DELETED == tcf_hash_release(p, 0, hinfo)) {
a->priv = p;
if (ACT_P_DELETED == tcf_hash_release(a, 0)) {
module_put(a->ops->owner);
n_i++;
}
Expand Down Expand Up @@ -198,7 +202,7 @@ int tcf_hash_search(struct tc_action *a, u32 index)
}
EXPORT_SYMBOL(tcf_hash_search);

struct tcf_common *tcf_hash_check(u32 index, struct tc_action *a, int bind)
int tcf_hash_check(u32 index, struct tc_action *a, int bind)
{
struct tcf_hashinfo *hinfo = a->ops->hinfo;
struct tcf_common *p = NULL;
Expand All @@ -207,19 +211,30 @@ struct tcf_common *tcf_hash_check(u32 index, struct tc_action *a, int bind)
p->tcfc_bindcnt++;
p->tcfc_refcnt++;
a->priv = p;
return 1;
}
return p;
return 0;
}
EXPORT_SYMBOL(tcf_hash_check);

struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est,
struct tc_action *a, int size, int bind)
void tcf_hash_cleanup(struct tc_action *a, struct nlattr *est)
{
struct tcf_common *pc = a->priv;
if (est)
gen_kill_estimator(&pc->tcfc_bstats,
&pc->tcfc_rate_est);
kfree_rcu(pc, tcfc_rcu);
}
EXPORT_SYMBOL(tcf_hash_cleanup);

int tcf_hash_create(u32 index, struct nlattr *est, struct tc_action *a,
int size, int bind)
{
struct tcf_hashinfo *hinfo = a->ops->hinfo;
struct tcf_common *p = kzalloc(size, GFP_KERNEL);

if (unlikely(!p))
return ERR_PTR(-ENOMEM);
return -ENOMEM;
p->tcfc_refcnt = 1;
if (bind)
p->tcfc_bindcnt = 1;
Expand All @@ -234,17 +249,19 @@ struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est,
&p->tcfc_lock, est);
if (err) {
kfree(p);
return ERR_PTR(err);
return err;
}
}

a->priv = (void *) p;
return p;
return 0;
}
EXPORT_SYMBOL(tcf_hash_create);

void tcf_hash_insert(struct tcf_common *p, struct tcf_hashinfo *hinfo)
void tcf_hash_insert(struct tc_action *a)
{
struct tcf_common *p = a->priv;
struct tcf_hashinfo *hinfo = a->ops->hinfo;
unsigned int h = tcf_hash(p->tcfc_index, hinfo->hmask);

spin_lock_bh(&hinfo->lock);
Expand Down
24 changes: 8 additions & 16 deletions net/sched/act_csum.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ static int tcf_csum_init(struct net *n, struct nlattr *nla, struct nlattr *est,
{
struct nlattr *tb[TCA_CSUM_MAX + 1];
struct tc_csum *parm;
struct tcf_common *pc;
struct tcf_csum *p;
int ret = 0, err;

Expand All @@ -63,38 +62,31 @@ static int tcf_csum_init(struct net *n, struct nlattr *nla, struct nlattr *est,
return -EINVAL;
parm = nla_data(tb[TCA_CSUM_PARMS]);

pc = tcf_hash_check(parm->index, a, bind);
if (!pc) {
pc = tcf_hash_create(parm->index, est, a, sizeof(*p), bind);
if (IS_ERR(pc))
return PTR_ERR(pc);
if (!tcf_hash_check(parm->index, a, bind)) {
ret = tcf_hash_create(parm->index, est, a, sizeof(*p), bind);
if (ret)
return ret;
ret = ACT_P_CREATED;
} else {
if (bind)/* dont override defaults */
return 0;
tcf_hash_release(pc, bind, a->ops->hinfo);
tcf_hash_release(a, bind);
if (!ovr)
return -EEXIST;
}

p = to_tcf_csum(pc);
p = to_tcf_csum(a);
spin_lock_bh(&p->tcf_lock);
p->tcf_action = parm->action;
p->update_flags = parm->update_flags;
spin_unlock_bh(&p->tcf_lock);

if (ret == ACT_P_CREATED)
tcf_hash_insert(pc, a->ops->hinfo);
tcf_hash_insert(a);

return ret;
}

static int tcf_csum_cleanup(struct tc_action *a, int bind)
{
struct tcf_csum *p = a->priv;
return tcf_hash_release(&p->common, bind, &csum_hash_info);
}

/**
* tcf_csum_skb_nextlayer - Get next layer pointer
* @skb: sk_buff to use
Expand Down Expand Up @@ -574,7 +566,7 @@ static struct tc_action_ops act_csum_ops = {
.owner = THIS_MODULE,
.act = tcf_csum,
.dump = tcf_csum_dump,
.cleanup = tcf_csum_cleanup,
.cleanup = tcf_hash_release,
.init = tcf_csum_init,
};

Expand Down
27 changes: 8 additions & 19 deletions net/sched/act_gact.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ static int tcf_gact_init(struct net *net, struct nlattr *nla,
struct nlattr *tb[TCA_GACT_MAX + 1];
struct tc_gact *parm;
struct tcf_gact *gact;
struct tcf_common *pc;
int ret = 0;
int err;
#ifdef CONFIG_GACT_PROB
Expand Down Expand Up @@ -86,21 +85,20 @@ static int tcf_gact_init(struct net *net, struct nlattr *nla,
}
#endif

pc = tcf_hash_check(parm->index, a, bind);
if (!pc) {
pc = tcf_hash_create(parm->index, est, a, sizeof(*gact), bind);
if (IS_ERR(pc))
return PTR_ERR(pc);
if (!tcf_hash_check(parm->index, a, bind)) {
ret = tcf_hash_create(parm->index, est, a, sizeof(*gact), bind);
if (ret)
return ret;
ret = ACT_P_CREATED;
} else {
if (bind)/* dont override defaults */
return 0;
tcf_hash_release(pc, bind, a->ops->hinfo);
tcf_hash_release(a, bind);
if (!ovr)
return -EEXIST;
}

gact = to_gact(pc);
gact = to_gact(a);

spin_lock_bh(&gact->tcf_lock);
gact->tcf_action = parm->action;
Expand All @@ -113,19 +111,10 @@ static int tcf_gact_init(struct net *net, struct nlattr *nla,
#endif
spin_unlock_bh(&gact->tcf_lock);
if (ret == ACT_P_CREATED)
tcf_hash_insert(pc, a->ops->hinfo);
tcf_hash_insert(a);
return ret;
}

static int tcf_gact_cleanup(struct tc_action *a, int bind)
{
struct tcf_gact *gact = a->priv;

if (gact)
return tcf_hash_release(&gact->common, bind, a->ops->hinfo);
return 0;
}

static int tcf_gact(struct sk_buff *skb, const struct tc_action *a,
struct tcf_result *res)
{
Expand Down Expand Up @@ -196,7 +185,7 @@ static struct tc_action_ops act_gact_ops = {
.owner = THIS_MODULE,
.act = tcf_gact,
.dump = tcf_gact_dump,
.cleanup = tcf_gact_cleanup,
.cleanup = tcf_hash_release,
.init = tcf_gact_init,
};

Expand Down
Loading

0 comments on commit 8606203

Please sign in to comment.