#include <config.h>
#include "netdev-tc-offloads.h"
+
#include <errno.h>
#include <linux/if_ether.h>
+
+#include "dpif.h"
+#include "hash.h"
#include "openvswitch/hmap.h"
#include "openvswitch/match.h"
#include "openvswitch/ofpbuf.h"
#include "openvswitch/thread.h"
#include "openvswitch/types.h"
+#include "openvswitch/util.h"
#include "openvswitch/vlog.h"
-#include "netdev-provider.h"
+#include "netdev-linux.h"
#include "netlink.h"
#include "netlink-socket.h"
#include "odp-netlink.h"
+#include "odp-util.h"
+#include "tc.h"
#include "unaligned.h"
#include "util.h"
-#include "hash.h"
-#include "dpif.h"
-#include "tc.h"
VLOG_DEFINE_THIS_MODULE(netdev_tc_offloads);
static struct vlog_rate_limit error_rl = VLOG_RATE_LIMIT_INIT(60, 5);
static struct hmap ufid_tc = HMAP_INITIALIZER(&ufid_tc);
+static bool multi_mask_per_prio = false;
+
+struct netlink_field {
+ int offset;
+ int flower_offset;
+ int size;
+};
+
+static struct netlink_field set_flower_map[][3] = {
+ [OVS_KEY_ATTR_IPV4] = {
+ { offsetof(struct ovs_key_ipv4, ipv4_src),
+ offsetof(struct tc_flower_key, ipv4.ipv4_src),
+ MEMBER_SIZEOF(struct tc_flower_key, ipv4.ipv4_src)
+ },
+ { offsetof(struct ovs_key_ipv4, ipv4_dst),
+ offsetof(struct tc_flower_key, ipv4.ipv4_dst),
+ MEMBER_SIZEOF(struct tc_flower_key, ipv4.ipv4_dst)
+ },
+ { offsetof(struct ovs_key_ipv4, ipv4_ttl),
+ offsetof(struct tc_flower_key, ipv4.rewrite_ttl),
+ MEMBER_SIZEOF(struct tc_flower_key, ipv4.rewrite_ttl)
+ },
+ },
+ [OVS_KEY_ATTR_IPV6] = {
+ { offsetof(struct ovs_key_ipv6, ipv6_src),
+ offsetof(struct tc_flower_key, ipv6.ipv6_src),
+ MEMBER_SIZEOF(struct tc_flower_key, ipv6.ipv6_src)
+ },
+ { offsetof(struct ovs_key_ipv6, ipv6_dst),
+ offsetof(struct tc_flower_key, ipv6.ipv6_dst),
+ MEMBER_SIZEOF(struct tc_flower_key, ipv6.ipv6_dst)
+ },
+ },
+ [OVS_KEY_ATTR_ETHERNET] = {
+ { offsetof(struct ovs_key_ethernet, eth_src),
+ offsetof(struct tc_flower_key, src_mac),
+ MEMBER_SIZEOF(struct tc_flower_key, src_mac)
+ },
+ { offsetof(struct ovs_key_ethernet, eth_dst),
+ offsetof(struct tc_flower_key, dst_mac),
+ MEMBER_SIZEOF(struct tc_flower_key, dst_mac)
+ },
+ },
+ [OVS_KEY_ATTR_ETHERTYPE] = {
+ { 0,
+ offsetof(struct tc_flower_key, eth_type),
+ MEMBER_SIZEOF(struct tc_flower_key, eth_type)
+ },
+ },
+ [OVS_KEY_ATTR_TCP] = {
+ { offsetof(struct ovs_key_tcp, tcp_src),
+ offsetof(struct tc_flower_key, tcp_src),
+ MEMBER_SIZEOF(struct tc_flower_key, tcp_src)
+ },
+ { offsetof(struct ovs_key_tcp, tcp_dst),
+ offsetof(struct tc_flower_key, tcp_dst),
+ MEMBER_SIZEOF(struct tc_flower_key, tcp_dst)
+ },
+ },
+ [OVS_KEY_ATTR_UDP] = {
+ { offsetof(struct ovs_key_udp, udp_src),
+ offsetof(struct tc_flower_key, udp_src),
+ MEMBER_SIZEOF(struct tc_flower_key, udp_src)
+ },
+ { offsetof(struct ovs_key_udp, udp_dst),
+ offsetof(struct tc_flower_key, udp_dst),
+ MEMBER_SIZEOF(struct tc_flower_key, udp_dst)
+ },
+ },
+};
+
static struct ovs_mutex ufid_lock = OVS_MUTEX_INITIALIZER;
/**
static struct ovs_mutex prios_lock = OVS_MUTEX_INITIALIZER;
static uint16_t last_prio = 0;
size_t key_len = sizeof(struct tc_flower_key);
- size_t hash = hash_bytes(&flower->mask, key_len,
- (OVS_FORCE uint32_t) flower->key.eth_type);
+ size_t hash = hash_int((OVS_FORCE uint32_t) flower->key.eth_type, 0);
struct prio_map_data *data;
struct prio_map_data *new_data;
+ if (!multi_mask_per_prio) {
+ hash = hash_bytes(&flower->mask, key_len, hash);
+ }
+
/* We can use the same prio for same mask/eth combination but must have
* different prio if not. Flower classifier will reject same prio for
- * different mask/eth combination. */
+ * different mask combination unless multi mask per prio is supported. */
ovs_mutex_lock(&prios_lock);
HMAP_FOR_EACH_WITH_HASH(data, node, hash, &prios) {
- if (!memcmp(&flower->mask, &data->mask, key_len)
+ if ((multi_mask_per_prio
+ || !memcmp(&flower->mask, &data->mask, key_len))
&& data->protocol == flower->key.eth_type) {
ovs_mutex_unlock(&prios_lock);
return data->prio;
int ifindex = netdev_get_ifindex(netdev);
if (ifindex < 0) {
- VLOG_ERR_RL(&error_rl, "failed to get ifindex for %s: %s",
+ VLOG_ERR_RL(&error_rl, "flow_flush: failed to get ifindex for %s: %s",
netdev_get_name(netdev), ovs_strerror(-ifindex));
return -ifindex;
}
ifindex = netdev_get_ifindex(netdev);
if (ifindex < 0) {
- VLOG_ERR_RL(&error_rl, "failed to get ifindex for %s: %s",
+ VLOG_ERR_RL(&error_rl, "dump_create: failed to get ifindex for %s: %s",
netdev_get_name(netdev), ovs_strerror(-ifindex));
return -ifindex;
}
return 0;
}
+static void
+parse_flower_rewrite_to_netlink_action(struct ofpbuf *buf,
+ struct tc_flower *flower)
+{
+ char *mask = (char *) &flower->rewrite.mask;
+ char *data = (char *) &flower->rewrite.key;
+
+ for (int type = 0; type < ARRAY_SIZE(set_flower_map); type++) {
+ char *put = NULL;
+ size_t nested = 0;
+ int len = ovs_flow_key_attr_lens[type].len;
+
+ if (len <= 0) {
+ continue;
+ }
+
+ for (int j = 0; j < ARRAY_SIZE(set_flower_map[type]); j++) {
+ struct netlink_field *f = &set_flower_map[type][j];
+
+ if (!f->size) {
+ break;
+ }
+
+ if (!is_all_zeros(mask + f->flower_offset, f->size)) {
+ if (!put) {
+ nested = nl_msg_start_nested(buf,
+ OVS_ACTION_ATTR_SET_MASKED);
+ put = nl_msg_put_unspec_zero(buf, type, len * 2);
+ }
+
+ memcpy(put + f->offset, data + f->flower_offset, f->size);
+ memcpy(put + len + f->offset,
+ mask + f->flower_offset, f->size);
+ }
+ }
+
+ if (put) {
+ nl_msg_end_nested(buf, nested);
+ }
+ }
+}
+
static int
parse_tc_flower_to_match(struct tc_flower *flower,
struct match *match,
struct nlattr **actions,
struct dpif_flow_stats *stats,
- struct ofpbuf *buf) {
+ struct ofpbuf *buf)
+{
size_t act_off;
struct tc_flower_key *key = &flower->key;
struct tc_flower_key *mask = &flower->mask;
odp_port_t outport = 0;
-
- if (flower->ifindex_out) {
- outport = netdev_ifindex_to_odp_port(flower->ifindex_out);
- if (!outport) {
- return ENOENT;
- }
- }
+ struct tc_action *action;
+ int i;
ofpbuf_clear(buf);
match_set_dl_type(match, key->eth_type);
}
- if (key->ip_proto && is_ip_any(&match->flow)) {
- match_set_nw_proto(match, key->ip_proto);
- }
+ if (is_ip_any(&match->flow)) {
+ if (key->ip_proto) {
+ match_set_nw_proto(match, key->ip_proto);
+ }
- match_set_nw_src_masked(match, key->ipv4.ipv4_src, mask->ipv4.ipv4_src);
- match_set_nw_dst_masked(match, key->ipv4.ipv4_dst, mask->ipv4.ipv4_dst);
+ match_set_nw_ttl_masked(match, key->ip_ttl, mask->ip_ttl);
- match_set_ipv6_src_masked(match,
- &key->ipv6.ipv6_src, &mask->ipv6.ipv6_src);
- match_set_ipv6_dst_masked(match,
- &key->ipv6.ipv6_dst, &mask->ipv6.ipv6_dst);
+ if (mask->flags) {
+ uint8_t flags = 0;
+ uint8_t flags_mask = 0;
- match_set_tp_dst_masked(match, key->dst_port, mask->dst_port);
- match_set_tp_src_masked(match, key->src_port, mask->src_port);
+ if (mask->flags & TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT) {
+ if (key->flags & TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT) {
+ flags |= FLOW_NW_FRAG_ANY;
+ }
+ flags_mask |= FLOW_NW_FRAG_ANY;
+ }
+
+ if (mask->flags & TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST) {
+ if (!(key->flags & TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST)) {
+ flags |= FLOW_NW_FRAG_LATER;
+ }
+ flags_mask |= FLOW_NW_FRAG_LATER;
+ }
+
+ match_set_nw_frag_masked(match, flags, flags_mask);
+ }
+
+ match_set_nw_src_masked(match, key->ipv4.ipv4_src, mask->ipv4.ipv4_src);
+ match_set_nw_dst_masked(match, key->ipv4.ipv4_dst, mask->ipv4.ipv4_dst);
+
+ match_set_ipv6_src_masked(match,
+ &key->ipv6.ipv6_src, &mask->ipv6.ipv6_src);
+ match_set_ipv6_dst_masked(match,
+ &key->ipv6.ipv6_dst, &mask->ipv6.ipv6_dst);
+
+ if (key->ip_proto == IPPROTO_TCP) {
+ match_set_tp_dst_masked(match, key->tcp_dst, mask->tcp_dst);
+ match_set_tp_src_masked(match, key->tcp_src, mask->tcp_src);
+ match_set_tcp_flags_masked(match, key->tcp_flags, mask->tcp_flags);
+ } else if (key->ip_proto == IPPROTO_UDP) {
+ match_set_tp_dst_masked(match, key->udp_dst, mask->udp_dst);
+ match_set_tp_src_masked(match, key->udp_src, mask->udp_src);
+ } else if (key->ip_proto == IPPROTO_SCTP) {
+ match_set_tp_dst_masked(match, key->sctp_dst, mask->sctp_dst);
+ match_set_tp_src_masked(match, key->sctp_src, mask->sctp_src);
+ }
+ }
if (flower->tunnel.tunnel) {
match_set_tun_id(match, flower->tunnel.id);
act_off = nl_msg_start_nested(buf, OVS_FLOW_ATTR_ACTIONS);
{
- if (flower->vlan_pop) {
- nl_msg_put_flag(buf, OVS_ACTION_ATTR_POP_VLAN);
- }
-
- if (flower->vlan_push_id || flower->vlan_push_prio) {
- struct ovs_action_push_vlan *push;
- push = nl_msg_put_unspec_zero(buf, OVS_ACTION_ATTR_PUSH_VLAN,
- sizeof *push);
-
- push->vlan_tpid = htons(ETH_TYPE_VLAN);
- push->vlan_tci = htons(flower->vlan_push_id
- | (flower->vlan_push_prio << 13)
- | VLAN_CFI);
- }
-
- if (flower->set.set) {
- size_t set_offset = nl_msg_start_nested(buf, OVS_ACTION_ATTR_SET);
- size_t tunnel_offset =
- nl_msg_start_nested(buf, OVS_KEY_ATTR_TUNNEL);
-
- nl_msg_put_be64(buf, OVS_TUNNEL_KEY_ATTR_ID, flower->set.id);
- if (flower->set.ipv4.ipv4_src) {
- nl_msg_put_be32(buf, OVS_TUNNEL_KEY_ATTR_IPV4_SRC,
- flower->set.ipv4.ipv4_src);
- }
- if (flower->set.ipv4.ipv4_dst) {
- nl_msg_put_be32(buf, OVS_TUNNEL_KEY_ATTR_IPV4_DST,
- flower->set.ipv4.ipv4_dst);
+ action = flower->actions;
+ for (i = 0; i < flower->action_count; i++, action++) {
+ switch (action->type) {
+ case TC_ACT_VLAN_POP: {
+ nl_msg_put_flag(buf, OVS_ACTION_ATTR_POP_VLAN);
}
- if (!is_all_zeros(&flower->set.ipv6.ipv6_src,
- sizeof flower->set.ipv6.ipv6_src)) {
- nl_msg_put_in6_addr(buf, OVS_TUNNEL_KEY_ATTR_IPV6_SRC,
- &flower->set.ipv6.ipv6_src);
+ break;
+ case TC_ACT_VLAN_PUSH: {
+ struct ovs_action_push_vlan *push;
+
+ push = nl_msg_put_unspec_zero(buf, OVS_ACTION_ATTR_PUSH_VLAN,
+ sizeof *push);
+ push->vlan_tpid = htons(ETH_TYPE_VLAN);
+ push->vlan_tci = htons(action->vlan.vlan_push_id
+ | (action->vlan.vlan_push_prio << 13)
+ | VLAN_CFI);
}
- if (!is_all_zeros(&flower->set.ipv6.ipv6_dst,
- sizeof flower->set.ipv6.ipv6_dst)) {
- nl_msg_put_in6_addr(buf, OVS_TUNNEL_KEY_ATTR_IPV6_DST,
- &flower->set.ipv6.ipv6_dst);
+ break;
+ case TC_ACT_PEDIT: {
+ parse_flower_rewrite_to_netlink_action(buf, flower);
}
- nl_msg_put_be16(buf, OVS_TUNNEL_KEY_ATTR_TP_DST,
- flower->set.tp_dst);
-
- nl_msg_end_nested(buf, tunnel_offset);
- nl_msg_end_nested(buf, set_offset);
- }
+ break;
+ case TC_ACT_ENCAP: {
+ size_t set_offset = nl_msg_start_nested(buf, OVS_ACTION_ATTR_SET);
+ size_t tunnel_offset =
+ nl_msg_start_nested(buf, OVS_KEY_ATTR_TUNNEL);
+
+ nl_msg_put_be64(buf, OVS_TUNNEL_KEY_ATTR_ID, action->encap.id);
+ if (action->encap.ipv4.ipv4_src) {
+ nl_msg_put_be32(buf, OVS_TUNNEL_KEY_ATTR_IPV4_SRC,
+ action->encap.ipv4.ipv4_src);
+ }
+ if (action->encap.ipv4.ipv4_dst) {
+ nl_msg_put_be32(buf, OVS_TUNNEL_KEY_ATTR_IPV4_DST,
+ action->encap.ipv4.ipv4_dst);
+ }
+ if (!is_all_zeros(&action->encap.ipv6.ipv6_src,
+ sizeof action->encap.ipv6.ipv6_src)) {
+ nl_msg_put_in6_addr(buf, OVS_TUNNEL_KEY_ATTR_IPV6_SRC,
+ &action->encap.ipv6.ipv6_src);
+ }
+ if (!is_all_zeros(&action->encap.ipv6.ipv6_dst,
+ sizeof action->encap.ipv6.ipv6_dst)) {
+ nl_msg_put_in6_addr(buf, OVS_TUNNEL_KEY_ATTR_IPV6_DST,
+ &action->encap.ipv6.ipv6_dst);
+ }
+ nl_msg_put_be16(buf, OVS_TUNNEL_KEY_ATTR_TP_DST,
+ action->encap.tp_dst);
- if (flower->ifindex_out > 0) {
- nl_msg_put_u32(buf, OVS_ACTION_ATTR_OUTPUT, odp_to_u32(outport));
+ nl_msg_end_nested(buf, tunnel_offset);
+ nl_msg_end_nested(buf, set_offset);
+ }
+ break;
+ case TC_ACT_OUTPUT: {
+ if (action->ifindex_out) {
+ outport = netdev_ifindex_to_odp_port(action->ifindex_out);
+ if (!outport) {
+ return ENOENT;
+ }
+ }
+ nl_msg_put_u32(buf, OVS_ACTION_ATTR_OUTPUT, odp_to_u32(outport));
+ }
+ break;
+ }
}
-
}
nl_msg_end_nested(buf, act_off);
}
static int
-parse_put_flow_set_action(struct tc_flower *flower, const struct nlattr *set,
- size_t set_len)
+parse_put_flow_set_masked_action(struct tc_flower *flower,
+ struct tc_action *action,
+ const struct nlattr *set,
+ size_t set_len,
+ bool hasmask)
{
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;
+ uint64_t set_stub[1024 / 8];
+ struct ofpbuf set_buf = OFPBUF_STUB_INITIALIZER(set_stub);
+ char *set_data, *set_mask;
+ char *key = (char *) &flower->rewrite.key;
+ char *mask = (char *) &flower->rewrite.mask;
+ const struct nlattr *attr;
+ int i, j, type;
+ size_t size;
+
+ /* copy so we can set attr mask to 0 for used ovs key struct members */
+ attr = ofpbuf_put(&set_buf, set, set_len);
+
+ type = nl_attr_type(attr);
+ size = nl_attr_get_size(attr) / 2;
+ set_data = CONST_CAST(char *, nl_attr_get(attr));
+ set_mask = set_data + size;
+
+ if (type >= ARRAY_SIZE(set_flower_map)
+ || !set_flower_map[type][0].size) {
+ VLOG_DBG_RL(&rl, "unsupported set action type: %d", type);
+ ofpbuf_uninit(&set_buf);
+ return EOPNOTSUPP;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(set_flower_map[type]); i++) {
+ struct netlink_field *f = &set_flower_map[type][i];
+
+ if (!f->size) {
+ break;
+ }
+
+ /* copy masked value */
+ for (j = 0; j < f->size; j++) {
+ char maskval = hasmask ? set_mask[f->offset + j] : 0xFF;
+
+ key[f->flower_offset + j] = maskval & set_data[f->offset + j];
+ mask[f->flower_offset + j] = maskval;
+
+ }
+
+ /* set its mask to 0 to show it's been used. */
+ if (hasmask) {
+ memset(set_mask + f->offset, 0, f->size);
}
}
+
+ if (!is_all_zeros(&flower->rewrite, sizeof flower->rewrite)) {
+ if (flower->rewrite.rewrite == false) {
+ flower->rewrite.rewrite = true;
+ action->type = TC_ACT_PEDIT;
+ flower->action_count++;
+ }
+ }
+
+ if (hasmask && !is_all_zeros(set_mask, size)) {
+ VLOG_DBG_RL(&rl, "unsupported sub attribute of set action type %d",
+ type);
+ ofpbuf_uninit(&set_buf);
+ return EOPNOTSUPP;
+ }
+
+ ofpbuf_uninit(&set_buf);
+ return 0;
+}
+
+static int
+parse_put_flow_set_action(struct tc_flower *flower, struct tc_action *action,
+ const struct nlattr *set, size_t set_len)
+{
+ const struct nlattr *tunnel;
+ const struct nlattr *tun_attr;
+ size_t tun_left, tunnel_len;
+
+ if (nl_attr_type(set) != OVS_KEY_ATTR_TUNNEL) {
+ return parse_put_flow_set_masked_action(flower, action, set,
+ set_len, false);
+ }
+
+ tunnel = nl_attr_get(set);
+ tunnel_len = nl_attr_get_size(set);
+
+ action->type = TC_ACT_ENCAP;
+ flower->action_count++;
+ NL_ATTR_FOR_EACH_UNSAFE(tun_attr, tun_left, tunnel, tunnel_len) {
+ switch (nl_attr_type(tun_attr)) {
+ case OVS_TUNNEL_KEY_ATTR_ID: {
+ action->encap.id = nl_attr_get_be64(tun_attr);
+ }
+ break;
+ case OVS_TUNNEL_KEY_ATTR_IPV4_SRC: {
+ action->encap.ipv4.ipv4_src = nl_attr_get_be32(tun_attr);
+ }
+ break;
+ case OVS_TUNNEL_KEY_ATTR_IPV4_DST: {
+ action->encap.ipv4.ipv4_dst = nl_attr_get_be32(tun_attr);
+ }
+ break;
+ case OVS_TUNNEL_KEY_ATTR_IPV6_SRC: {
+ action->encap.ipv6.ipv6_src =
+ nl_attr_get_in6_addr(tun_attr);
+ }
+ break;
+ case OVS_TUNNEL_KEY_ATTR_IPV6_DST: {
+ action->encap.ipv6.ipv6_dst =
+ nl_attr_get_in6_addr(tun_attr);
+ }
+ break;
+ case OVS_TUNNEL_KEY_ATTR_TP_SRC: {
+ action->encap.tp_src = nl_attr_get_be16(tun_attr);
+ }
+ break;
+ case OVS_TUNNEL_KEY_ATTR_TP_DST: {
+ action->encap.tp_dst = nl_attr_get_be16(tun_attr);
+ }
+ break;
+ }
+ }
+
return 0;
}
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 (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");
const struct flow *key = &match->flow;
struct flow *mask = &match->wc.masks;
const struct flow_tnl *tnl = &match->flow.tunnel;
+ struct tc_action *action;
struct nlattr *nla;
size_t left;
int prio = 0;
ifindex = netdev_get_ifindex(netdev);
if (ifindex < 0) {
- VLOG_ERR_RL(&error_rl, "failed to get ifindex for %s: %s",
+ VLOG_ERR_RL(&error_rl, "flow_put: 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) {
+ if (flow_tnl_dst_is_set(&key->tunnel)) {
VLOG_DBG_RL(&rl,
"tunnel: id %#" PRIx64 " src " IP_FMT
" dst " IP_FMT " tp_src %d tp_dst %d",
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);
}
+ memset(&mask->tunnel, 0, sizeof mask->tunnel);
flower.key.eth_type = key->dl_type;
flower.mask.eth_type = mask->dl_type;
if (is_ip_any(key)) {
flower.key.ip_proto = key->nw_proto;
flower.mask.ip_proto = mask->nw_proto;
+ flower.key.ip_ttl = key->nw_ttl;
+ flower.mask.ip_ttl = mask->nw_ttl;
+
+ if (mask->nw_frag & FLOW_NW_FRAG_ANY) {
+ flower.mask.flags |= TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT;
+
+ if (key->nw_frag & FLOW_NW_FRAG_ANY) {
+ flower.key.flags |= TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT;
+
+ if (mask->nw_frag & FLOW_NW_FRAG_LATER) {
+ flower.mask.flags |= TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST;
+
+ if (!(key->nw_frag & FLOW_NW_FRAG_LATER)) {
+ flower.key.flags |= TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST;
+ }
+ }
+ }
- if (key->nw_proto == IPPROTO_TCP || key->nw_proto == IPPROTO_UDP) {
- flower.key.dst_port = key->tp_dst;
- flower.mask.dst_port = mask->tp_dst;
- flower.key.src_port = key->tp_src;
- flower.mask.src_port = mask->tp_src;
+ mask->nw_frag = 0;
+ }
+
+ if (key->nw_proto == IPPROTO_TCP) {
+ flower.key.tcp_dst = key->tp_dst;
+ flower.mask.tcp_dst = mask->tp_dst;
+ flower.key.tcp_src = key->tp_src;
+ flower.mask.tcp_src = mask->tp_src;
+ flower.key.tcp_flags = key->tcp_flags;
+ flower.mask.tcp_flags = mask->tcp_flags;
+ mask->tp_src = 0;
+ mask->tp_dst = 0;
+ mask->tcp_flags = 0;
+ } else if (key->nw_proto == IPPROTO_UDP) {
+ flower.key.udp_dst = key->tp_dst;
+ flower.mask.udp_dst = mask->tp_dst;
+ flower.key.udp_src = key->tp_src;
+ flower.mask.udp_src = mask->tp_src;
+ mask->tp_src = 0;
+ mask->tp_dst = 0;
+ } else if (key->nw_proto == IPPROTO_SCTP) {
+ flower.key.sctp_dst = key->tp_dst;
+ flower.mask.sctp_dst = mask->tp_dst;
+ flower.key.sctp_src = key->tp_src;
+ flower.mask.sctp_src = mask->tp_src;
mask->tp_src = 0;
mask->tp_dst = 0;
}
- mask->nw_frag = 0;
mask->nw_tos = 0;
mask->nw_proto = 0;
+ mask->nw_ttl = 0;
if (key->dl_type == htons(ETH_P_IP)) {
flower.key.ipv4.ipv4_src = key->nw_src;
}
NL_ATTR_FOR_EACH(nla, left, actions, actions_len) {
+ if (flower.action_count >= TCA_ACT_MAX_PRIO) {
+ VLOG_DBG_RL(&rl, "Can only support %d actions", flower.action_count);
+ return EOPNOTSUPP;
+ }
+ action = &flower.actions[flower.action_count];
if (nl_attr_type(nla) == OVS_ACTION_ATTR_OUTPUT) {
odp_port_t port = nl_attr_get_odp_port(nla);
- struct netdev *outdev = netdev_ports_get(port,
- info->port_hmap_obj);
+ struct netdev *outdev = netdev_ports_get(port, info->dpif_class);
- flower.ifindex_out = netdev_get_ifindex(outdev);
- flower.set.tp_dst = info->tp_dst_port;
+ action->ifindex_out = netdev_get_ifindex(outdev);
+ action->type = TC_ACT_OUTPUT;
+ flower.action_count++;
netdev_close(outdev);
} else if (nl_attr_type(nla) == OVS_ACTION_ATTR_PUSH_VLAN) {
const struct ovs_action_push_vlan *vlan_push = nl_attr_get(nla);
- flower.vlan_push_id = vlan_tci_to_vid(vlan_push->vlan_tci);
- flower.vlan_push_prio = vlan_tci_to_pcp(vlan_push->vlan_tci);
+ action->vlan.vlan_push_id = vlan_tci_to_vid(vlan_push->vlan_tci);
+ action->vlan.vlan_push_prio = vlan_tci_to_pcp(vlan_push->vlan_tci);
+ action->type = TC_ACT_VLAN_PUSH;
+ flower.action_count++;
} else if (nl_attr_type(nla) == OVS_ACTION_ATTR_POP_VLAN) {
- flower.vlan_pop = 1;
+ action->type = TC_ACT_VLAN_POP;
+ flower.action_count++;
} else if (nl_attr_type(nla) == OVS_ACTION_ATTR_SET) {
const struct nlattr *set = nl_attr_get(nla);
const size_t set_len = nl_attr_get_size(nla);
- err = parse_put_flow_set_action(&flower, set, set_len);
+ err = parse_put_flow_set_action(&flower, action, set, set_len);
+ if (err) {
+ return err;
+ }
+ if (action->type == TC_ACT_ENCAP) {
+ action->encap.tp_dst = info->tp_dst_port;
+ }
+ } else if (nl_attr_type(nla) == OVS_ACTION_ATTR_SET_MASKED) {
+ const struct nlattr *set = nl_attr_get(nla);
+ const size_t set_len = nl_attr_get_size(nla);
+
+ err = parse_put_flow_set_masked_action(&flower, action, set,
+ set_len, true);
if (err) {
return err;
}
int
netdev_tc_flow_get(struct netdev *netdev OVS_UNUSED,
- struct match *match OVS_UNUSED,
- struct nlattr **actions OVS_UNUSED,
- const ovs_u128 *ufid OVS_UNUSED,
- struct dpif_flow_stats *stats OVS_UNUSED,
- struct ofpbuf *buf OVS_UNUSED)
+ struct match *match,
+ struct nlattr **actions,
+ const ovs_u128 *ufid,
+ struct dpif_flow_stats *stats,
+ struct ofpbuf *buf)
{
- return EOPNOTSUPP;
+ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
+ struct netdev *dev;
+ struct tc_flower flower;
+ odp_port_t in_port;
+ int prio = 0;
+ int ifindex;
+ int handle;
+ int err;
+
+ handle = get_ufid_tc_mapping(ufid, &prio, &dev);
+ if (!handle) {
+ return ENOENT;
+ }
+
+ ifindex = netdev_get_ifindex(dev);
+ if (ifindex < 0) {
+ VLOG_ERR_RL(&error_rl, "flow_get: failed to get ifindex for %s: %s",
+ netdev_get_name(dev), ovs_strerror(-ifindex));
+ netdev_close(dev);
+ return -ifindex;
+ }
+
+ VLOG_DBG_RL(&rl, "flow get (dev %s prio %d handle %d)",
+ netdev_get_name(dev), prio, handle);
+ err = tc_get_flower(ifindex, prio, handle, &flower);
+ netdev_close(dev);
+ if (err) {
+ VLOG_ERR_RL(&error_rl, "flow get failed (dev %s prio %d handle %d): %s",
+ netdev_get_name(dev), prio, handle, ovs_strerror(err));
+ return err;
+ }
+
+ in_port = netdev_ifindex_to_odp_port(ifindex);
+ parse_tc_flower_to_match(&flower, match, actions, stats, buf);
+
+ match->wc.masks.in_port.odp_port = u32_to_odp(UINT32_MAX);
+ match->flow.in_port.odp_port = in_port;
+
+ return 0;
}
int
const ovs_u128 *ufid,
struct dpif_flow_stats *stats)
{
+ struct tc_flower flower;
struct netdev *dev;
int prio = 0;
int ifindex;
ifindex = netdev_get_ifindex(dev);
if (ifindex < 0) {
- VLOG_ERR_RL(&error_rl, "failed to get ifindex for %s: %s",
+ VLOG_ERR_RL(&error_rl, "flow_del: failed to get ifindex for %s: %s",
netdev_get_name(dev), ovs_strerror(-ifindex));
netdev_close(dev);
return -ifindex;
}
+ if (stats) {
+ memset(stats, 0, sizeof *stats);
+ if (!tc_get_flower(ifindex, prio, handle, &flower)) {
+ stats->n_packets = get_32aligned_u64(&flower.stats.n_packets);
+ stats->n_bytes = get_32aligned_u64(&flower.stats.n_bytes);
+ stats->used = flower.lastused;
+ }
+ }
+
error = tc_del_filter(ifindex, prio, handle);
del_ufid_tc_mapping(ufid);
netdev_close(dev);
- if (stats) {
- memset(stats, 0, sizeof *stats);
- }
return error;
}
+static void
+probe_multi_mask_per_prio(int ifindex)
+{
+ struct tc_flower flower;
+ int error;
+
+ memset(&flower, 0, sizeof flower);
+
+ flower.key.eth_type = htons(ETH_P_IP);
+ flower.mask.eth_type = OVS_BE16_MAX;
+ memset(&flower.key.dst_mac, 0x11, sizeof flower.key.dst_mac);
+ memset(&flower.mask.dst_mac, 0xff, sizeof flower.mask.dst_mac);
+
+ error = tc_replace_flower(ifindex, 1, 1, &flower);
+ if (error) {
+ return;
+ }
+
+ memset(&flower.key.src_mac, 0x11, sizeof flower.key.src_mac);
+ memset(&flower.mask.src_mac, 0xff, sizeof flower.mask.src_mac);
+
+ error = tc_replace_flower(ifindex, 1, 2, &flower);
+ tc_del_filter(ifindex, 1, 1);
+
+ if (error) {
+ return;
+ }
+
+ tc_del_filter(ifindex, 1, 2);
+
+ multi_mask_per_prio = true;
+ VLOG_INFO("probe tc: multiple masks on single tc prio is supported.");
+}
+
int
-netdev_tc_init_flow_api(struct netdev *netdev OVS_UNUSED)
+netdev_tc_init_flow_api(struct netdev *netdev)
{
+ static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
+ int ifindex;
+ int error;
+
+ ifindex = netdev_get_ifindex(netdev);
+ if (ifindex < 0) {
+ VLOG_ERR_RL(&error_rl, "init: failed to get ifindex for %s: %s",
+ netdev_get_name(netdev), ovs_strerror(-ifindex));
+ return -ifindex;
+ }
+
+ error = tc_add_del_ingress_qdisc(ifindex, true);
+
+ if (error && error != EEXIST) {
+ VLOG_ERR("failed adding ingress qdisc required for offloading: %s",
+ ovs_strerror(error));
+ return error;
+ }
+
+ VLOG_INFO("added ingress qdisc to %s", netdev_get_name(netdev));
+
+ if (ovsthread_once_start(&once)) {
+ probe_multi_mask_per_prio(ifindex);
+ ovsthread_once_done(&once);
+ }
+
return 0;
}