Commit 4bf8758a authored by Pieter Jansen van Vuuren's avatar Pieter Jansen van Vuuren Committed by David S. Miller

nfp: flower: add helper functions for tunnel classification

Adds IPv4 address and TTL/TOS helper functions, which is done in
preparation for compiling new tunnel types.
Signed-off-by: default avatarPieter Jansen van Vuuren <pieter.jansenvanvuuren@netronome.com>
Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: default avatarJohn Hurley <john.hurley@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 986643de
...@@ -354,6 +354,16 @@ struct nfp_flower_ipv6 { ...@@ -354,6 +354,16 @@ struct nfp_flower_ipv6 {
struct in6_addr ipv6_dst; struct in6_addr ipv6_dst;
}; };
struct nfp_flower_tun_ipv4 {
__be32 src;
__be32 dst;
};
struct nfp_flower_tun_ip_ext {
u8 tos;
u8 ttl;
};
/* Flow Frame IPv4 UDP TUNNEL --> Tunnel details (4W/16B) /* Flow Frame IPv4 UDP TUNNEL --> Tunnel details (4W/16B)
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* 3 2 1 * 3 2 1
...@@ -371,11 +381,9 @@ struct nfp_flower_ipv6 { ...@@ -371,11 +381,9 @@ struct nfp_flower_ipv6 {
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/ */
struct nfp_flower_ipv4_udp_tun { struct nfp_flower_ipv4_udp_tun {
__be32 ip_src; struct nfp_flower_tun_ipv4 ipv4;
__be32 ip_dst;
__be16 reserved1; __be16 reserved1;
u8 tos; struct nfp_flower_tun_ip_ext ip_ext;
u8 ttl;
__be32 reserved2; __be32 reserved2;
__be32 tun_id; __be32 tun_id;
}; };
......
...@@ -280,6 +280,42 @@ nfp_flower_compile_geneve_opt(void *ext, void *msk, ...@@ -280,6 +280,42 @@ nfp_flower_compile_geneve_opt(void *ext, void *msk,
return 0; return 0;
} }
static void
nfp_flower_compile_tun_ipv4_addrs(struct nfp_flower_tun_ipv4 *ext,
struct nfp_flower_tun_ipv4 *msk,
struct tc_cls_flower_offload *flow)
{
struct flow_rule *rule = tc_cls_flower_offload_flow_rule(flow);
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS)) {
struct flow_match_ipv4_addrs match;
flow_rule_match_enc_ipv4_addrs(rule, &match);
ext->src = match.key->src;
ext->dst = match.key->dst;
msk->src = match.mask->src;
msk->dst = match.mask->dst;
}
}
static void
nfp_flower_compile_tun_ip_ext(struct nfp_flower_tun_ip_ext *ext,
struct nfp_flower_tun_ip_ext *msk,
struct tc_cls_flower_offload *flow)
{
struct flow_rule *rule = tc_cls_flower_offload_flow_rule(flow);
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_IP)) {
struct flow_match_ip match;
flow_rule_match_enc_ip(rule, &match);
ext->tos = match.key->tos;
ext->ttl = match.key->ttl;
msk->tos = match.mask->tos;
msk->ttl = match.mask->ttl;
}
}
static void static void
nfp_flower_compile_ipv4_udp_tun(struct nfp_flower_ipv4_udp_tun *ext, nfp_flower_compile_ipv4_udp_tun(struct nfp_flower_ipv4_udp_tun *ext,
struct nfp_flower_ipv4_udp_tun *msk, struct nfp_flower_ipv4_udp_tun *msk,
...@@ -301,25 +337,8 @@ nfp_flower_compile_ipv4_udp_tun(struct nfp_flower_ipv4_udp_tun *ext, ...@@ -301,25 +337,8 @@ nfp_flower_compile_ipv4_udp_tun(struct nfp_flower_ipv4_udp_tun *ext,
msk->tun_id = cpu_to_be32(temp_vni); msk->tun_id = cpu_to_be32(temp_vni);
} }
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS)) { nfp_flower_compile_tun_ipv4_addrs(&ext->ipv4, &msk->ipv4, flow);
struct flow_match_ipv4_addrs match; nfp_flower_compile_tun_ip_ext(&ext->ip_ext, &msk->ip_ext, flow);
flow_rule_match_enc_ipv4_addrs(rule, &match);
ext->ip_src = match.key->src;
ext->ip_dst = match.key->dst;
msk->ip_src = match.mask->src;
msk->ip_dst = match.mask->dst;
}
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ENC_IP)) {
struct flow_match_ip match;
flow_rule_match_enc_ip(rule, &match);
ext->tos = match.key->tos;
ext->ttl = match.key->ttl;
msk->tos = match.mask->tos;
msk->ttl = match.mask->ttl;
}
} }
int nfp_flower_compile_flow_match(struct nfp_app *app, int nfp_flower_compile_flow_match(struct nfp_app *app,
...@@ -411,7 +430,7 @@ int nfp_flower_compile_flow_match(struct nfp_app *app, ...@@ -411,7 +430,7 @@ int nfp_flower_compile_flow_match(struct nfp_app *app,
__be32 tun_dst; __be32 tun_dst;
nfp_flower_compile_ipv4_udp_tun((void *)ext, (void *)msk, flow); nfp_flower_compile_ipv4_udp_tun((void *)ext, (void *)msk, flow);
tun_dst = ((struct nfp_flower_ipv4_udp_tun *)ext)->ip_dst; tun_dst = ((struct nfp_flower_ipv4_udp_tun *)ext)->ipv4.dst;
ext += sizeof(struct nfp_flower_ipv4_udp_tun); ext += sizeof(struct nfp_flower_ipv4_udp_tun);
msk += sizeof(struct nfp_flower_ipv4_udp_tun); msk += sizeof(struct nfp_flower_ipv4_udp_tun);
......
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