Skip to content

Commit 8f25662

Browse files
ummakynesdavem330
authored andcommitted
flow_offload: add flow_rule and flow_match structures and use them
This patch wraps the dissector key and mask - that flower uses to represent the matching side - around the flow_match structure. To avoid a follow up patch that would edit the same LoCs in the drivers, this patch also wraps this new flow match structure around the flow rule object. This new structure will also contain the flow actions in follow up patches. This introduces two new interfaces: bool flow_rule_match_key(rule, dissector_id) that returns true if a given matching key is set on, and: flow_rule_match_XYZ(rule, &match); To fetch the matching side XYZ into the match container structure, to retrieve the key and the mask with one single call. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Acked-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d9b5a67 commit 8f25662

17 files changed

Lines changed: 1209 additions & 1222 deletions

File tree

‎drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c‎

Lines changed: 74 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,12 @@ static int bnxt_tc_parse_actions(struct bnxt *bp,
177177
return 0;
178178
}
179179

180-
#define GET_KEY(flow_cmd, key_type) \
181-
skb_flow_dissector_target((flow_cmd)->dissector, key_type,\
182-
(flow_cmd)->key)
183-
#define GET_MASK(flow_cmd, key_type) \
184-
skb_flow_dissector_target((flow_cmd)->dissector, key_type,\
185-
(flow_cmd)->mask)
186-
187180
static int bnxt_tc_parse_flow(struct bnxt *bp,
188181
struct tc_cls_flower_offload *tc_flow_cmd,
189182
struct bnxt_tc_flow *flow)
190183
{
191-
struct flow_dissector *dissector = tc_flow_cmd->dissector;
184+
struct flow_rule *rule = tc_cls_flower_offload_flow_rule(tc_flow_cmd);
185+
struct flow_dissector *dissector = rule->match.dissector;
192186

193187
/* KEY_CONTROL and KEY_BASIC are needed for forming a meaningful key */
194188
if ((dissector->used_keys & BIT(FLOW_DISSECTOR_KEY_CONTROL)) == 0 ||
@@ -198,140 +192,120 @@ static int bnxt_tc_parse_flow(struct bnxt *bp,
198192
return -EOPNOTSUPP;
199193
}
200194

201-
if (dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_BASIC)) {
202-
struct flow_dissector_key_basic *key =
203-
GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_BASIC);
204-
struct flow_dissector_key_basic *mask =
205-
GET_MASK(tc_flow_cmd, FLOW_DISSECTOR_KEY_BASIC);
195+
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC)) {
196+
struct flow_match_basic match;
206197

207-
flow->l2_key.ether_type = key->n_proto;
208-
flow->l2_mask.ether_type = mask->n_proto;
198+
flow_rule_match_basic(rule, &match);
199+
flow->l2_key.ether_type = match.key->n_proto;
200+
flow->l2_mask.ether_type = match.mask->n_proto;
209201

210-
if (key->n_proto == htons(ETH_P_IP) ||
211-
key->n_proto == htons(ETH_P_IPV6)) {
212-
flow->l4_key.ip_proto = key->ip_proto;
213-
flow->l4_mask.ip_proto = mask->ip_proto;
202+
if (match.key->n_proto == htons(ETH_P_IP) ||
203+
match.key->n_proto == htons(ETH_P_IPV6)) {
204+
flow->l4_key.ip_proto = match.key->ip_proto;
205+
flow->l4_mask.ip_proto = match.mask->ip_proto;
214206
}
215207
}
216208

217-
if (dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
218-
struct flow_dissector_key_eth_addrs *key =
219-
GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_ETH_ADDRS);
220-
struct flow_dissector_key_eth_addrs *mask =
221-
GET_MASK(tc_flow_cmd, FLOW_DISSECTOR_KEY_ETH_ADDRS);
209+
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
210+
struct flow_match_eth_addrs match;
222211

212+
flow_rule_match_eth_addrs(rule, &match);
223213
flow->flags |= BNXT_TC_FLOW_FLAGS_ETH_ADDRS;
224-
ether_addr_copy(flow->l2_key.dmac, key->dst);
225-
ether_addr_copy(flow->l2_mask.dmac, mask->dst);
226-
ether_addr_copy(flow->l2_key.smac, key->src);
227-
ether_addr_copy(flow->l2_mask.smac, mask->src);
214+
ether_addr_copy(flow->l2_key.dmac, match.key->dst);
215+
ether_addr_copy(flow->l2_mask.dmac, match.mask->dst);
216+
ether_addr_copy(flow->l2_key.smac, match.key->src);
217+
ether_addr_copy(flow->l2_mask.smac, match.mask->src);
228218
}
229219

