Skip to content

Commit c1f6f1e

Browse files
committed
Merge branch 'net-sched-flower-num-vlan-tags'
Boris Sukholitko says: ==================== net/sched: flower: match on the number of vlan tags Our customers in the fiber telecom world have network configurations where they would like to control their traffic according to the number of tags appearing in the packet. For example, TR247 GPON conformance test suite specification mostly talks about untagged, single, double tagged packets and gives lax guidelines on the vlan protocol vs. number of vlan tags. This is different from the common IT networks where 802.1Q and 802.1ad protocols are usually describe single and double tagged packet. GPON configurations that we work with have arbitrary mix the above protocols and number of vlan tags in the packet. The following patch series implement number of vlans flower filter. They add num_of_vlans flower filter as an alternative to vlan ethtype protocol matching. The end result is that the following command becomes possible: tc filter add dev eth1 ingress flower \ num_of_vlans 1 vlan_prio 5 action drop Also, from our logs, we have redirect rules such that: tc filter add dev $GPON ingress flower num_of_vlans $N \ action mirred egress redirect dev $DEV where N can range from 0 to 3 and $DEV is the function of $N. Also there are rules setting skb mark based on the number of vlans: tc filter add dev $GPON ingress flower num_of_vlans $N vlan_prio \ $P action skbedit mark $M More about the patch series: - patches 1-2 remove duplicate code by introducing is_key_vlan helper. - patch 3, 4 implement num_of_vlans in the dissector and in the flower. - patch 5 uses the num_of_vlans filter to allow further matching on vlan attributes. Complementary iproute2 patches are being sent separately. Thanks, Boris. - v4: rebased to the latest net-next - v3: - more example commands in patch 3 description (request by Jamal) - patch 5 description made clearer (thanks to Jiri) - v2: - add suitable subject prefixes - more evolved patch 5 description ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents e63dd41 + 99fdb22 commit c1f6f1e

File tree

4 files changed

+88
-33
lines changed

4 files changed

+88
-33
lines changed

include/net/flow_dissector.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,14 @@ struct flow_dissector_key_hash {
253253
u32 hash;
254254
};
255255

