Commit 95b06938 authored by Pedro Tammela's avatar Pedro Tammela Committed by Paolo Abeni

net/sched: simplify tcf_pedit_act

Remove the check for a negative number of keys as
this cannot ever happen
Reviewed-by: default avatarJamal Hadi Salim <jhs@mojatatu.com>
Reviewed-by: default avatarSimon Horman <simon.horman@corigine.com>
Signed-off-by: default avatarPedro Tammela <pctammela@mojatatu.com>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent 52cf89f7
...@@ -346,8 +346,12 @@ TC_INDIRECT_SCOPE int tcf_pedit_act(struct sk_buff *skb, ...@@ -346,8 +346,12 @@ TC_INDIRECT_SCOPE int tcf_pedit_act(struct sk_buff *skb,
const struct tc_action *a, const struct tc_action *a,
struct tcf_result *res) struct tcf_result *res)
{ {
enum pedit_header_type htype = TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK;
enum pedit_cmd cmd = TCA_PEDIT_KEY_EX_CMD_SET;
struct tcf_pedit *p = to_pedit(a); struct tcf_pedit *p = to_pedit(a);
struct tcf_pedit_key_ex *tkey_ex;
struct tcf_pedit_parms *parms; struct tcf_pedit_parms *parms;
struct tc_pedit_key *tkey;
u32 max_offset; u32 max_offset;
int i; int i;
...@@ -363,88 +367,81 @@ TC_INDIRECT_SCOPE int tcf_pedit_act(struct sk_buff *skb, ...@@ -363,88 +367,81 @@ TC_INDIRECT_SCOPE int tcf_pedit_act(struct sk_buff *skb,
tcf_lastuse_update(&p->tcf_tm); tcf_lastuse_update(&p->tcf_tm);
tcf_action_update_bstats(&p->common, skb); tcf_action_update_bstats(&p->common, skb);
if (parms->tcfp_nkeys > 0) { tkey = parms->tcfp_keys;
struct tc_pedit_key *tkey = parms->tcfp_keys; tkey_ex = parms->tcfp_keys_ex;
struct tcf_pedit_key_ex *tkey_ex = parms->tcfp_keys_ex;
enum pedit_header_type htype =
TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK;
enum pedit_cmd cmd = TCA_PEDIT_KEY_EX_CMD_SET;
for (i = parms->tcfp_nkeys; i > 0; i--, tkey++) {
u32 *ptr, hdata;
int offset = tkey->off;
int hoffset;
u32 val;
int rc;
if (tkey_ex) {
htype = tkey_ex->htype;
cmd = tkey_ex->cmd;
tkey_ex++;
}
rc = pedit_skb_hdr_offset(skb, htype, &hoffset); for (i = parms->tcfp_nkeys; i > 0; i--, tkey++) {
if (rc) { int offset = tkey->off;
pr_info("tc action pedit bad header type specified (0x%x)\n", u32 *ptr, hdata;
htype); int hoffset;
goto bad; u32 val;
} int rc;
if (tkey->offmask) { if (tkey_ex) {
u8 *d, _d; htype = tkey_ex->htype;
cmd = tkey_ex->cmd;
if (!offset_valid(skb, hoffset + tkey->at)) {
pr_info("tc action pedit 'at' offset %d out of bounds\n",
hoffset + tkey->at);
goto bad;
}
d = skb_header_pointer(skb, hoffset + tkey->at,
sizeof(_d), &_d);
if (!d)
goto bad;
offset += (*d & tkey->offmask) >> tkey->shift;
}
if (offset % 4) { tkey_ex++;
pr_info("tc action pedit offset must be on 32 bit boundaries\n"); }
goto bad;
}
if (!offset_valid(skb, hoffset + offset)) { rc = pedit_skb_hdr_offset(skb, htype, &hoffset);
pr_info("tc action pedit offset %d out of bounds\n", if (rc) {
hoffset + offset); pr_info("tc action pedit bad header type specified (0x%x)\n",
goto bad; htype);
} goto bad;
}
ptr = skb_header_pointer(skb, hoffset + offset, if (tkey->offmask) {
sizeof(hdata), &hdata); u8 *d, _d;
if (!ptr)
goto bad; if (!offset_valid(skb, hoffset + tkey->at)) {
/* just do it, baby */ pr_info("tc action pedit 'at' offset %d out of bounds\n",
switch (cmd) { hoffset + tkey->at);
case TCA_PEDIT_KEY_EX_CMD_SET:
val = tkey->val;
break;
case TCA_PEDIT_KEY_EX_CMD_ADD:
val = (*ptr + tkey->val) & ~tkey->mask;
break;
default:
pr_info("tc action pedit bad command (%d)\n",
cmd);
goto bad; goto bad;
} }
d = skb_header_pointer(skb, hoffset + tkey->at,
sizeof(_d), &_d);
if (!d)
goto bad;
offset += (*d & tkey->offmask) >> tkey->shift;
}
*ptr = ((*ptr & tkey->mask) ^ val); if (offset % 4) {
if (ptr == &hdata) pr_info("tc action pedit offset must be on 32 bit boundaries\n");
skb_store_bits(skb, hoffset + offset, ptr, 4); goto bad;
} }
goto done; if (!offset_valid(skb, hoffset + offset)) {
} else { pr_info("tc action pedit offset %d out of bounds\n",
WARN(1, "pedit BUG: index %d\n", p->tcf_index); hoffset + offset);
goto bad;
}
ptr = skb_header_pointer(skb, hoffset + offset,
sizeof(hdata), &hdata);
if (!ptr)
goto bad;
/* just do it, baby */
switch (cmd) {
case TCA_PEDIT_KEY_EX_CMD_SET:
val = tkey->val;
break;
case TCA_PEDIT_KEY_EX_CMD_ADD:
val = (*ptr + tkey->val) & ~tkey->mask;
break;
default:
pr_info("tc action pedit bad command (%d)\n",
cmd);
goto bad;
}
*ptr = ((*ptr & tkey->mask) ^ val);
if (ptr == &hdata)
skb_store_bits(skb, hoffset + offset, ptr, 4);
} }
goto done;
bad: bad:
spin_lock(&p->tcf_lock); spin_lock(&p->tcf_lock);
p->tcf_qstats.overlimits++; p->tcf_qstats.overlimits++;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment