Skip to content

Commit 99fdb22

Browse files
Boris Sukholitkodavem330
authored andcommitted
net/sched: flower: Consider the number of tags for vlan filters
Before this patch the existence of vlan filters was conditional on the vlan protocol being matched in the tc rule. For example, the following rule: tc filter add dev eth1 ingress flower vlan_prio 5 was illegal because vlan protocol (e.g. 802.1q) does not appear in the rule. Remove the above restriction by looking at the num_of_vlans filter to allow further matching on vlan attributes. The following rule becomes legal as a result of this commit: tc filter add dev eth1 ingress flower num_of_vlans 1 vlan_prio 5 because having num_of_vlans==1 implies that the packet is single tagged. Change is_vlan_key helper to look at the number of vlans in addition to the vlan ethertype. The outcome of this change is that outer (e.g. vlan_prio) and inner (e.g. cvlan_prio) tag vlan filters require the number of vlan tags to be greater then 0 and 1 accordingly. As a result of is_vlan_key change, the ethertype may be set to 0 when matching on the number of vlans. Update fl_set_key_vlan to avoid setting key, mask vlan_tpid for the 0 ethertype. Signed-off-by: Boris Sukholitko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b400031 commit 99fdb22

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

net/sched/cls_flower.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,8 +1030,10 @@ static void fl_set_key_vlan(struct nlattr **tb,
10301030
VLAN_PRIORITY_MASK;
10311031
key_mask->vlan_priority = VLAN_PRIORITY_MASK;
10321032
}
1033-
key_val->vlan_tpid = ethertype;
1034-
key_mask->vlan_tpid = cpu_to_be16(~0);
1033+
if (ethertype) {
1034+
key_val->vlan_tpid = ethertype;
1035+
key_mask->vlan_tpid = cpu_to_be16(~0);
1036+
}
10351037
if (tb[vlan_next_eth_type_key]) {
10361038
key_val->vlan_eth_type =
10371039
nla_get_be16(tb[vlan_next_eth_type_key]);
@@ -1582,13 +1584,18 @@ static int fl_set_key_ct(struct nlattr **tb,
15821584
}
15831585

15841586
static bool is_vlan_key(struct nlattr *tb, __be16 *ethertype,
1585-
struct fl_flow_key *key, struct fl_flow_key *mask)
1587+
struct fl_flow_key *key, struct fl_flow_key *mask,
1588+
int vthresh)
15861589
{
1587-
if (!tb)
1588-
return false;
1590+
const bool good_num_of_vlans = key->num_of_vlans.num_of_vlans > vthresh;
1591+
1592+
if (!tb) {
1593+
*ethertype = 0;
1594+
return good_num_of_vlans;
1595+
}
15891596

15901597
*ethertype = nla_get_be16(tb);
1591-
if (eth_type_vlan(*ethertype))
1598+
if (good_num_of_vlans || eth_type_vlan(*ethertype))
15921599
return true;
15931600

15941601
key->basic.n_proto = *ethertype;
@@ -1623,13 +1630,14 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
16231630
TCA_FLOWER_UNSPEC,
16241631
sizeof(key->num_of_vlans));
16251632

1626-
if (is_vlan_key(tb[TCA_FLOWER_KEY_ETH_TYPE], &ethertype, key, mask)) {
1633+
if (is_vlan_key(tb[TCA_FLOWER_KEY_ETH_TYPE], &ethertype, key, mask, 0)) {
16271634
fl_set_key_vlan(tb, ethertype, TCA_FLOWER_KEY_VLAN_ID,
16281635
TCA_FLOWER_KEY_VLAN_PRIO,
16291636
TCA_FLOWER_KEY_VLAN_ETH_TYPE,
16301637
&key->vlan, &mask->vlan);
16311638

1632-
if (is_vlan_key(tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE], &ethertype, key, mask)) {
1639+
if (is_vlan_key(tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE],
1640+
&ethertype, key, mask, 1)) {
16331641
fl_set_key_vlan(tb, ethertype,
16341642
TCA_FLOWER_KEY_CVLAN_ID,
16351643
TCA_FLOWER_KEY_CVLAN_PRIO,

0 commit comments

Comments
 (0)