256+
/**
257+
* struct flow_dissector_key_num_of_vlans:
258+
* @num_of_vlans: num_of_vlans value
259+
*/
260+
struct flow_dissector_key_num_of_vlans {
261+
u8 num_of_vlans;
262+
};
263+
256264
enum flow_dissector_key_id {
257265
FLOW_DISSECTOR_KEY_CONTROL, /* struct flow_dissector_key_control */
258266
FLOW_DISSECTOR_KEY_BASIC, /* struct flow_dissector_key_basic */
@@ -282,6 +290,7 @@ enum flow_dissector_key_id {
282290
FLOW_DISSECTOR_KEY_META, /* struct flow_dissector_key_meta */
283291
FLOW_DISSECTOR_KEY_CT, /* struct flow_dissector_key_ct */
284292
FLOW_DISSECTOR_KEY_HASH, /* struct flow_dissector_key_hash */
293+
FLOW_DISSECTOR_KEY_NUM_OF_VLANS, /* struct flow_dissector_key_num_of_vlans */
285294

286295
FLOW_DISSECTOR_KEY_MAX,
287296
};

include/uapi/linux/pkt_cls.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,8 @@ enum {
587587
TCA_FLOWER_KEY_HASH, /* u32 */
588588
TCA_FLOWER_KEY_HASH_MASK, /* u32 */
589589

590+
TCA_FLOWER_KEY_NUM_OF_VLANS, /* u8 */
591+
590592
__TCA_FLOWER_MAX,
591593
};
592594

net/core/flow_dissector.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,16 @@ bool __skb_flow_dissect(const struct net *net,
10351035
memcpy(key_eth_addrs, eth, sizeof(*key_eth_addrs));
10361036
}
10371037

1038+
if (dissector_uses_key(flow_dissector,
1039+
FLOW_DISSECTOR_KEY_NUM_OF_VLANS)) {
1040+
struct flow_dissector_key_num_of_vlans *key_num_of_vlans;
1041+
1042+
key_num_of_vlans = skb_flow_dissector_target(flow_dissector,
1043+
FLOW_DISSECTOR_KEY_NUM_OF_VLANS,
1044+
target_container);
1045+
key_num_of_vlans->num_of_vlans = 0;
1046+
}
1047+
10381048
proto_again:
10391049
fdret = FLOW_DISSECT_RET_CONTINUE;
10401050

@@ -1158,6 +1168,16 @@ bool __skb_flow_dissect(const struct net *net,
11581168
nhoff += sizeof(*vlan);
11591169
}
11601170

1171+
if (dissector_uses_key(flow_dissector,
1172+
FLOW_DISSECTOR_KEY_NUM_OF_VLANS)) {
1173+
struct flow_dissector_key_num_of_vlans *key_nvs;
1174+
1175+
key_nvs = skb_flow_dissector_target(flow_dissector,
1176+
FLOW_DISSECTOR_KEY_NUM_OF_VLANS,
1177+
target_container);
1178+
key_nvs->num_of_vlans++;
1179+
}
1180+
11611181
if (dissector_vlan == FLOW_DISSECTOR_KEY_MAX) {
11621182
dissector_vlan = FLOW_DISSECTOR_KEY_VLAN;
11631183
} else if (dissector_vlan == FLOW_DISSECTOR_KEY_VLAN) {

net/sched/cls_flower.c

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct fl_flow_key {
7272
} tp_range;
7373
struct flow_dissector_key_ct ct;
7474
struct flow_dissector_key_hash hash;
75+
struct flow_dissector_key_num_of_vlans num_of_vlans;
7576
} __aligned(BITS_PER_LONG / 8); /* Ensure that we can do comparisons as longs. */
7677

7778
struct fl_flow_mask_range {
@@ -712,6 +713,7 @@ static const struct nla_policy fl_policy[TCA_FLOWER_MAX + 1] = {
712713
[TCA_FLOWER_FLAGS] = { .type = NLA_U32 },
713714
[TCA_FLOWER_KEY_HASH] = { .type = NLA_U32 },
714715
[TCA_FLOWER_KEY_HASH_MASK] = { .type = NLA_U32 },
716+
[TCA_FLOWER_KEY_NUM_OF_VLANS] = { .type = NLA_U8 },
715717

716718
};
717719

@@ -1028,8 +1030,10 @@ static void fl_set_key_vlan(struct nlattr **tb,
10281030
VLAN_PRIORITY_MASK;
10291031
key_mask->vlan_priority = VLAN_PRIORITY_MASK;
10301032
}
1031-
key_val->vlan_tpid = ethertype;
1032-
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+
}
10331037
if (tb[vlan_next_eth_type_key]) {
10341038
key_val->vlan_eth_type =
10351039
nla_get_be16(tb[vlan_next_eth_type_key]);
@@ -1579,6 +1583,26 @@ static int fl_set_key_ct(struct nlattr **tb,
15791583
return 0;
15801584
}
15811585

1586+
static bool is_vlan_key(struct nlattr *tb, __be16 *ethertype,
1587+
struct fl_flow_key *key, struct fl_flow_key *mask,
1588+
int vthresh)
1589+
{
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+
}
1596+
1597+
*ethertype = nla_get_be16(tb);
1598+
if (good_num_of_vlans || eth_type_vlan(*ethertype))
1599+
return true;
1600+
1601+
key->basic.n_proto = *ethertype;
1602+
mask->basic.n_proto = cpu_to_be16(~0);
1603+
return false;
1604+
}
1605+
15821606
static int fl_set_key(struct net *net, struct nlattr **tb,
15831607
struct fl_flow_key *key, struct fl_flow_key *mask,
15841608
struct netlink_ext_ack *extack)
@@ -1600,37 +1624,30 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
16001624
fl_set_key_val(tb, key->eth.src, TCA_FLOWER_KEY_ETH_SRC,
16011625
mask->eth.src, TCA_FLOWER_KEY_ETH_SRC_MASK,
16021626
sizeof(key->eth.src));
1603-
1604-
if (tb[TCA_FLOWER_KEY_ETH_TYPE]) {
1605-
ethertype = nla_get_be16(tb[TCA_FLOWER_KEY_ETH_TYPE]);
1606-
1607-
if (eth_type_vlan(ethertype)) {
1608-
fl_set_key_vlan(tb, ethertype, TCA_FLOWER_KEY_VLAN_ID,
1609-
TCA_FLOWER_KEY_VLAN_PRIO,
1610-
TCA_FLOWER_KEY_VLAN_ETH_TYPE,
1611-
&key->vlan, &mask->vlan);
1612-
1613-
if (tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE]) {
1614-
ethertype = nla_get_be16(tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE]);
1615-
if (eth_type_vlan(ethertype)) {
1616-
fl_set_key_vlan(tb, ethertype,
1617-
TCA_FLOWER_KEY_CVLAN_ID,
1618-
TCA_FLOWER_KEY_CVLAN_PRIO,
1619-
TCA_FLOWER_KEY_CVLAN_ETH_TYPE,
1620-
&key->cvlan, &mask->cvlan);
1621-
fl_set_key_val(tb, &key->basic.n_proto,
1622-
TCA_FLOWER_KEY_CVLAN_ETH_TYPE,
1623-
&mask->basic.n_proto,
1624-
TCA_FLOWER_UNSPEC,
1625-
sizeof(key->basic.n_proto));
1626-
} else {
1627-
key->basic.n_proto = ethertype;
1628-
mask->basic.n_proto = cpu_to_be16(~0);
1629-
}
1630-
}
1631-
} else {
1632-
key->basic.n_proto = ethertype;
1633-
mask->basic.n_proto = cpu_to_be16(~0);
1627+
fl_set_key_val(tb, &key->num_of_vlans,
1628+
TCA_FLOWER_KEY_NUM_OF_VLANS,
1629+
&mask->num_of_vlans,
1630+
TCA_FLOWER_UNSPEC,
1631+
sizeof(key->num_of_vlans));
1632+
1633+
if (is_vlan_key(tb[TCA_FLOWER_KEY_ETH_TYPE], &ethertype, key, mask, 0)) {
1634+
fl_set_key_vlan(tb, ethertype, TCA_FLOWER_KEY_VLAN_ID,
1635+
TCA_FLOWER_KEY_VLAN_PRIO,
1636+
TCA_FLOWER_KEY_VLAN_ETH_TYPE,
1637+
&key->vlan, &mask->vlan);
1638+
1639+
if (is_vlan_key(tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE],
1640+
&ethertype, key, mask, 1)) {
1641+
fl_set_key_vlan(tb, ethertype,
1642+
TCA_FLOWER_KEY_CVLAN_ID,
1643+
TCA_FLOWER_KEY_CVLAN_PRIO,
1644+
TCA_FLOWER_KEY_CVLAN_ETH_TYPE,
1645+
&key->cvlan, &mask->cvlan);
1646+
fl_set_key_val(tb, &key->basic.n_proto,
1647+
TCA_FLOWER_KEY_CVLAN_ETH_TYPE,
1648+
&mask->basic.n_proto,
1649+
TCA_FLOWER_UNSPEC,
1650+
sizeof(key->basic.n_proto));
16341651
}
16351652
}
16361653