230-
if (dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_VLAN)) {
231-
struct flow_dissector_key_vlan *key =
232-
GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_VLAN);
233-
struct flow_dissector_key_vlan *mask =
234-
GET_MASK(tc_flow_cmd, FLOW_DISSECTOR_KEY_VLAN);
220+
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_VLAN)) {
221+
struct flow_match_vlan match;
235222

223+
flow_rule_match_vlan(rule, &match);
236224
flow->l2_key.inner_vlan_tci =
237-
cpu_to_be16(VLAN_TCI(key->vlan_id, key->vlan_priority));
225+
cpu_to_be16(VLAN_TCI(match.key->vlan_id,
226+
match.key->vlan_priority));
238227
flow->l2_mask.inner_vlan_tci =
239-
cpu_to_be16((VLAN_TCI(mask->vlan_id, mask->vlan_priority)));
228+
cpu_to_be16((VLAN_TCI(match.mask->vlan_id,
229+
match.mask->vlan_priority)));
240230
flow->l2_key.inner_vlan_tpid = htons(ETH_P_8021Q);
241231
flow->l2_mask.inner_vlan_tpid = htons(0xffff);
242232
flow->l2_key.num_vlans = 1;
243233
}
244234

245-
if (dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_IPV4_ADDRS)) {
246-
struct flow_dissector_key_ipv4_addrs *key =
247-
GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_IPV4_ADDRS);
248-
struct flow_dissector_key_ipv4_addrs *mask =
249-
GET_MASK(tc_flow_cmd, FLOW_DISSECTOR_KEY_IPV4_ADDRS);
235+
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_IPV4_ADDRS)) {
236+
struct flow_match_ipv4_addrs match;
250237

238+
flow_rule_match_ipv4_addrs(rule, &match);
251239
flow->flags |= BNXT_TC_FLOW_FLAGS_IPV4_ADDRS;
252-
flow->l3_key.ipv4.daddr.s_addr = key->dst;
253-
flow->l3_mask.ipv4.daddr.s_addr = mask->dst;
254-
flow->l3_key.ipv4.saddr.s_addr = key->src;
255-
flow->l3_mask.ipv4.saddr.s_addr = mask->src;
256-
} else if (dissector_uses_key(dissector,
257-
FLOW_DISSECTOR_KEY_IPV6_ADDRS)) {
258-
struct flow_dissector_key_ipv6_addrs *key =
259-
GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_IPV6_ADDRS);
260-
struct flow_dissector_key_ipv6_addrs *mask =
261-
GET_MASK(tc_flow_cmd, FLOW_DISSECTOR_KEY_IPV6_ADDRS);
262-
240+
flow->l3_key.ipv4.daddr.s_addr = match.key->dst;
241+
flow->l3_mask.ipv4.daddr.s_addr = match.mask->dst;
242+
flow->l3_key.ipv4.saddr.s_addr = match.key->src;
243+
flow->l3_mask.ipv4.saddr.s_addr = match.mask->src;
244+
} else if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_IPV6_ADDRS)) {
245+
struct flow_match_ipv6_addrs match;
246+
247+
flow_rule_match_ipv6_addrs(rule, &match);
263248
flow->flags |= BNXT_TC_FLOW_FLAGS_IPV6_ADDRS;
264-
flow->l3_key.ipv6.daddr = key->dst;
265-
flow->l3_mask.ipv6.daddr = mask->dst;
266-
flow->l3_key.ipv6.saddr = key->src;
267-
flow->l3_mask.ipv6.saddr = mask->src;
249+
flow->l3_key.ipv6.daddr = match.key->dst;
250+
flow->l3_mask.ipv6.daddr = match.mask->dst;
251+
flow->l3_key.ipv6.saddr = match.key->src;
252+
flow->l3_mask.ipv6.saddr = match.mask->src;
268253
}
269254

270-
if (dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_PORTS)) {
271-
struct flow_dissector_key_ports *key =
272-
GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_PORTS);
273-
struct flow_dissector_key_ports *mask =
274-
GET_MASK(tc_flow_cmd, FLOW_DISSECTOR_KEY_PORTS);
255+
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_PORTS)) {
256+
struct flow_match_ports match;
275257

258+
flow_rule_match_ports(rule, &match);
276259
flow->flags |= BNXT_TC_FLOW_FLAGS_PORTS;
277-
flow->l4_key.ports.dport = key->dst;
278-
flow->l4_mask.ports.dport = mask->dst;
279-
flow->l4_key.ports.sport = key->src;
280-
flow->l4_mask.ports.sport = mask->src;
260+
flow->l4_key.ports.dport = match.key->dst;
261+
flow->l4_mask.ports.dport = match.mask->dst;
262+
flow->l4_key.ports.sport = match.key->src;
263+
flow->l4_mask.ports.sport = match.mask->src;
281264
}
282265

