Files
freebsd/sys/netlink/route/interface.h
T
Kevin Bowling 2019f3d86f rtnetlink: Add native SR-IOV VF status
Add a transport neutral kernel snapshot for NIC-specific SR-IOV VF
status and an optional iflib provider method.  Providers gather state
under driver defined synchronization.

Honor RTEXT_FILTER_VF on RTM_GETLINK requests and encode the status as
native typed route Netlink attributes.  Represent VFs, driver
namespaces, and namespace fields as directly repeated nested attributes.
Presence masks in consumers can distinguish omission from false or zero.

Drivers may add custom status under stable, versioned namespaces.  The
named, typed representation lets generic transports and consumers carry
or display fields without knowing their driver-specific schemas, while
the driver retains ownership of their names and meanings.

Document the ABI and add parser and RTM_GETLINK coverage.

Reviewed by:	melifaro, iflib (gallatin), kgalazka (previous version)
Sponsored by:	BBOX.io
Differential Revision:	https://reviews.freebsd.org/D58776
2026-09-06 06:51:52 -07:00

426 lines
13 KiB
C

/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2022 Alexander V. Chernikov <[email protected]>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Interface-related (RTM_<NEW|DEL|GET|SET>LINK) message header and attributes.
*/
#ifndef _NETLINK_ROUTE_INTERFACE_H_
#define _NETLINK_ROUTE_INTERFACE_H_
/* Base header for all of the relevant messages */
struct ifinfomsg {
unsigned char ifi_family; /* not used */
unsigned char __ifi_pad;
unsigned short ifi_type; /* IFT_* (net/if_types.h) */
int ifi_index; /* Interface index */
unsigned ifi_flags; /* IFF_* flags */
unsigned ifi_change; /* IFF_* change mask */
};
/* Linux-specific link-level state flag */
#define IFF_LOWER_UP IFF_NETLINK_1
#ifndef _KERNEL
/* Compatilbility helpers */
#define _IFINFO_HDRLEN ((int)sizeof(struct ifinfomsg))
#define IFLA_RTA(_ifi) ((struct rtattr *)NL_ITEM_DATA(_ifi, _IFINFO_HDRLEN))
#define IFLA_PAYLOAD(_ifi) NLMSG_PAYLOAD(_ifi, _IFINFO_HDRLEN)
#endif
enum {
IFLA_UNSPEC = 0,
IFLA_ADDRESS = 1, /* binary: Link-level address (MAC) */
#define IFLA_ADDRESS IFLA_ADDRESS
IFLA_BROADCAST = 2, /* binary: link-level broadcast address */
#define IFLA_BROADCAST IFLA_BROADCAST
IFLA_IFNAME = 3, /* string: Interface name */
#define IFLA_IFNAME IFLA_IFNAME
IFLA_MTU = 4, /* u32: Current interface L3 mtu */
#define IFLA_MTU IFLA_MTU
IFLA_LINK = 5, /* u32: interface index */
#define IFLA_LINK IFLA_LINK
IFLA_QDISC = 6, /* string: Queing policy (not supported) */
#define IFLA_QDISC IFLA_QDISC
IFLA_STATS = 7, /* Interface counters */
#define IFLA_STATS IFLA_STATS
IFLA_COST = 8, /* not supported */
#define IFLA_COST IFLA_COST
IFLA_PRIORITY = 9, /* not supported */
#define IFLA_PRIORITY IFLA_PRIORITY
IFLA_MASTER = 10, /* u32: parent interface ifindex */
#define IFLA_MASTER IFLA_MASTER
IFLA_WIRELESS = 11, /* not supported */
#define IFLA_WIRELESS IFLA_WIRELESS
IFLA_PROTINFO = 12, /* protocol-specific data */
#define IFLA_PROTINFO IFLA_PROTINFO
IFLA_TXQLEN = 13, /* u32: transmit queue length */
#define IFLA_TXQLEN IFLA_TXQLEN
IFLA_MAP = 14, /* not supported */
#define IFLA_MAP IFLA_MAP
IFLA_WEIGHT = 15, /* not supported */
#define IFLA_WEIGHT IFLA_WEIGHT
IFLA_OPERSTATE = 16, /* u8: ifOperStatus per RFC 2863 */
#define IFLA_OPERSTATE IFLA_OPERSTATE
IFLA_LINKMODE = 17, /* u8: ifmedia (not supported) */
#define IFLA_LINKMODE IFLA_LINKMODE
IFLA_LINKINFO = 18, /* nested: IFLA_INFO_ */
#define IFLA_LINKINFO IFLA_LINKINFO
IFLA_NET_NS_PID = 19, /* u32: vnet id (not supported) */
#define IFLA_NET_NS_PID IFLA_NET_NS_PID
IFLA_IFALIAS = 20, /* string: interface description */
#define IFLA_IFALIAS IFLA_IFALIAS
IFLA_NUM_VF = 21, /* u32: VF records, when requested */
#define IFLA_NUM_VF IFLA_NUM_VF
IFLA_VFINFO_LIST= 22, /* not supported */
#define IFLA_VFINFO_LIST IFLA_VFINFO_LIST
IFLA_STATS64 = 23, /* rtnl_link_stats64: iface stats */
#define IFLA_STATS64 IFLA_STATS64
IFLA_VF_PORTS,
IFLA_PORT_SELF,
IFLA_AF_SPEC,
IFLA_GROUP, /* Group the device belongs to */
IFLA_NET_NS_FD,
IFLA_EXT_MASK, /* Extended info mask, VFs, etc */
IFLA_PROMISCUITY, /* Promiscuity count: > 0 means acts PROMISC */
#define IFLA_PROMISCUITY IFLA_PROMISCUITY
IFLA_NUM_TX_QUEUES,
IFLA_NUM_RX_QUEUES,
IFLA_CARRIER,
IFLA_PHYS_PORT_ID,
IFLA_CARRIER_CHANGES,
IFLA_PHYS_SWITCH_ID,
IFLA_LINK_NETNSID,
IFLA_PHYS_PORT_NAME,
IFLA_PROTO_DOWN,
IFLA_GSO_MAX_SEGS,
IFLA_GSO_MAX_SIZE,
IFLA_PAD,
IFLA_XDP,
IFLA_EVENT,
IFLA_NEW_NETNSID,
IFLA_IF_NETNSID,
IFLA_TARGET_NETNSID = IFLA_IF_NETNSID, /* new alias */
IFLA_CARRIER_UP_COUNT,
IFLA_CARRIER_DOWN_COUNT,
IFLA_NEW_IFINDEX,
IFLA_MIN_MTU,
IFLA_MAX_MTU,
IFLA_PROP_LIST,
IFLA_ALT_IFNAME, /* Alternative ifname */
IFLA_PERM_ADDRESS,
IFLA_PROTO_DOWN_REASON,
IFLA_PARENT_DEV_NAME,
IFLA_PARENT_DEV_BUS_NAME,
IFLA_GRO_MAX_SIZE,
IFLA_TSO_MAX_SEGS,
IFLA_ALLMULTI,
IFLA_DEVLINK_PORT,
IFLA_GSO_IPV4_MAX_SIZE,
IFLA_GRO_IPV4_MAX_SIZE,
IFLA_FREEBSD,
IFLA_FREEBSD_VF, /* nested, IFLAF_VF_*; repeated */
__IFLA_MAX
};
#define IFLA_MAX (__IFLA_MAX - 1)
/* IFLA_EXT_MASK values. */
#define RTEXT_FILTER_VF (1U << 0)
enum {
IFLAF_UNSPEC = 0,
IFLAF_ORIG_IFNAME = 1, /* string, original interface name at creation */
IFLAF_ORIG_HWADDR = 2, /* binary, original hardware address */
IFLAF_CAPS = 3, /* bitset, interface capabilities */
IFLAF_GROUP = 4, /* string, interface group name (multi-attr) */
IFLAF_VF_STATUS = 5, /* nested, IFLAF_VFS_* */
__IFLAF_MAX
};
#define IFLAF_MAX (__IFLAF_MAX - 1)
/* IFLAF_VF_STATUS attributes. */
enum {
IFLAF_VFS_UNSPEC = 0,
IFLAF_VFS_ERROR = 1, /* u32: errno from requested query */
IFLAF_VFS_PF_LINK_STATE = 2, /* u8: IFLAF_VF_LINK_* */
IFLAF_VFS_PF_LINK_SPEED = 3, /* u64: bits per second */
__IFLAF_VFS_MAX
};
#define IFLAF_VFS_MAX (__IFLAF_VFS_MAX - 1)
/* IFLA_FREEBSD_VF attributes. */
enum {
IFLAF_VF_UNSPEC = 0,
IFLAF_VF_INDEX = 1, /* u32 */
IFLAF_VF_CONFIGURED = 2, /* bool */
IFLAF_VF_INITIALIZED = 3, /* bool */
IFLAF_VF_MAC = 4, /* binary */
IFLAF_VF_VLAN_MODE = 5, /* u8: IFLAF_VF_VLAN_* */
IFLAF_VF_VLAN = 6, /* u16 */
IFLAF_VF_VLAN_PCP = 7, /* u8: IEEE 802.1p PCP */
IFLAF_VF_VLAN_PROTO = 8, /* u16: host-order EtherType */
IFLAF_VF_VLAN_COUNT = 9, /* u32 */
IFLAF_VF_VLAN_LIMIT = 10, /* u32 */
IFLAF_VF_NUM_TX_QUEUES = 11, /* u16 */
IFLAF_VF_NUM_RX_QUEUES = 12, /* u16 */
IFLAF_VF_MIN_TX_RATE = 13, /* u64: minimum bits per second */
IFLAF_VF_MAX_TX_RATE = 14, /* u64: maximum bits per second */
IFLAF_VF_ALLOW_SET_MAC = 15, /* bool */
IFLAF_VF_ALLOW_SET_VLAN = 16, /* bool */
IFLAF_VF_MAC_ANTI_SPOOF = 17, /* bool */
IFLAF_VF_ALLOW_PROMISC = 18, /* bool */
IFLAF_VF_TRAFFIC_ALLOWED = 19, /* bool */
IFLAF_VF_FAULT_BLOCKED = 20, /* bool */
IFLAF_VF_QUARANTINED = 21, /* bool */
IFLAF_VF_API_VERSION = 22, /* string */
IFLAF_VF_LINK_STATE_POLICY = 23, /* u8: IFLAF_VF_LINK_* */
IFLAF_VF_DRIVER = 24, /* nested; repeated */
__IFLAF_VF_MAX
};
#define IFLAF_VF_MAX (__IFLAF_VF_MAX - 1)
/* IFLAF_VF_DRIVER attributes. */
enum {
IFLAF_VFD_UNSPEC = 0,
IFLAF_VFD_NAME = 1, /* string: stable namespace */
IFLAF_VFD_VERSION = 2, /* u32: namespace version */
IFLAF_VFD_FIELD = 3, /* nested, IFLAF_VFDF_*; repeated */
__IFLAF_VFD_MAX
};
#define IFLAF_VFD_MAX (__IFLAF_VFD_MAX - 1)
/* IFLAF_VFD_FIELD attributes; exactly one value attribute is present. */
enum {
IFLAF_VFDF_UNSPEC = 0,
IFLAF_VFDF_NAME = 1, /* string: namespace-local name */
IFLAF_VFDF_BOOL = 2, /* bool */
IFLAF_VFDF_NUMBER = 3, /* u64 */
IFLAF_VFDF_STRING = 4, /* string */
IFLAF_VFDF_BINARY = 5, /* binary */
__IFLAF_VFDF_MAX
};
#define IFLAF_VFDF_MAX (__IFLAF_VFDF_MAX - 1)
enum {
IFLAF_VF_LINK_UNKNOWN = 0,
IFLAF_VF_LINK_DOWN = 1,
IFLAF_VF_LINK_UP = 2,
IFLAF_VF_LINK_AUTO = 3,
};
enum {
IFLAF_VF_VLAN_UNKNOWN = 0,
IFLAF_VF_VLAN_ACCESS = 1,
IFLAF_VF_VLAN_TRUNK = 2,
};
/*
* Attributes that can be used as filters:
* IFLA_IFNAME, IFLA_GROUP, IFLA_ALT_IFNAME
* Headers that can be used as filters:
* ifi_index, ifi_type
*/
/*
* IFLA_OPERSTATE.
* The values below represent the possible
* states of ifOperStatus defined by RFC 2863
*/
enum {
IF_OPER_UNKNOWN = 0, /* status can not be determined */
IF_OPER_NOTPRESENT = 1, /* some (hardware) component not present */
IF_OPER_DOWN = 2, /* down */
IF_OPER_LOWERLAYERDOWN = 3, /* some lower-level interface is down */
IF_OPER_TESTING = 4, /* in some test mode */
IF_OPER_DORMANT = 5, /* "up" but waiting for some condition (802.1X) */
IF_OPER_UP = 6, /* ready to pass packets */
};
/* IFLA_STATS */
struct rtnl_link_stats {
uint32_t rx_packets; /* total RX packets (IFCOUNTER_IPACKETS) */
uint32_t tx_packets; /* total TX packets (IFCOUNTER_OPACKETS) */
uint32_t rx_bytes; /* total RX bytes (IFCOUNTER_IBYTES) */
uint32_t tx_bytes; /* total TX bytes (IFCOUNTER_OBYTES) */
uint32_t rx_errors; /* RX errors (IFCOUNTER_IERRORS) */
uint32_t tx_errors; /* RX errors (IFCOUNTER_OERRORS) */
uint32_t rx_dropped; /* RX drop (no space in ring/no bufs) (IFCOUNTER_IQDROPS) */
uint32_t tx_dropped; /* TX drop (IFCOUNTER_OQDROPS) */
uint32_t multicast; /* RX multicast packets (IFCOUNTER_IMCASTS) */
uint32_t collisions; /* not supported */
uint32_t rx_length_errors; /* not supported */
uint32_t rx_over_errors; /* not supported */
uint32_t rx_crc_errors; /* not supported */
uint32_t rx_frame_errors; /* not supported */
uint32_t rx_fifo_errors; /* not supported */
uint32_t rx_missed_errors; /* not supported */
uint32_t tx_aborted_errors; /* not supported */
uint32_t tx_carrier_errors; /* not supported */
uint32_t tx_fifo_errors; /* not supported */
uint32_t tx_heartbeat_errors; /* not supported */
uint32_t tx_window_errors; /* not supported */
uint32_t rx_compressed; /* not supported */
uint32_t tx_compressed; /* not supported */
uint32_t rx_nohandler; /* dropped due to no proto handler (IFCOUNTER_NOPROTO) */
};
/* IFLA_STATS64 */
struct rtnl_link_stats64 {
uint64_t rx_packets; /* total RX packets (IFCOUNTER_IPACKETS) */
uint64_t tx_packets; /* total TX packets (IFCOUNTER_OPACKETS) */
uint64_t rx_bytes; /* total RX bytes (IFCOUNTER_IBYTES) */
uint64_t tx_bytes; /* total TX bytes (IFCOUNTER_OBYTES) */
uint64_t rx_errors; /* RX errors (IFCOUNTER_IERRORS) */
uint64_t tx_errors; /* RX errors (IFCOUNTER_OERRORS) */
uint64_t rx_dropped; /* RX drop (no space in ring/no bufs) (IFCOUNTER_IQDROPS) */
uint64_t tx_dropped; /* TX drop (IFCOUNTER_OQDROPS) */
uint64_t multicast; /* RX multicast packets (IFCOUNTER_IMCASTS) */
uint64_t collisions; /* not supported */
uint64_t rx_length_errors; /* not supported */
uint64_t rx_over_errors; /* not supported */
uint64_t rx_crc_errors; /* not supported */
uint64_t rx_frame_errors; /* not supported */
uint64_t rx_fifo_errors; /* not supported */
uint64_t rx_missed_errors; /* not supported */
uint64_t tx_aborted_errors; /* not supported */
uint64_t tx_carrier_errors; /* not supported */
uint64_t tx_fifo_errors; /* not supported */
uint64_t tx_heartbeat_errors; /* not supported */
uint64_t tx_window_errors; /* not supported */
uint64_t rx_compressed; /* not supported */
uint64_t tx_compressed; /* not supported */
uint64_t rx_nohandler; /* dropped due to no proto handler (IFCOUNTER_NOPROTO) */
};
/* IFLA_LINKINFO child nlattr types */
enum {
IFLA_INFO_UNSPEC,
IFLA_INFO_KIND = 1, /* string, link type ("vlan") */
IFLA_INFO_DATA = 2, /* Per-link-type custom data */
IFLA_INFO_XSTATS = 3,
IFLA_INFO_SLAVE_KIND = 4,
IFLA_INFO_SLAVE_DATA = 5,
__IFLA_INFO_MAX,
};
#define IFLA_INFO_MAX (__IFLA_INFO_MAX - 1)
/* Encapsulation Types */
enum {
IFLA_TUNNEL_NONE,
IFLA_TUNNEL_GRE_UDP, /* GRE UDP Encapsulation */
__IFLA_TUNNEL_MAX,
};
#define IFLA_TUNNEL_MAX (__IFLA_TUNNEL_MAX - 1)
/* IFLA_INFO_DATA vlan attributes */
enum {
IFLA_VLAN_UNSPEC,
IFLA_VLAN_ID,
IFLA_VLAN_FLAGS,
IFLA_VLAN_EGRESS_QOS,
IFLA_VLAN_INGRESS_QOS,
IFLA_VLAN_PROTOCOL,
__IFLA_VLAN_MAX,
};
#define IFLA_VLAN_MAX (__IFLA_VLAN_MAX - 1)
struct ifla_vlan_flags {
uint32_t flags;
uint32_t mask;
};
/* IFLA_INFO_DATA gif attributes */
enum {
IFLA_IPTUN_UNSPEC,
IFLA_IPTUN_LOCAL,
IFLA_IPTUN_REMOTE,
IFLA_IPTUN_FLAGS,
__IFLA_IPTUN_MAX,
};
#define IFLA_IPTUN_MAX (__IFLA_IPTUN_MAX - 1)
/* IFLA_INFO_DATA gre attributes */
enum {
IFLA_GRE_UNSPEC,
IFLA_GRE_LOCAL,
IFLA_GRE_REMOTE,
IFLA_GRE_FLAGS,
IFLA_GRE_OKEY,
IFLA_GRE_ENCAP_TYPE,
IFLA_GRE_ENCAP_SPORT,
__IFLA_GRE_MAX,
};
#define IFLA_GRE_MAX (__IFLA_GRE_MAX - 1)
/* IFLA_INFO_DATA geneve attributes */
enum {
IFLA_GENEVE_UNSPEC,
IFLA_GENEVE_ID,
IFLA_GENEVE_PROTOCOL,
IFLA_GENEVE_LOCAL,
IFLA_GENEVE_REMOTE,
IFLA_GENEVE_LOCAL_PORT,
IFLA_GENEVE_PORT,
IFLA_GENEVE_PORT_RANGE,
IFLA_GENEVE_DF,
IFLA_GENEVE_TTL,
IFLA_GENEVE_TTL_INHERIT,
IFLA_GENEVE_DSCP_INHERIT,
IFLA_GENEVE_COLLECT_METADATA,
IFLA_GENEVE_FTABLE_LEARN,
IFLA_GENEVE_FTABLE_FLUSH,
IFLA_GENEVE_FTABLE_MAX,
IFLA_GENEVE_FTABLE_TIMEOUT,
IFLA_GENEVE_FTABLE_COUNT,
IFLA_GENEVE_FTABLE_NOSPACE_CNT,
IFLA_GENEVE_FTABLE_LOCK_UP_FAIL_CNT,
IFLA_GENEVE_MC_IFNAME,
IFLA_GENEVE_MC_IFINDEX,
IFLA_GENEVE_TXCSUM_CNT,
IFLA_GENEVE_TSO_CNT,
IFLA_GENEVE_RXCSUM_CNT,
__IFLA_GENEVE_MAX,
};
#define IFLA_GENEVE_MAX (__IFLA_GENEVE_MAX - 1)
enum ifla_geneve_df {
IFLA_GENEVE_DF_UNSET,
IFLA_GENEVE_DF_SET,
IFLA_GENEVE_DF_INHERIT,
__IFLA_GENEVE_DF_MAX,
};
#define IFLA_GENEVE_DF_MAX (__IFLA_GENEVE_DF_MAX - 1)
struct ifla_geneve_port_range {
uint16_t low;
uint16_t high;
};
#endif