From: Paul Blakey <pa...@mellanox.com>
Currently only tunnel offload is supported.
Signed-off-by: Paul Blakey <pa...@mellanox.com>
Reviewed-by: Roi Dayan <r...@mellanox.com>
Reviewed-by: Simon Horman <simon.hor...@netronome.com>
---
lib/dpif-netlink.c | 4 +-
lib/netdev-tc-offloads.c | 392 ++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 385 insertions(+), 11 deletions(-)
diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
index 81d513d..7e6c647 100644
--- a/lib/dpif-netlink.c
+++ b/lib/dpif-netlink.c
@@ -1937,8 +1937,6 @@ parse_flow_put(struct dpif_netlink *dpif, struct
dpif_flow_put *put)
return EOPNOTSUPP;
}
- memset(&match, 0, sizeof match);
-
err = parse_key_and_mask_to_match(put->key, put->key_len, put->mask,
put->mask_len, &match);
if (err) {
@@ -2011,7 +2009,7 @@ parse_flow_put(struct dpif_netlink *dpif, struct
dpif_flow_put *put)
VLOG_DBG("added flow");
} else if (err != EEXIST) {
- VLOG_ERR_RL(&rl, "failed to offload flow: %s", ovs_strerror(err));
+ VLOG_ERR_RL(&rl, "failed adding flow: %s", ovs_strerror(err));
}
out:
diff --git a/lib/netdev-tc-offloads.c b/lib/netdev-tc-offloads.c
index 7e33fff..e3daf62 100644
--- a/lib/netdev-tc-offloads.c
+++ b/lib/netdev-tc-offloads.c
@@ -461,16 +461,392 @@ netdev_tc_flow_dump_next(struct netdev_flow_dump *dump,
return false;
}
+static int
+parse_put_flow_set_action(struct tc_flower *flower, const struct nlattr *set,
+ size_t set_len)
+{
+ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
+ const struct nlattr *set_attr;
+ size_t set_left;
+
+ NL_ATTR_FOR_EACH_UNSAFE(set_attr, set_left, set, set_len) {
+ if (nl_attr_type(set_attr) == OVS_KEY_ATTR_TUNNEL) {
+ const struct nlattr *tunnel = nl_attr_get(set_attr);
+ const size_t tunnel_len = nl_attr_get_size(set_attr);
+ const struct nlattr *tun_attr;
+ size_t tun_left;
+
+ flower->set.set = true;
+ NL_ATTR_FOR_EACH_UNSAFE(tun_attr, tun_left, tunnel, tunnel_len) {
+ switch (nl_attr_type(tun_attr)) {
+ case OVS_TUNNEL_KEY_ATTR_ID: {
+ flower->set.id = nl_attr_get_be64(tun_attr);
+ }
+ break;
+ case OVS_TUNNEL_KEY_ATTR_IPV4_SRC: {
+ flower->set.ipv4.ipv4_src = nl_attr_get_be32(tun_attr);
+ }
+ break;
+ case OVS_TUNNEL_KEY_ATTR_IPV4_DST: {
+ flower->set.ipv4.ipv4_dst = nl_attr_get_be32(tun_attr);
+ }
+ break;
+ case OVS_TUNNEL_KEY_ATTR_IPV6_SRC: {
+ flower->set.ipv6.ipv6_src =
+ nl_attr_get_in6_addr(tun_attr);
+ }
+ break;
+ case OVS_TUNNEL_KEY_ATTR_IPV6_DST: {
+ flower->set.ipv6.ipv6_dst =
+ nl_attr_get_in6_addr(tun_attr);
+ }
+ break;
+ case OVS_TUNNEL_KEY_ATTR_TP_SRC: {
+ flower->set.tp_src = nl_attr_get_be16(tun_attr);
+ }
+ break;
+ case OVS_TUNNEL_KEY_ATTR_TP_DST: {
+ flower->set.tp_dst = nl_attr_get_be16(tun_attr);
+ }
+ break;
+ }
+ }
+ } else {
+ VLOG_DBG_RL(&rl, "unsupported set action type: %d",
+ nl_attr_type(set_attr));
+ return EOPNOTSUPP;
+ }
+ }
+ return 0;
+}
+
+static int
+test_key_and_mask(struct match *match) {
+ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
+ const struct flow *key = &match->flow;
+ struct flow *mask = &match->wc.masks;
+
+ if (mask->pkt_mark) {
+ VLOG_DBG_RL(&rl, "offloading attribute pkt_mark isn't supported");
+ return EOPNOTSUPP;
+ }
+
+ if (mask->recirc_id && key->recirc_id != 0) {
+ VLOG_DBG_RL(&rl, "offloading attribute recirc_id isn't supported");
+ return EOPNOTSUPP;
+ }
+ mask->recirc_id = 0;
+
+ if (mask->dp_hash) {
+ VLOG_DBG_RL(&rl, "offloading attribute dp_hash isn't supported");
+ return EOPNOTSUPP;
+ }
+
+ if (mask->conj_id) {
+ VLOG_DBG_RL(&rl, "offloading attribute conj_id isn't supported");
+ return EOPNOTSUPP;
+ }
+
+ if (mask->skb_priority) {
+ VLOG_DBG_RL(&rl, "offloading attribute skb_priority isn't supported");
+ return EOPNOTSUPP;
+ }
+
+ if (mask->actset_output) {
+ VLOG_DBG_RL(&rl,
+ "offloading attribute actset_output isn't supported");
+ return EOPNOTSUPP;
+ }
+
+ if (mask->ct_state) {
+ VLOG_DBG_RL(&rl, "offloading attribute ct_state isn't supported");
+ return EOPNOTSUPP;
+ }
+
+ if (mask->ct_zone) {
+ VLOG_DBG_RL(&rl, "offloading attribute ct_zone isn't supported");
+ return EOPNOTSUPP;
+ }
+
+ if (mask->ct_mark) {
+ VLOG_DBG_RL(&rl, "offloading attribute ct_zone isn't supported");
+ return EOPNOTSUPP;
+ }
+
+ if (!ovs_u128_is_zero(mask->ct_label)) {
+ VLOG_DBG_RL(&rl, "offloading attribute ct_lable isn't supported");
+ return EOPNOTSUPP;
+ }
+
+ for (int i = 0; i < FLOW_N_REGS; i++) {
+ if (mask->regs[i]) {
+ VLOG_DBG_RL(&rl,
+ "offloading attribute regs[%d] isn't supported", i);
+ return EOPNOTSUPP;
+ }
+ }
+
+ if (mask->metadata != 0) {
+ VLOG_DBG_RL(&rl, "offloading attribute metadata isn't supported");
+ return EOPNOTSUPP;
+ }
+
+ if (mask->nw_tos) {
+ VLOG_DBG_RL(&rl, "offloading attribute nw_tos isn't supported");
+ return EOPNOTSUPP;
+ }
+
+ if (mask->nw_ttl) {
+ VLOG_DBG_RL(&rl, "offloading attribute nw_ttl isn't supported");
+ return EOPNOTSUPP;
+ }
+
+ if (mask->nw_frag) {
+ VLOG_DBG_RL(&rl, "offloading attribute nw_frag isn't supported");
+ return EOPNOTSUPP;
+ }
+
+ for (int i = 0; i < FLOW_MAX_MPLS_LABELS; i++) {
+ if (mask->mpls_lse[i]) {
+ VLOG_DBG_RL(&rl, "offloading attribute mpls_lse isn't supported");
+ return EOPNOTSUPP;
+ }
+ }
+
+ if (key->dl_type == htons(ETH_TYPE_IP) &&
+ key->nw_proto == IPPROTO_ICMP) {
+ if (mask->tp_src) {
+ VLOG_DBG_RL(&rl,
+ "offloading attribute icmp_type isn't supported");
+ return EOPNOTSUPP;
+ }
+ if (mask->tp_dst) {
+ VLOG_DBG_RL(&rl,
+ "offloading attribute icmp_code isn't supported");
+ return EOPNOTSUPP;
+ }
+ } else if (key->dl_type == htons(ETH_TYPE_IP) &&
+ key->nw_proto == IPPROTO_IGMP) {
+ if (mask->tp_src) {
+ VLOG_DBG_RL(&rl,
+ "offloading attribute igmp_type isn't supported");
+ return EOPNOTSUPP;
+ }
+ if (mask->tp_dst) {
+ VLOG_DBG_RL(&rl,
+ "offloading attribute igmp_code isn't supported");
+ return EOPNOTSUPP;
+ }
+ } else if (key->dl_type == htons(ETH_TYPE_IPV6) &&
+ key->nw_proto == IPPROTO_ICMPV6) {
+ if (mask->tp_src) {
+ VLOG_DBG_RL(&rl,
+ "offloading attribute icmp_type isn't supported");
+ return EOPNOTSUPP;
+ }
+ if (mask->tp_dst) {
+ VLOG_DBG_RL(&rl,
+ "offloading attribute icmp_code isn't supported");
+ return EOPNOTSUPP;
+ }
+ }
+ if (is_ip_any(key) && key->nw_proto == IPPROTO_TCP && mask->tcp_flags) {
+ if (mask->tcp_flags) {
+ VLOG_DBG_RL(&rl,
+ "offloading attribute tcp_flags isn't supported");
+ return EOPNOTSUPP;
+ }
+ }
+
+ if (!is_all_zeros(mask, sizeof *mask)) {
+ VLOG_DBG_RL(&rl, "offloading isn't supported, unknown attribute");
+ return EOPNOTSUPP;
+ }
+
+ return 0;
+}
+
int
-netdev_tc_flow_put(struct netdev *netdev OVS_UNUSED,
- struct match *match OVS_UNUSED,
- struct nlattr *actions OVS_UNUSED,
- size_t actions_len OVS_UNUSED,
- struct dpif_flow_stats *stats OVS_UNUSED,
- const ovs_u128 *ufid OVS_UNUSED,
- struct offload_info *info OVS_UNUSED)
+netdev_tc_flow_put(struct netdev *netdev,
+ struct match *match,
+ struct nlattr *actions,
+ size_t actions_len,
+ const ovs_u128 *ufid,
+ struct offload_info *info,
+ struct dpif_flow_stats *stats OVS_UNUSED)
{
- return EOPNOTSUPP;
+ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
+ struct tc_flower flower;
+ const struct flow *key = &match->flow;
+ struct flow *mask = &match->wc.masks;
+ const struct flow_tnl *tnl = &match->flow.tunnel;
+ struct nlattr *nla;
+ size_t left;
+ int prio = 0;
+ int handle;
+ int ifindex;
+ int err;
+
+ ifindex = netdev_get_ifindex(netdev);
+ if (ifindex < 0) {
+ VLOG_ERR_RL(&rl_err, "failed to get ifindex for %s: %s",
+ netdev_get_name(netdev), ovs_strerror(-ifindex));
+ return -ifindex;
+ }
+
+ memset(&flower, 0, sizeof flower);
+
+ if (tnl->tun_id) {
+ VLOG_DBG_RL(&rl,
+ "tunnel: id %#" PRIx64 " src " IP_FMT
+ " dst " IP_FMT " tp_src %d tp_dst %d",
+ ntohll(tnl->tun_id),
+ IP_ARGS(tnl->ip_src), IP_ARGS(tnl->ip_dst),
+ ntohs(tnl->tp_src), ntohs(tnl->tp_dst));
+ flower.tunnel.id = tnl->tun_id;
+ flower.tunnel.ipv4.ipv4_src = tnl->ip_src;
+ flower.tunnel.ipv4.ipv4_dst = tnl->ip_dst;
+ flower.tunnel.ipv6.ipv6_src = tnl->ipv6_src;
+ flower.tunnel.ipv6.ipv6_dst = tnl->ipv6_dst;
+ flower.tunnel.tp_src = tnl->tp_src;
+ flower.tunnel.tp_dst = tnl->tp_dst;
+ flower.tunnel.tunnel = true;
+
+ memset(&mask->tunnel, 0, sizeof mask->tunnel);
+ }
+
+ flower.key.eth_type = key->dl_type;
+ flower.mask.eth_type = mask->dl_type;
+
+ if (mask->vlans[0].tci) {
+ ovs_be16 vid_mask = mask->vlans[0].tci & htons(VLAN_VID_MASK);
+ ovs_be16 pcp_mask = mask->vlans[0].tci & htons(VLAN_PCP_MASK);
+ ovs_be16 cfi = mask->vlans[0].tci & htons(VLAN_CFI);
+
+ if (cfi && key->vlans[0].tci & htons(VLAN_CFI)
+ && (!vid_mask || vid_mask == htons(VLAN_VID_MASK))
+ && (!pcp_mask || pcp_mask == htons(VLAN_PCP_MASK))
+ && (vid_mask || pcp_mask)) {
+ if (vid_mask) {
+ flower.key.vlan_id = vlan_tci_to_vid(key->vlans[0].tci);
+ VLOG_DBG_RL(&rl, "vlan_id: %d\n", flower.key.vlan_id);
+ }
+ if (pcp_mask) {
+ flower.key.vlan_prio = vlan_tci_to_pcp(key->vlans[0].tci);
+ VLOG_DBG_RL(&rl, "vlan_prio: %d\n", flower.key.vlan_prio);
+ }
+ flower.key.encap_eth_type = flower.key.eth_type;
+ flower.key.eth_type = htons(ETH_TYPE_VLAN);
+ } else if (mask->vlans[0].tci == htons(0xffff) &&
+ ntohs(key->vlans[0].tci) == 0) {
+ /* exact && no vlan */
+ } else {
+ /* partial mask */
+ return EOPNOTSUPP;
+ }
+ } else if (mask->vlans[1].tci) {
+ return EOPNOTSUPP;
+ }
+ memset(mask->vlans, 0, sizeof mask->vlans);
+
+ flower.key.dst_mac = key->dl_dst;
+ memset(&flower.mask.dst_mac, 0xFF, sizeof(flower.mask.dst_mac));
+ flower.key.src_mac = key->dl_src;
+ flower.mask.src_mac = mask->dl_src;