283-
if (dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_ICMP)) {
284-
struct flow_dissector_key_icmp *key =
285-
GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_ICMP);
286-
struct flow_dissector_key_icmp *mask =
287-
GET_MASK(tc_flow_cmd, FLOW_DISSECTOR_KEY_ICMP);
266+
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ICMP)) {
267+
struct flow_match_icmp match;
288268

269+
flow_rule_match_icmp(rule, &match);
289270
flow->flags |= BNXT_TC_FLOW_FLAGS_ICMP;
290-
flow->l4_key.icmp.type = key->type;
291-
flow->l4_key.icmp.code = key->code;
292-
flow->l4_mask.icmp.type = mask->type;
293-
flow->l4_mask.icmp.code = mask->code;
271+
flow->l4_key.icmp.type = match.key->type;
272+
flow->l4_key.icmp.code = match.key->code;
273+
flow->l4_mask.icmp.type = match.mask->type;
274+
flow->l4_mask.icmp.code = match.mask->code;
294275
}
295276

296-
if (dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS)) {
297-
struct flow_dissector_key_ipv4_addrs *key =
298-
GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS);
299-
struct flow_dissector_key_ipv4_addrs *mask =
300-
GET_MASK(tc_flow_cmd,
301-
FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS);
277+
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS)) {
278+
struct flow_match_ipv4_addrs match;
302279

280+
flow_rule_match_enc_ipv4_addrs(rule, &match);
303281
flow->flags |= BNXT_TC_FLOW_FLAGS_TUNL_IPV4_ADDRS;
304-
flow->tun_key.u.ipv4.dst = key->dst;
305-
flow->tun_mask.u.ipv4.dst = mask->dst;
306-
flow->tun_key.u.ipv4.src = key->src;
307-
flow->tun_mask.u.ipv4.src = mask->src;
308-
} else if (dissector_uses_key(dissector,
282+
flow->tun_key.u.ipv4.dst = match.key->dst;
283+
flow->tun_mask.u.ipv4.dst = match.mask->dst;
284+
flow->tun_key.u.ipv4.src = match.key->src;
285+
flow->tun_mask.u.ipv4.src = match.mask->src;
286+
} else if (flow_rule_match_key(rule,
309287
FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS)) {
310288
return -EOPNOTSUPP;
311289
}
312290

313-
if (dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_ENC_KEYID)) {
314-
struct flow_dissector_key_keyid *key =
315-
GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_ENC_KEYID);
316-
struct flow_dissector_key_keyid *mask =
317-
GET_MASK(tc_flow_cmd, FLOW_DISSECTOR_KEY_ENC_KEYID);
291+
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_KEYID)) {
292+
struct flow_match_enc_keyid match;
318293

294+
flow_rule_match_enc_keyid(rule, &match);
319295
flow->flags |= BNXT_TC_FLOW_FLAGS_TUNL_ID;
320-
flow->tun_key.tun_id = key32_to_tunnel_id(key->keyid);
321-
flow->tun_mask.tun_id = key32_to_tunnel_id(mask->keyid);
296+
flow->tun_key.tun_id = key32_to_tunnel_id(match.key->keyid);
297+
flow->tun_mask.tun_id = key32_to_tunnel_id(match.mask->keyid);
322298
}
323299

324-
if (dissector_uses_key(dissector, FLOW_DISSECTOR_KEY_ENC_PORTS)) {
325-
struct flow_dissector_key_ports *key =
326-
GET_KEY(tc_flow_cmd, FLOW_DISSECTOR_KEY_ENC_PORTS);
327-
struct flow_dissector_key_ports *mask =
328-
GET_MASK(tc_flow_cmd, FLOW_DISSECTOR_KEY_ENC_PORTS);
300+
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_PORTS)) {
301+
struct flow_match_ports match;
329302

303+
flow_rule_match_enc_ports(rule, &match);
330304
flow->flags |= BNXT_TC_FLOW_FLAGS_TUNL_PORTS;
331-
flow->tun_key.tp_dst = key->dst;
332-
flow->tun_mask.tp_dst = mask->dst;
333-
flow->tun_key.tp_src = key->src;
334-
flow->tun_mask.tp_src = mask->src;
305+
flow->tun_key.tp_dst = match.key->dst;
306+
flow->tun_mask.tp_dst = match.mask->dst;
307+
flow->tun_key.tp_src = match.key->src;
308+
flow->tun_mask.tp_src = match.mask->src;
335309
}
336310

337311
return bnxt_tc_parse_actions(bp, &flow->actions, tc_flow_cmd->exts);

0 commit comments

Comments
 (0)