2017-06-13 18:03:24 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Nicira, Inc.
|
2017-06-13 18:03:27 +03:00
|
|
|
* Copyright (c) 2016 Mellanox Technologies, Ltd.
|
2017-06-13 18:03:24 +03:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TC_H
|
|
|
|
#define TC_H 1
|
|
|
|
|
2017-11-06 14:42:32 -08:00
|
|
|
#include <sys/types.h>
|
2017-06-19 14:33:22 -07:00
|
|
|
#include <netinet/in.h> /* Must happen before linux/pkt_cls.h - Glibc #20215 */
|
2017-06-13 18:03:24 +03:00
|
|
|
#include <linux/pkt_cls.h>
|
|
|
|
#include <linux/pkt_sched.h>
|
2017-06-19 14:33:23 -07:00
|
|
|
|
|
|
|
#include "netlink-socket.h"
|
2017-06-13 18:03:27 +03:00
|
|
|
#include "odp-netlink.h"
|
2017-06-13 18:03:24 +03:00
|
|
|
#include "openvswitch/ofpbuf.h"
|
|
|
|
|
2017-06-13 18:03:27 +03:00
|
|
|
/* For backwards compatability with older kernels */
|
|
|
|
#ifndef TC_H_CLSACT
|
|
|
|
#define TC_H_CLSACT TC_H_INGRESS
|
|
|
|
#endif
|
|
|
|
#ifndef TC_H_MIN_INGRESS
|
|
|
|
#define TC_H_MIN_INGRESS 0xFFF2U
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define TC_INGRESS_PARENT TC_H_MAKE(TC_H_CLSACT, TC_H_MIN_INGRESS)
|
|
|
|
|
2017-06-13 18:03:30 +03:00
|
|
|
#define TC_POLICY_DEFAULT "none"
|
|
|
|
|
2017-06-13 18:03:26 +03:00
|
|
|
/* Returns tc handle 'major':'minor'. */
|
|
|
|
static inline unsigned int
|
|
|
|
tc_make_handle(unsigned int major, unsigned int minor)
|
|
|
|
{
|
|
|
|
return TC_H_MAKE(major << 16, minor);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns the major number from 'handle'. */
|
|
|
|
static inline unsigned int
|
|
|
|
tc_get_major(unsigned int handle)
|
|
|
|
{
|
|
|
|
return TC_H_MAJ(handle) >> 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns the minor number from 'handle'. */
|
|
|
|
static inline unsigned int
|
|
|
|
tc_get_minor(unsigned int handle)
|
|
|
|
{
|
|
|
|
return TC_H_MIN(handle);
|
|
|
|
}
|
|
|
|
|
2017-06-13 18:03:24 +03:00
|
|
|
struct tcmsg *tc_make_request(int ifindex, int type,
|
|
|
|
unsigned int flags, struct ofpbuf *);
|
|
|
|
int tc_transact(struct ofpbuf *request, struct ofpbuf **replyp);
|
2018-06-28 17:03:02 +01:00
|
|
|
int tc_add_del_ingress_qdisc(int ifindex, bool add, uint32_t block_id);
|
2017-06-13 18:03:24 +03:00
|
|
|
|
2017-06-13 18:03:27 +03:00
|
|
|
struct tc_cookie {
|
|
|
|
const void *data;
|
|
|
|
size_t len;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tc_flower_key {
|
|
|
|
ovs_be16 eth_type;
|
|
|
|
uint8_t ip_proto;
|
|
|
|
|
|
|
|
struct eth_addr dst_mac;
|
|
|
|
struct eth_addr src_mac;
|
|
|
|
|
2017-08-03 16:38:24 +03:00
|
|
|
ovs_be16 tcp_src;
|
|
|
|
ovs_be16 tcp_dst;
|
2017-08-07 18:19:10 +03:00
|
|
|
ovs_be16 tcp_flags;
|
2017-08-03 16:38:24 +03:00
|
|
|
|
|
|
|
ovs_be16 udp_src;
|
|
|
|
ovs_be16 udp_dst;
|
|
|
|
|
|
|
|
ovs_be16 sctp_src;
|
|
|
|
ovs_be16 sctp_dst;
|
2017-06-13 18:03:27 +03:00
|
|
|
|
|
|
|
uint16_t vlan_id;
|
|
|
|
uint8_t vlan_prio;
|
|
|
|
|
|
|
|
ovs_be16 encap_eth_type;
|
|
|
|
|
2018-03-12 14:58:47 +02:00
|
|
|
uint8_t flags;
|
2017-08-07 18:19:06 +03:00
|
|
|
uint8_t ip_ttl;
|
|
|
|
|
2017-08-03 16:38:24 +03:00
|
|
|
struct {
|
|
|
|
ovs_be32 ipv4_src;
|
|
|
|
ovs_be32 ipv4_dst;
|
2017-09-18 07:16:03 +03:00
|
|
|
uint8_t rewrite_ttl;
|
2017-08-03 16:38:24 +03:00
|
|
|
} ipv4;
|
|
|
|
struct {
|
|
|
|
struct in6_addr ipv6_src;
|
|
|
|
struct in6_addr ipv6_dst;
|
|
|
|
} ipv6;
|
2017-06-13 18:03:27 +03:00
|
|
|
};
|
|
|
|
|
2018-04-10 14:18:08 +09:00
|
|
|
enum tc_action_type {
|
|
|
|
TC_ACT_OUTPUT,
|
|
|
|
TC_ACT_ENCAP,
|
|
|
|
TC_ACT_PEDIT,
|
|
|
|
TC_ACT_VLAN_POP,
|
|
|
|
TC_ACT_VLAN_PUSH,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tc_action {
|
|
|
|
union {
|
|
|
|
int ifindex_out;
|
|
|
|
|
|
|
|
struct {
|
2018-07-17 02:01:54 +00:00
|
|
|
ovs_be16 vlan_push_tpid;
|
2018-04-10 14:18:08 +09:00
|
|
|
uint16_t vlan_push_id;
|
|
|
|
uint8_t vlan_push_prio;
|
|
|
|
} vlan;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
ovs_be64 id;
|
|
|
|
ovs_be16 tp_src;
|
|
|
|
ovs_be16 tp_dst;
|
|
|
|
struct {
|
|
|
|
ovs_be32 ipv4_src;
|
|
|
|
ovs_be32 ipv4_dst;
|
|
|
|
} ipv4;
|
|
|
|
struct {
|
|
|
|
struct in6_addr ipv6_src;
|
|
|
|
struct in6_addr ipv6_dst;
|
|
|
|
} ipv6;
|
|
|
|
} encap;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum tc_action_type type;
|
|
|
|
};
|
|
|
|
|
dpctl: Properly reflect a rule's offloaded to HW state
Previously, any rule that is offloaded via a netdev, not necessarily
to the HW, would be reported as "offloaded". This patch fixes this
misalignment, and introduces the 'dp' state, as follows:
rule is in HW via TC offload -> offloaded=yes dp:tc
rule is in not HW over TC DP -> offloaded=no dp:tc
rule is in not HW over OVS DP -> offloaded=no dp:ovs
To achieve this, the flows's 'offloaded' flag was encapsulated in a new
attrs struct, which contains the offloaded state of the flow and the
DP layer the flow is handled in, and instead of setting the flow's
'offloaded' state based solely on the type of dump it was acquired
via, for netdev flows it now sends the new attrs struct to be
collected along with the rest of the flow via the netdev, allowing
it to be set per flow.
For TC offloads, the offloaded state is set based on the 'in_hw' and
'not_in_hw' flags received from the TC as part of the flower. If no
such flag was received, due to lack of kernel support, it defaults
to true.
Signed-off-by: Gavi Teitz <gavi@mellanox.com>
Acked-by: Roi Dayan <roid@mellanox.com>
[simon: resolved conflict in lib/dpctl.man]
Signed-off-by: Simon Horman <simon.horman@netronome.com>
2018-06-07 09:36:59 +03:00
|
|
|
enum tc_offloaded_state {
|
|
|
|
TC_OFFLOADED_STATE_UNDEFINED,
|
|
|
|
TC_OFFLOADED_STATE_IN_HW,
|
|
|
|
TC_OFFLOADED_STATE_NOT_IN_HW,
|
|
|
|
};
|
|
|
|
|
2017-06-13 18:03:27 +03:00
|
|
|
struct tc_flower {
|
|
|
|
uint32_t handle;
|
|
|
|
uint32_t prio;
|
|
|
|
|
|
|
|
struct tc_flower_key key;
|
|
|
|
struct tc_flower_key mask;
|
|
|
|
|
2018-04-10 14:18:08 +09:00
|
|
|
int action_count;
|
|
|
|
struct tc_action actions[TCA_ACT_MAX_PRIO];
|
2017-06-13 18:03:27 +03:00
|
|
|
|
|
|
|
struct ovs_flow_stats stats;
|
|
|
|
uint64_t lastused;
|
|
|
|
|
2017-09-18 07:16:03 +03:00
|
|
|
struct {
|
|
|
|
bool rewrite;
|
|
|
|
struct tc_flower_key key;
|
|
|
|
struct tc_flower_key mask;
|
|
|
|
} rewrite;
|
|
|
|
|
|
|
|
uint32_t csum_update_flags;
|
|
|
|
|
2017-06-13 18:03:27 +03:00
|
|
|
struct {
|
|
|
|
bool tunnel;
|
|
|
|
struct {
|
|
|
|
ovs_be32 ipv4_src;
|
|
|
|
ovs_be32 ipv4_dst;
|
|
|
|
} ipv4;
|
|
|
|
struct {
|
|
|
|
struct in6_addr ipv6_src;
|
|
|
|
struct in6_addr ipv6_dst;
|
|
|
|
} ipv6;
|
|
|
|
ovs_be64 id;
|
|
|
|
ovs_be16 tp_src;
|
|
|
|
ovs_be16 tp_dst;
|
|
|
|
} tunnel;
|
|
|
|
|
|
|
|
struct tc_cookie act_cookie;
|
2017-11-21 14:40:38 +02:00
|
|
|
|
|
|
|
bool needs_full_ip_proto_mask;
|
dpctl: Properly reflect a rule's offloaded to HW state
Previously, any rule that is offloaded via a netdev, not necessarily
to the HW, would be reported as "offloaded". This patch fixes this
misalignment, and introduces the 'dp' state, as follows:
rule is in HW via TC offload -> offloaded=yes dp:tc
rule is in not HW over TC DP -> offloaded=no dp:tc
rule is in not HW over OVS DP -> offloaded=no dp:ovs
To achieve this, the flows's 'offloaded' flag was encapsulated in a new
attrs struct, which contains the offloaded state of the flow and the
DP layer the flow is handled in, and instead of setting the flow's
'offloaded' state based solely on the type of dump it was acquired
via, for netdev flows it now sends the new attrs struct to be
collected along with the rest of the flow via the netdev, allowing
it to be set per flow.
For TC offloads, the offloaded state is set based on the 'in_hw' and
'not_in_hw' flags received from the TC as part of the flower. If no
such flag was received, due to lack of kernel support, it defaults
to true.
Signed-off-by: Gavi Teitz <gavi@mellanox.com>
Acked-by: Roi Dayan <roid@mellanox.com>
[simon: resolved conflict in lib/dpctl.man]
Signed-off-by: Simon Horman <simon.horman@netronome.com>
2018-06-07 09:36:59 +03:00
|
|
|
|
|
|
|
enum tc_offloaded_state offloaded_state;
|
2017-06-13 18:03:27 +03:00
|
|
|
};
|
|
|
|
|
2017-09-18 07:16:03 +03:00
|
|
|
/* assert that if we overflow with a masked write of uint32_t to the last byte
|
|
|
|
* of flower.rewrite we overflow inside struct flower.
|
|
|
|
* shouldn't happen unless someone moves rewrite to the end of flower */
|
|
|
|
BUILD_ASSERT_DECL(offsetof(struct tc_flower, rewrite)
|
|
|
|
+ MEMBER_SIZEOF(struct tc_flower, rewrite)
|
|
|
|
+ sizeof(uint32_t) - 2 < sizeof(struct tc_flower));
|
|
|
|
|
2017-06-13 18:03:27 +03:00
|
|
|
int tc_replace_flower(int ifindex, uint16_t prio, uint32_t handle,
|
2018-06-28 17:03:02 +01:00
|
|
|
struct tc_flower *flower, uint32_t block_id);
|
|
|
|
int tc_del_filter(int ifindex, int prio, int handle, uint32_t block_id);
|
2017-06-13 18:03:27 +03:00
|
|
|
int tc_get_flower(int ifindex, int prio, int handle,
|
2018-06-28 17:03:02 +01:00
|
|
|
struct tc_flower *flower, uint32_t block_id);
|
|
|
|
int tc_flush(int ifindex, uint32_t block_id);
|
|
|
|
int tc_dump_flower_start(int ifindex, struct nl_dump *dump, uint32_t block_id);
|
2017-06-13 18:03:27 +03:00
|
|
|
int parse_netlink_to_tc_flower(struct ofpbuf *reply,
|
|
|
|
struct tc_flower *flower);
|
2017-06-13 18:03:30 +03:00
|
|
|
void tc_set_policy(const char *policy);
|
2017-06-13 18:03:27 +03:00
|
|
|
|
2017-06-13 18:03:24 +03:00
|
|
|
#endif /* tc.h */
|