Commit c7d759eb authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller
Browse files

ethtool: add tunnel info interface



Add an interface to report offloaded UDP ports via ethtool netlink.

Now that core takes care of tracking which UDP tunnel ports the NICs
are aware of we can quite easily export this information out to
user space.

The responsibility of writing the netlink dumps is split between
ethtool code and udp_tunnel_nic.c - since udp_tunnel module may
not always be loaded, yet we should always report the capabilities
of the NIC.

$ ethtool --show-tunnels eth0
Tunnel information for eth0:
  UDP port table 0:
    Size: 4
    Types: vxlan
    No entries
  UDP port table 1:
    Size: 4
    Types: geneve, vxlan-gpe
    Entries (1):
        port 1230, vxlan-gpe

v4:
 - back to v2, build fix is now directly in udp_tunnel.h
v3:
 - don't compile ETHTOOL_MSG_TUNNEL_INFO_GET in if CONFIG_INET
   not set.
v2:
 - fix string set count,
 - reorder enums in the uAPI,
 - fix type of ETHTOOL_A_TUNNEL_UDP_TABLE_TYPES to bitset
   in docs and comments.

Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent cc4e3835
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -1230,6 +1230,39 @@ used to report the amplitude of the reflection for a given pair.
 | | | ``ETHTOOL_A_CABLE_AMPLITUDE_mV``        | s16    | Reflection amplitude |
 +-+-+-----------------------------------------+--------+----------------------+

TUNNEL_INFO
===========

Gets information about the tunnel state NIC is aware of.

Request contents:

  =====================================  ======  ==========================
  ``ETHTOOL_A_TUNNEL_INFO_HEADER``       nested  request header
  =====================================  ======  ==========================

Kernel response contents:

 +---------------------------------------------+--------+---------------------+
 | ``ETHTOOL_A_TUNNEL_INFO_HEADER``            | nested | reply header        |
 +---------------------------------------------+--------+---------------------+
 | ``ETHTOOL_A_TUNNEL_INFO_UDP_PORTS``         | nested | all UDP port tables |
 +-+-------------------------------------------+--------+---------------------+
 | | ``ETHTOOL_A_TUNNEL_UDP_TABLE``            | nested | one UDP port table  |
 +-+-+-----------------------------------------+--------+---------------------+
 | | | ``ETHTOOL_A_TUNNEL_UDP_TABLE_SIZE``     | u32    | max size of the     |
 | | |                                         |        | table               |
 +-+-+-----------------------------------------+--------+---------------------+
 | | | ``ETHTOOL_A_TUNNEL_UDP_TABLE_TYPES``    | bitset | tunnel types which  |
 | | |                                         |        | table can hold      |
 +-+-+-----------------------------------------+--------+---------------------+
 | | | ``ETHTOOL_A_TUNNEL_UDP_TABLE_ENTRY``    | nested | offloaded UDP port  |
 +-+-+-+---------------------------------------+--------+---------------------+
 | | | | ``ETHTOOL_A_TUNNEL_UDP_ENTRY_PORT``   | be16   | UDP port            |
 +-+-+-+---------------------------------------+--------+---------------------+
 | | | | ``ETHTOOL_A_TUNNEL_UDP_ENTRY_TYPE``   | u32    | tunnel type         |
 +-+-+-+---------------------------------------+--------+---------------------+

Request translation
===================

+21 −0
Original line number Diff line number Diff line
@@ -255,6 +255,10 @@ struct udp_tunnel_nic_ops {
	void (*add_port)(struct net_device *dev, struct udp_tunnel_info *ti);
	void (*del_port)(struct net_device *dev, struct udp_tunnel_info *ti);
	void (*reset_ntf)(struct net_device *dev);

	size_t (*dump_size)(struct net_device *dev, unsigned int table);
	int (*dump_write)(struct net_device *dev, unsigned int table,
			  struct sk_buff *skb);
};

#ifdef CONFIG_INET
@@ -318,4 +322,21 @@ static inline void udp_tunnel_nic_reset_ntf(struct net_device *dev)
	if (udp_tunnel_nic_ops)
		udp_tunnel_nic_ops->reset_ntf(dev);
}

static inline size_t
udp_tunnel_nic_dump_size(struct net_device *dev, unsigned int table)
{
	if (!udp_tunnel_nic_ops)
		return 0;
	return udp_tunnel_nic_ops->dump_size(dev, table);
}