@@ -1904,6 +1921,8 @@ static void fl_init_dissector(struct flow_dissector *dissector,
19041921
FLOW_DISSECTOR_KEY_CT, ct);
19051922
FL_KEY_SET_IF_MASKED(mask, keys, cnt,
19061923
FLOW_DISSECTOR_KEY_HASH, hash);
1924+
FL_KEY_SET_IF_MASKED(mask, keys, cnt,
1925+
FLOW_DISSECTOR_KEY_NUM_OF_VLANS, num_of_vlans);
19071926

19081927
skb_flow_dissector_init(dissector, keys, cnt);
19091928
}
@@ -2992,6 +3011,11 @@ static int fl_dump_key(struct sk_buff *skb, struct net *net,
29923011
sizeof(key->basic.n_proto)))
29933012
goto nla_put_failure;
29943013

3014+
if (mask->num_of_vlans.num_of_vlans) {
3015+
if (nla_put_u8(skb, TCA_FLOWER_KEY_NUM_OF_VLANS, key->num_of_vlans.num_of_vlans))
3016+
goto nla_put_failure;
3017+
}
3018+
29953019
if (fl_dump_key_mpls(skb, &key->mpls, &mask->mpls))
29963020
goto nla_put_failure;
29973021

0 commit comments

Comments
 (0)