Commit 285ba06b authored by Boris Sukholitko's avatar Boris Sukholitko Committed by David S. Miller

net/sched: flower: Helper function for vlan ethtype checks

There are somewhat repetitive ethertype checks in fl_set_key. Refactor
them into is_vlan_key helper function.

To make the changes clearer, avoid touching identation levels. This is
the job for the next patch in the series.
Signed-off-by: default avatarBoris Sukholitko <boris.sukholitko@broadcom.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e63dd412
...@@ -1579,6 +1579,21 @@ static int fl_set_key_ct(struct nlattr **tb, ...@@ -1579,6 +1579,21 @@ static int fl_set_key_ct(struct nlattr **tb,
return 0; return 0;
} }
static bool is_vlan_key(struct nlattr *tb, __be16 *ethertype,
struct fl_flow_key *key, struct fl_flow_key *mask)
{
if (!tb)
return false;
*ethertype = nla_get_be16(tb);
if (eth_type_vlan(*ethertype))
return true;
key->basic.n_proto = *ethertype;
mask->basic.n_proto = cpu_to_be16(~0);
return false;
}
static int fl_set_key(struct net *net, struct nlattr **tb, static int fl_set_key(struct net *net, struct nlattr **tb,
struct fl_flow_key *key, struct fl_flow_key *mask, struct fl_flow_key *key, struct fl_flow_key *mask,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
...@@ -1601,18 +1616,13 @@ static int fl_set_key(struct net *net, struct nlattr **tb, ...@@ -1601,18 +1616,13 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
mask->eth.src, TCA_FLOWER_KEY_ETH_SRC_MASK, mask->eth.src, TCA_FLOWER_KEY_ETH_SRC_MASK,
sizeof(key->eth.src)); sizeof(key->eth.src));
if (tb[TCA_FLOWER_KEY_ETH_TYPE]) { if (is_vlan_key(tb[TCA_FLOWER_KEY_ETH_TYPE], &ethertype, key, mask)) {
ethertype = nla_get_be16(tb[TCA_FLOWER_KEY_ETH_TYPE]);
if (eth_type_vlan(ethertype)) {
fl_set_key_vlan(tb, ethertype, TCA_FLOWER_KEY_VLAN_ID, fl_set_key_vlan(tb, ethertype, TCA_FLOWER_KEY_VLAN_ID,
TCA_FLOWER_KEY_VLAN_PRIO, TCA_FLOWER_KEY_VLAN_PRIO,
TCA_FLOWER_KEY_VLAN_ETH_TYPE, TCA_FLOWER_KEY_VLAN_ETH_TYPE,
&key->vlan, &mask->vlan); &key->vlan, &mask->vlan);
if (tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE]) { if (is_vlan_key(tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE], &ethertype, key, mask)) {
ethertype = nla_get_be16(tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE]);
if (eth_type_vlan(ethertype)) {
fl_set_key_vlan(tb, ethertype, fl_set_key_vlan(tb, ethertype,
TCA_FLOWER_KEY_CVLAN_ID, TCA_FLOWER_KEY_CVLAN_ID,
TCA_FLOWER_KEY_CVLAN_PRIO, TCA_FLOWER_KEY_CVLAN_PRIO,
...@@ -1623,15 +1633,7 @@ static int fl_set_key(struct net *net, struct nlattr **tb, ...@@ -1623,15 +1633,7 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
&mask->basic.n_proto, &mask->basic.n_proto,
TCA_FLOWER_UNSPEC, TCA_FLOWER_UNSPEC,
sizeof(key->basic.n_proto)); sizeof(key->basic.n_proto));
} else {
key->basic.n_proto = ethertype;
mask->basic.n_proto = cpu_to_be16(~0);
}
} }
} else {
key->basic.n_proto = ethertype;
mask->basic.n_proto = cpu_to_be16(~0);
}
} }
if (key->basic.n_proto == htons(ETH_P_IP) || if (key->basic.n_proto == htons(ETH_P_IP) ||
......
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