static inline int
udp_tunnel_nic_dump_write(struct net_device *dev, unsigned int table,
			  struct sk_buff *skb)
{
	if (!udp_tunnel_nic_ops)
		return 0;
	return udp_tunnel_nic_ops->dump_write(dev, table, skb);
}
#endif
+2 −0
Original line number Diff line number Diff line
@@ -669,6 +669,7 @@ enum ethtool_link_ext_substate_cable_issue {
 * @ETH_SS_SOF_TIMESTAMPING: SOF_TIMESTAMPING_* flags
 * @ETH_SS_TS_TX_TYPES: timestamping Tx types
 * @ETH_SS_TS_RX_FILTERS: timestamping Rx filters
 * @ETH_SS_UDP_TUNNEL_TYPES: UDP tunnel types
 */
enum ethtool_stringset {
	ETH_SS_TEST		= 0,
@@ -686,6 +687,7 @@ enum ethtool_stringset {
	ETH_SS_SOF_TIMESTAMPING,
	ETH_SS_TS_TX_TYPES,
	ETH_SS_TS_RX_FILTERS,
	ETH_SS_UDP_TUNNEL_TYPES,

	/* add new constants above here */
	ETH_SS_COUNT
+55 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ enum {
	ETHTOOL_MSG_TSINFO_GET,
	ETHTOOL_MSG_CABLE_TEST_ACT,
	ETHTOOL_MSG_CABLE_TEST_TDR_ACT,
	ETHTOOL_MSG_TUNNEL_INFO_GET,

	/* add new constants above here */
	__ETHTOOL_MSG_USER_CNT,
@@ -556,6 +557,60 @@ enum {
	ETHTOOL_A_CABLE_TEST_TDR_NTF_MAX = __ETHTOOL_A_CABLE_TEST_TDR_NTF_CNT - 1
};

/* TUNNEL INFO */

enum {
	ETHTOOL_UDP_TUNNEL_TYPE_VXLAN,
	ETHTOOL_UDP_TUNNEL_TYPE_GENEVE,
	ETHTOOL_UDP_TUNNEL_TYPE_VXLAN_GPE,

	__ETHTOOL_UDP_TUNNEL_TYPE_CNT
};

enum {
	ETHTOOL_A_TUNNEL_UDP_ENTRY_UNSPEC,

	ETHTOOL_A_TUNNEL_UDP_ENTRY_PORT,		/* be16 */
	ETHTOOL_A_TUNNEL_UDP_ENTRY_TYPE,		/* u32 */

	/* add new constants above here */
	__ETHTOOL_A_TUNNEL_UDP_ENTRY_CNT,
	ETHTOOL_A_TUNNEL_UDP_ENTRY_MAX = (__ETHTOOL_A_TUNNEL_UDP_ENTRY_CNT - 1)
};

enum {
	ETHTOOL_A_TUNNEL_UDP_TABLE_UNSPEC,

	ETHTOOL_A_TUNNEL_UDP_TABLE_SIZE,		/* u32 */
	ETHTOOL_A_TUNNEL_UDP_TABLE_TYPES,		/* bitset */
	ETHTOOL_A_TUNNEL_UDP_TABLE_ENTRY,		/* nest - _UDP_ENTRY_* */

	/* add new constants above here */
	__ETHTOOL_A_TUNNEL_UDP_TABLE_CNT,
	ETHTOOL_A_TUNNEL_UDP_TABLE_MAX = (__ETHTOOL_A_TUNNEL_UDP_TABLE_CNT - 1)
};

enum {
	ETHTOOL_A_TUNNEL_UDP_UNSPEC,

	ETHTOOL_A_TUNNEL_UDP_TABLE,			/* nest - _UDP_TABLE_* */

	/* add new constants above here */
	__ETHTOOL_A_TUNNEL_UDP_CNT,
	ETHTOOL_A_TUNNEL_UDP_MAX = (__ETHTOOL_A_TUNNEL_UDP_CNT - 1)
};

enum {
	ETHTOOL_A_TUNNEL_INFO_UNSPEC,
	ETHTOOL_A_TUNNEL_INFO_HEADER,			/* nest - _A_HEADER_* */

	ETHTOOL_A_TUNNEL_INFO_UDP_PORTS,		/* nest - _UDP_TABLE */

	/* add new constants above here */
	__ETHTOOL_A_TUNNEL_INFO_CNT,
	ETHTOOL_A_TUNNEL_INFO_MAX = (__ETHTOOL_A_TUNNEL_INFO_CNT - 1)
};

/* generic netlink info */
#define ETHTOOL_GENL_NAME "ethtool"
#define ETHTOOL_GENL_VERSION 1
+2 −1
Original line number Diff line number Diff line
@@ -6,4 +6,5 @@ obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o

ethtool_nl-y	:= netlink.o bitset.o strset.o linkinfo.o linkmodes.o \
		   linkstate.o debug.o wol.o features.o privflags.o rings.o \
		   channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o
		   channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o \
		   tunnels.o
Loading