Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net_sched: act: fetch hinfo from a->ops->hinfo

Every action ops has a pointer to hash info, so we don't need to
hard-code it in each module.

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>

authored by

WANG Cong and committed by
David S. Miller
c779f7af 75e4364f

+53 -60
+2 -2
include/net/act_api.h
··· 103 103 struct tcf_hashinfo *hinfo); 104 104 u32 tcf_hash_new_index(struct tcf_hashinfo *hinfo); 105 105 struct tcf_common *tcf_hash_check(u32 index, struct tc_action *a, 106 - int bind, struct tcf_hashinfo *hinfo); 106 + int bind); 107 107 struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est, 108 108 struct tc_action *a, int size, 109 - int bind, struct tcf_hashinfo *hinfo); 109 + int bind); 110 110 void tcf_hash_insert(struct tcf_common *p, struct tcf_hashinfo *hinfo); 111 111 112 112 int tcf_register_action(struct tc_action_ops *a);
+11 -12
net/sched/act_api.c
··· 62 62 EXPORT_SYMBOL(tcf_hash_release); 63 63 64 64 static int tcf_dump_walker(struct sk_buff *skb, struct netlink_callback *cb, 65 - struct tc_action *a, struct tcf_hashinfo *hinfo) 65 + struct tc_action *a) 66 66 { 67 + struct tcf_hashinfo *hinfo = a->ops->hinfo; 67 68 struct hlist_head *head; 68 69 struct tcf_common *p; 69 70 int err = 0, index = -1, i = 0, s_i = 0, n_i = 0; ··· 110 109 goto done; 111 110 } 112 111 113 - static int tcf_del_walker(struct sk_buff *skb, struct tc_action *a, 114 - struct tcf_hashinfo *hinfo) 112 + static int tcf_del_walker(struct sk_buff *skb, struct tc_action *a) 115 113 { 114 + struct tcf_hashinfo *hinfo = a->ops->hinfo; 116 115 struct hlist_head *head; 117 116 struct hlist_node *n; 118 117 struct tcf_common *p; ··· 146 145 static int tcf_generic_walker(struct sk_buff *skb, struct netlink_callback *cb, 147 146 int type, struct tc_action *a) 148 147 { 149 - struct tcf_hashinfo *hinfo = a->ops->hinfo; 150 - 151 148 if (type == RTM_DELACTION) { 152 - return tcf_del_walker(skb, a, hinfo); 149 + return tcf_del_walker(skb, a); 153 150 } else if (type == RTM_GETACTION) { 154 - return tcf_dump_walker(skb, cb, a, hinfo); 151 + return tcf_dump_walker(skb, cb, a); 155 152 } else { 156 153 WARN(1, "tcf_generic_walker: unknown action %d\n", type); 157 154 return -EINVAL; ··· 198 199 return 0; 199 200 } 200 201 201 - struct tcf_common *tcf_hash_check(u32 index, struct tc_action *a, int bind, 202 - struct tcf_hashinfo *hinfo) 202 + struct tcf_common *tcf_hash_check(u32 index, struct tc_action *a, int bind) 203 203 { 204 + struct tcf_hashinfo *hinfo = a->ops->hinfo; 204 205 struct tcf_common *p = NULL; 205 206 if (index && (p = tcf_hash_lookup(index, hinfo)) != NULL) { 206 207 if (bind) ··· 213 214 EXPORT_SYMBOL(tcf_hash_check); 214 215 215 216 struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est, 216 - struct tc_action *a, int size, int bind, 217 - struct tcf_hashinfo *hinfo) 217 + struct tc_action *a, int size, int bind) 218 218 { 219 + struct tcf_hashinfo *hinfo = a->ops->hinfo; 219 220 struct tcf_common *p = kzalloc(size, GFP_KERNEL); 220 221 221 222 if (unlikely(!p)) ··· 494 495 if (a == NULL) 495 496 goto err_mod; 496 497 498 + a->ops = a_o; 497 499 INIT_LIST_HEAD(&a->list); 498 500 /* backward compatibility for policer */ 499 501 if (name == NULL) ··· 510 510 */ 511 511 if (err != ACT_P_CREATED) 512 512 module_put(a_o->owner); 513 - a->ops = a_o; 514 513 515 514 return a; 516 515
+4 -5
net/sched/act_csum.c
··· 63 63 return -EINVAL; 64 64 parm = nla_data(tb[TCA_CSUM_PARMS]); 65 65 66 - pc = tcf_hash_check(parm->index, a, bind, &csum_hash_info); 66 + pc = tcf_hash_check(parm->index, a, bind); 67 67 if (!pc) { 68 - pc = tcf_hash_create(parm->index, est, a, sizeof(*p), bind, 69 - &csum_hash_info); 68 + pc = tcf_hash_create(parm->index, est, a, sizeof(*p), bind); 70 69 if (IS_ERR(pc)) 71 70 return PTR_ERR(pc); 72 71 ret = ACT_P_CREATED; 73 72 } else { 74 73 if (bind)/* dont override defaults */ 75 74 return 0; 76 - tcf_hash_release(pc, bind, &csum_hash_info); 75 + tcf_hash_release(pc, bind, a->ops->hinfo); 77 76 if (!ovr) 78 77 return -EEXIST; 79 78 } ··· 84 85 spin_unlock_bh(&p->tcf_lock); 85 86 86 87 if (ret == ACT_P_CREATED) 87 - tcf_hash_insert(pc, &csum_hash_info); 88 + tcf_hash_insert(pc, a->ops->hinfo); 88 89 89 90 return ret; 90 91 }
+5 -6
net/sched/act_gact.c
··· 86 86 } 87 87 #endif 88 88 89 - pc = tcf_hash_check(parm->index, a, bind, &gact_hash_info); 89 + pc = tcf_hash_check(parm->index, a, bind); 90 90 if (!pc) { 91 - pc = tcf_hash_create(parm->index, est, a, sizeof(*gact), 92 - bind, &gact_hash_info); 91 + pc = tcf_hash_create(parm->index, est, a, sizeof(*gact), bind); 93 92 if (IS_ERR(pc)) 94 93 return PTR_ERR(pc); 95 94 ret = ACT_P_CREATED; 96 95 } else { 97 96 if (bind)/* dont override defaults */ 98 97 return 0; 99 - tcf_hash_release(pc, bind, &gact_hash_info); 98 + tcf_hash_release(pc, bind, a->ops->hinfo); 100 99 if (!ovr) 101 100 return -EEXIST; 102 101 } ··· 113 114 #endif 114 115 spin_unlock_bh(&gact->tcf_lock); 115 116 if (ret == ACT_P_CREATED) 116 - tcf_hash_insert(pc, &gact_hash_info); 117 + tcf_hash_insert(pc, a->ops->hinfo); 117 118 return ret; 118 119 } 119 120 ··· 122 123 struct tcf_gact *gact = a->priv; 123 124 124 125 if (gact) 125 - return tcf_hash_release(&gact->common, bind, &gact_hash_info); 126 + return tcf_hash_release(&gact->common, bind, a->ops->hinfo); 126 127 return 0; 127 128 } 128 129
+3 -4
net/sched/act_ipt.c
··· 125 125 if (tb[TCA_IPT_INDEX] != NULL) 126 126 index = nla_get_u32(tb[TCA_IPT_INDEX]); 127 127 128 - pc = tcf_hash_check(index, a, bind, &ipt_hash_info); 128 + pc = tcf_hash_check(index, a, bind); 129 129 if (!pc) { 130 - pc = tcf_hash_create(index, est, a, sizeof(*ipt), bind, 131 - &ipt_hash_info); 130 + pc = tcf_hash_create(index, est, a, sizeof(*ipt), bind); 132 131 if (IS_ERR(pc)) 133 132 return PTR_ERR(pc); 134 133 ret = ACT_P_CREATED; ··· 170 171 ipt->tcfi_hook = hook; 171 172 spin_unlock_bh(&ipt->tcf_lock); 172 173 if (ret == ACT_P_CREATED) 173 - tcf_hash_insert(pc, &ipt_hash_info); 174 + tcf_hash_insert(pc, a->ops->hinfo); 174 175 return ret; 175 176 176 177 err3:
+3 -4
net/sched/act_mirred.c
··· 101 101 dev = NULL; 102 102 } 103 103 104 - pc = tcf_hash_check(parm->index, a, bind, &mirred_hash_info); 104 + pc = tcf_hash_check(parm->index, a, bind); 105 105 if (!pc) { 106 106 if (dev == NULL) 107 107 return -EINVAL; 108 - pc = tcf_hash_create(parm->index, est, a, sizeof(*m), bind, 109 - &mirred_hash_info); 108 + pc = tcf_hash_create(parm->index, est, a, sizeof(*m), bind); 110 109 if (IS_ERR(pc)) 111 110 return PTR_ERR(pc); 112 111 ret = ACT_P_CREATED; ··· 131 132 spin_unlock_bh(&m->tcf_lock); 132 133 if (ret == ACT_P_CREATED) { 133 134 list_add(&m->tcfm_list, &mirred_list); 134 - tcf_hash_insert(pc, &mirred_hash_info); 135 + tcf_hash_insert(pc, a->ops->hinfo); 135 136 } 136 137 137 138 return ret;
+4 -5
net/sched/act_nat.c
··· 57 57 return -EINVAL; 58 58 parm = nla_data(tb[TCA_NAT_PARMS]); 59 59 60 - pc = tcf_hash_check(parm->index, a, bind, &nat_hash_info); 60 + pc = tcf_hash_check(parm->index, a, bind); 61 61 if (!pc) { 62 - pc = tcf_hash_create(parm->index, est, a, sizeof(*p), bind, 63 - &nat_hash_info); 62 + pc = tcf_hash_create(parm->index, est, a, sizeof(*p), bind); 64 63 if (IS_ERR(pc)) 65 64 return PTR_ERR(pc); 66 65 ret = ACT_P_CREATED; 67 66 } else { 68 67 if (bind) 69 68 return 0; 70 - tcf_hash_release(pc, bind, &nat_hash_info); 69 + tcf_hash_release(pc, bind, a->ops->hinfo); 71 70 if (!ovr) 72 71 return -EEXIST; 73 72 } ··· 82 83 spin_unlock_bh(&p->tcf_lock); 83 84 84 85 if (ret == ACT_P_CREATED) 85 - tcf_hash_insert(pc, &nat_hash_info); 86 + tcf_hash_insert(pc, a->ops->hinfo); 86 87 87 88 return ret; 88 89 }
+4 -5
net/sched/act_pedit.c
··· 57 57 if (nla_len(tb[TCA_PEDIT_PARMS]) < sizeof(*parm) + ksize) 58 58 return -EINVAL; 59 59 60 - pc = tcf_hash_check(parm->index, a, bind, &pedit_hash_info); 60 + pc = tcf_hash_check(parm->index, a, bind); 61 61 if (!pc) { 62 62 if (!parm->nkeys) 63 63 return -EINVAL; 64 - pc = tcf_hash_create(parm->index, est, a, sizeof(*p), bind, 65 - &pedit_hash_info); 64 + pc = tcf_hash_create(parm->index, est, a, sizeof(*p), bind); 66 65 if (IS_ERR(pc)) 67 66 return PTR_ERR(pc); 68 67 p = to_pedit(pc); ··· 76 77 ret = ACT_P_CREATED; 77 78 } else { 78 79 p = to_pedit(pc); 79 - tcf_hash_release(pc, bind, &pedit_hash_info); 80 + tcf_hash_release(pc, bind, a->ops->hinfo); 80 81 if (bind) 81 82 return 0; 82 83 if (!ovr) ··· 100 101 memcpy(p->tcfp_keys, parm->keys, ksize); 101 102 spin_unlock_bh(&p->tcf_lock); 102 103 if (ret == ACT_P_CREATED) 103 - tcf_hash_insert(pc, &pedit_hash_info); 104 + tcf_hash_insert(pc, a->ops->hinfo); 104 105 return ret; 105 106 } 106 107
+10 -8
net/sched/act_police.c
··· 59 59 static int tcf_act_police_walker(struct sk_buff *skb, struct netlink_callback *cb, 60 60 int type, struct tc_action *a) 61 61 { 62 + struct tcf_hashinfo *hinfo = a->ops->hinfo; 62 63 struct hlist_head *head; 63 64 struct tcf_common *p; 64 65 int err = 0, index = -1, i = 0, s_i = 0, n_i = 0; 65 66 struct nlattr *nest; 66 67 67 - spin_lock_bh(&police_hash_info.lock); 68 + spin_lock_bh(&hinfo->lock); 68 69 69 70 s_i = cb->args[0]; 70 71 71 72 for (i = 0; i < (POL_TAB_MASK + 1); i++) { 72 - head = &police_hash_info.htab[tcf_hash(i, POL_TAB_MASK)]; 73 + head = &hinfo->htab[tcf_hash(i, POL_TAB_MASK)]; 73 74 74 75 hlist_for_each_entry_rcu(p, head, tcfc_head) { 75 76 index++; ··· 95 94 } 96 95 } 97 96 done: 98 - spin_unlock_bh(&police_hash_info.lock); 97 + spin_unlock_bh(&hinfo->lock); 99 98 if (n_i) 100 99 cb->args[0] += n_i; 101 100 return n_i; ··· 122 121 struct tc_police *parm; 123 122 struct tcf_police *police; 124 123 struct qdisc_rate_table *R_tab = NULL, *P_tab = NULL; 124 + struct tcf_hashinfo *hinfo = a->ops->hinfo; 125 125 int size; 126 126 127 127 if (nla == NULL) ··· 142 140 if (parm->index) { 143 141 struct tcf_common *pc; 144 142 145 - pc = tcf_hash_lookup(parm->index, &police_hash_info); 143 + pc = tcf_hash_lookup(parm->index, hinfo); 146 144 if (pc != NULL) { 147 145 a->priv = pc; 148 146 police = to_police(pc); ··· 238 236 239 237 police->tcfp_t_c = ktime_to_ns(ktime_get()); 240 238 police->tcf_index = parm->index ? parm->index : 241 - tcf_hash_new_index(&police_hash_info); 239 + tcf_hash_new_index(a->ops->hinfo); 242 240 h = tcf_hash(police->tcf_index, POL_TAB_MASK); 243 - spin_lock_bh(&police_hash_info.lock); 244 - hlist_add_head(&police->tcf_head, &police_hash_info.htab[h]); 245 - spin_unlock_bh(&police_hash_info.lock); 241 + spin_lock_bh(&hinfo->lock); 242 + hlist_add_head(&police->tcf_head, &hinfo->htab[h]); 243 + spin_unlock_bh(&hinfo->lock); 246 244 247 245 a->priv = police; 248 246 return ret;
+3 -4
net/sched/act_simple.c
··· 114 114 parm = nla_data(tb[TCA_DEF_PARMS]); 115 115 defdata = nla_data(tb[TCA_DEF_DATA]); 116 116 117 - pc = tcf_hash_check(parm->index, a, bind, &simp_hash_info); 117 + pc = tcf_hash_check(parm->index, a, bind); 118 118 if (!pc) { 119 - pc = tcf_hash_create(parm->index, est, a, sizeof(*d), bind, 120 - &simp_hash_info); 119 + pc = tcf_hash_create(parm->index, est, a, sizeof(*d), bind); 121 120 if (IS_ERR(pc)) 122 121 return PTR_ERR(pc); 123 122 ··· 144 145 } 145 146 146 147 if (ret == ACT_P_CREATED) 147 - tcf_hash_insert(pc, &simp_hash_info); 148 + tcf_hash_insert(pc, a->ops->hinfo); 148 149 return ret; 149 150 } 150 151
+4 -5
net/sched/act_skbedit.c
··· 100 100 101 101 parm = nla_data(tb[TCA_SKBEDIT_PARMS]); 102 102 103 - pc = tcf_hash_check(parm->index, a, bind, &skbedit_hash_info); 103 + pc = tcf_hash_check(parm->index, a, bind); 104 104 if (!pc) { 105 - pc = tcf_hash_create(parm->index, est, a, sizeof(*d), bind, 106 - &skbedit_hash_info); 105 + pc = tcf_hash_create(parm->index, est, a, sizeof(*d), bind); 107 106 if (IS_ERR(pc)) 108 107 return PTR_ERR(pc); 109 108 ··· 112 113 d = to_skbedit(pc); 113 114 if (bind) 114 115 return 0; 115 - tcf_hash_release(pc, bind, &skbedit_hash_info); 116 + tcf_hash_release(pc, bind, a->ops->hinfo); 116 117 if (!ovr) 117 118 return -EEXIST; 118 119 } ··· 132 133 spin_unlock_bh(&d->tcf_lock); 133 134 134 135 if (ret == ACT_P_CREATED) 135 - tcf_hash_insert(pc, &skbedit_hash_info); 136 + tcf_hash_insert(pc, a->ops->hinfo); 136 137 return ret; 137 138 } 138 139