Skip to content

Commit f4d997f

Browse files
hadarhenziondavem330
authored andcommitted
net/sched: cls_flower: Add UDP port to tunnel parameters
The current IP tunneling classification supports only IP addresses and key. Enhance UDP based IP tunneling classification parameters by adding UDP src and dst port. Signed-off-by: Hadar Hen Zion <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 519d105 commit f4d997f

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

include/net/flow_dissector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ enum flow_dissector_key_id {
132132
FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS, /* struct flow_dissector_key_ipv4_addrs */
133133
FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS, /* struct flow_dissector_key_ipv6_addrs */
134134
FLOW_DISSECTOR_KEY_ENC_CONTROL, /* struct flow_dissector_key_control */
135+
FLOW_DISSECTOR_KEY_ENC_PORTS, /* struct flow_dissector_key_ports */
135136

136137
FLOW_DISSECTOR_KEY_MAX,
137138
};

include/uapi/linux/pkt_cls.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,11 @@ enum {
452452

453453
TCA_FLOWER_KEY_SCTP_SRC, /* be16 */
454454
TCA_FLOWER_KEY_SCTP_DST, /* be16 */
455+
456+
TCA_FLOWER_KEY_ENC_UDP_SRC_PORT, /* be16 */
457+
TCA_FLOWER_KEY_ENC_UDP_SRC_PORT_MASK, /* be16 */
458+
TCA_FLOWER_KEY_ENC_UDP_DST_PORT, /* be16 */
459+
TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK, /* be16 */
455460
__TCA_FLOWER_MAX,
456461
};
457462

net/sched/cls_flower.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct fl_flow_key {
4343
struct flow_dissector_key_ipv4_addrs enc_ipv4;
4444
struct flow_dissector_key_ipv6_addrs enc_ipv6;
4545
};
46+
struct flow_dissector_key_ports enc_tp;
4647
} __aligned(BITS_PER_LONG / 8); /* Ensure that we can do comparisons as longs. */
4748

4849
struct fl_flow_mask_range {
@@ -155,6 +156,8 @@ static int fl_classify(struct sk_buff *skb, const struct tcf_proto *tp,
155156
}
156157

157158
skb_key.enc_key_id.keyid = tunnel_id_to_key32(key->tun_id);
159+
skb_key.enc_tp.src = key->tp_src;
160+
skb_key.enc_tp.dst = key->tp_dst;
158161
}
159162

160163
skb_key.indev_ifindex = skb->skb_iif;
@@ -348,6 +351,10 @@ static const struct nla_policy fl_policy[TCA_FLOWER_MAX + 1] = {
348351
[TCA_FLOWER_KEY_SCTP_DST_MASK] = { .type = NLA_U16 },
349352
[TCA_FLOWER_KEY_SCTP_SRC] = { .type = NLA_U16 },
350353
[TCA_FLOWER_KEY_SCTP_DST] = { .type = NLA_U16 },
354+
[TCA_FLOWER_KEY_ENC_UDP_SRC_PORT] = { .type = NLA_U16 },
355+
[TCA_FLOWER_KEY_ENC_UDP_SRC_PORT_MASK] = { .type = NLA_U16 },
356+
[TCA_FLOWER_KEY_ENC_UDP_DST_PORT] = { .type = NLA_U16 },
357+
[TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK] = { .type = NLA_U16 },
351358
};
352359

353360
static void fl_set_key_val(struct nlattr **tb,
@@ -500,6 +507,14 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
500507
&mask->enc_key_id.keyid, TCA_FLOWER_UNSPEC,
501508
sizeof(key->enc_key_id.keyid));
502509

510+
fl_set_key_val(tb, &key->enc_tp.src, TCA_FLOWER_KEY_ENC_UDP_SRC_PORT,
511+
&mask->enc_tp.src, TCA_FLOWER_KEY_ENC_UDP_SRC_PORT_MASK,
512+
sizeof(key->enc_tp.src));
513+
514+
fl_set_key_val(tb, &key->enc_tp.dst, TCA_FLOWER_KEY_ENC_UDP_DST_PORT,
515+
&mask->enc_tp.dst, TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK,
516+
sizeof(key->enc_tp.dst));
517+
503518
return 0;
504519
}
505520

@@ -577,6 +592,8 @@ static void fl_init_dissector(struct cls_fl_head *head,
577592
FL_KEY_IS_MASKED(&mask->key, enc_ipv6))
578593
FL_KEY_SET(keys, cnt, FLOW_DISSECTOR_KEY_ENC_CONTROL,
579594
enc_control);
595+
FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
596+
FLOW_DISSECTOR_KEY_ENC_PORTS, enc_tp);
580597

581598
skb_flow_dissector_init(&head->dissector, keys, cnt);
582599
}
@@ -951,7 +968,17 @@ static int fl_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
951968

952969
if (fl_dump_key_val(skb, &key->enc_key_id, TCA_FLOWER_KEY_ENC_KEY_ID,
953970
&mask->enc_key_id, TCA_FLOWER_UNSPEC,
954-
sizeof(key->enc_key_id)))
971+
sizeof(key->enc_key_id)) ||
972+
fl_dump_key_val(skb, &key->enc_tp.src,
973+
TCA_FLOWER_KEY_ENC_UDP_SRC_PORT,
974+
&mask->enc_tp.src,
975+
TCA_FLOWER_KEY_ENC_UDP_SRC_PORT_MASK,
976+
sizeof(key->enc_tp.src)) ||
977+
fl_dump_key_val(skb, &key->enc_tp.dst,
978+
TCA_FLOWER_KEY_ENC_UDP_DST_PORT,
979+
&mask->enc_tp.dst,
980+
TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK,
981+
sizeof(key->enc_tp.dst)))
955982
goto nla_put_failure;
956983

957984
nla_put_u32(skb, TCA_FLOWER_FLAGS, f->flags);

0 commit comments

Comments
 (0)