libnl: Links (Interfaces)

libnl 3.10.0

Topics | Data Structures | Enumerations | Functions | Variables
Links (Interfaces)
Routing Library (libnl-route)

## Topics
| Bonding
| Bridging
| CAN
| Controller Area Network link module
| Dummy
| Geneve
| Generic Network Virtualization Encapsulation
| IP6GRE
| ip6gre link module
| IP6TNL
| ip6tnl link module
| IP6VTI
| ip6vti link module
| IPGRE
| ipgre link module
| IPIP
| ipip link module
| IPVLAN
| IP-based Virtual LAN link module
| IPVTI
| ipvti link module
| Intermediate Functional Block
| Link Modules API
| MACVLAN/MACVTAP
| MAC-based Virtual LAN link module
| MACsec
| MACsec link module
| PPP
| SIT
| sit link module
| SRIOV
| SR-IOV VF link module
| Team
| VETH
| Virtual Ethernet
| VLAN
| Virtual LAN link module
| VRF
| Virtual Routing and Forwarding link module
| VXLAN
| Virtual eXtensible Local Area Network link module
| XFRMI
| xfrmi link module

## Data Structures
struct | rtnl_link
| Link object. More...

## Enumerations
enum | rtnl_link_stat_id_t { RTNL_LINK_RX_PACKETS , RTNL_LINK_TX_PACKETS , RTNL_LINK_RX_BYTES , RTNL_LINK_TX_BYTES , RTNL_LINK_RX_ERRORS , RTNL_LINK_TX_ERRORS , RTNL_LINK_RX_DROPPED , RTNL_LINK_TX_DROPPED , RTNL_LINK_RX_COMPRESSED , RTNL_LINK_TX_COMPRESSED , RTNL_LINK_RX_FIFO_ERR , RTNL_LINK_TX_FIFO_ERR , RTNL_LINK_RX_LEN_ERR , RTNL_LINK_RX_OVER_ERR , RTNL_LINK_RX_CRC_ERR , RTNL_LINK_RX_FRAME_ERR , RTNL_LINK_RX_MISSED_ERR , RTNL_LINK_TX_ABORT_ERR , RTNL_LINK_TX_CARRIER_ERR , RTNL_LINK_TX_HBEAT_ERR , RTNL_LINK_TX_WIN_ERR , RTNL_LINK_COLLISIONS , RTNL_LINK_MULTICAST , RTNL_LINK_IP6_INPKTS , RTNL_LINK_IP6_INHDRERRORS , RTNL_LINK_IP6_INTOOBIGERRORS , RTNL_LINK_IP6_INNOROUTES , RTNL_LINK_IP6_INADDRERRORS , RTNL_LINK_IP6_INUNKNOWNPROTOS , RTNL_LINK_IP6_INTRUNCATEDPKTS , RTNL_LINK_IP6_INDISCARDS , RTNL_LINK_IP6_INDELIVERS , RTNL_LINK_IP6_OUTFORWDATAGRAMS , RTNL_LINK_IP6_OUTPKTS , RTNL_LINK_IP6_OUTDISCARDS , RTNL_LINK_IP6_OUTNOROUTES , RTNL_LINK_IP6_REASMTIMEOUT , RTNL_LINK_IP6_REASMREQDS , RTNL_LINK_IP6_REASMOKS , RTNL_LINK_IP6_REASMFAILS , RTNL_LINK_IP6_FRAGOKS , RTNL_LINK_IP6_FRAGFAILS , RTNL_LINK_IP6_FRAGCREATES , RTNL_LINK_IP6_INMCASTPKTS , RTNL_LINK_IP6_OUTMCASTPKTS , RTNL_LINK_IP6_INBCASTPKTS , RTNL_LINK_IP6_OUTBCASTPKTS , RTNL_LINK_IP6_INOCTETS , RTNL_LINK_IP6_OUTOCTETS , RTNL_LINK_IP6_INMCASTOCTETS , RTNL_LINK_IP6_OUTMCASTOCTETS , RTNL_LINK_IP6_INBCASTOCTETS , RTNL_LINK_IP6_OUTBCASTOCTETS , RTNL_LINK_ICMP6_INMSGS , RTNL_LINK_ICMP6_INERRORS , RTNL_LINK_ICMP6_OUTMSGS , RTNL_LINK_ICMP6_OUTERRORS , RTNL_LINK_ICMP6_CSUMERRORS , RTNL_LINK_IP6_CSUMERRORS , RTNL_LINK_IP6_NOECTPKTS , RTNL_LINK_IP6_ECT1PKTS , RTNL_LINK_IP6_ECT0PKTS , RTNL_LINK_IP6_CEPKTS , RTNL_LINK_RX_NOHANDLER , RTNL_LINK_REASM_OVERLAPS , __RTNL_LINK_STATS_MAX }

## Functions
struct rtnl_link * | link_lookup (struct nl_cache *cache, int ifindex)
int | rtnl_link_info_parse (struct rtnl_link *link, struct nlattr **tb)
int | rtnl_link_fill_info (struct nl_msg *msg, struct rtnl_link *link)

## Variables
struct nla_policy | rtln_link_policy [IFLA_MAX+1]

## Utilities
char * | rtnl_link_flags2str (int flags, char *buf, size_t len)
int | rtnl_link_str2flags (const char *name)
char * | rtnl_link_stat2str (int st, char *buf, size_t len)
int | rtnl_link_str2stat (const char *name)
char * | rtnl_link_operstate2str (uint8_t st, char *buf, size_t len)
int | rtnl_link_str2operstate (const char *name)
char * | rtnl_link_mode2str (uint8_t st, char *buf, size_t len)
int | rtnl_link_str2mode (const char *name)
char * | rtnl_link_carrier2str (uint8_t st, char *buf, size_t len)
int | rtnl_link_str2carrier (const char *name)
int | rtnl_link_has_vf_list (struct rtnl_link *link)
void | rtnl_link_set_vf_list (struct rtnl_link *link)
void | rtnl_link_unset_vf_list (struct rtnl_link *link)

## Get / List
int | rtnl_link_alloc_cache_flags (struct nl_sock *sk, int family, struct nl_cache **result, unsigned int flags)
| Allocate link cache and fill in all configured links.
int | rtnl_link_alloc_cache (struct nl_sock *sk, int family, struct nl_cache **result)
| Allocate link cache and fill in all configured links.
struct rtnl_link * | rtnl_link_get (struct nl_cache *cache, int ifindex)
| Lookup link in cache by interface index.
struct rtnl_link * | rtnl_link_get_by_name (struct nl_cache *cache, const char *name)
| Lookup link in cache by link name.
int | rtnl_link_build_get_request (int ifindex, const char *name, struct nl_msg **result)
| Construct RTM_GETLINK netlink message.
int | rtnl_link_get_kernel (struct nl_sock *sk, int ifindex, const char *name, struct rtnl_link **result)
| Get a link object directly from kernel.
char * | rtnl_link_i2name (struct nl_cache *cache, int ifindex, char *dst, size_t len)
| Translate interface index to corresponding link name.
int | rtnl_link_name2i (struct nl_cache *cache, const char *name)
| Translate link name to corresponding interface index.

## Add / Modify
int | rtnl_link_build_add_request (struct rtnl_link *link, int flags, struct nl_msg **result)
| Build a netlink message requesting the addition of new virtual link.
int | rtnl_link_add (struct nl_sock *sk, struct rtnl_link *link, int flags)
| Add virtual link.
int | rtnl_link_build_change_request (struct rtnl_link *orig, struct rtnl_link *changes, int flags, struct nl_msg **result)
| Build a netlink message requesting the modification of link.
int | rtnl_link_change (struct nl_sock *sk, struct rtnl_link *orig, struct rtnl_link *changes, int flags)
| Change link.

## Delete
int | rtnl_link_build_delete_request (const struct rtnl_link *link, struct nl_msg **result)
| Build a netlink message requesting the deletion of a link.
int | rtnl_link_delete (struct nl_sock *sk, const struct rtnl_link *link)
| Delete link.

## Link Object
struct rtnl_link * | rtnl_link_alloc (void)
| Allocate link object.
void | rtnl_link_put (struct rtnl_link *link)
| Release a link object reference.
void | rtnl_link_set_name (struct rtnl_link *link, const char *name)
| Set name of link object.
char * | rtnl_link_get_name (struct rtnl_link *link)
| Return name of link object.
void | rtnl_link_set_group (struct rtnl_link *link, uint32_t group)
| Set the group identifier of a link object.
uint32_t | rtnl_link_get_group (struct rtnl_link *link)
| Return the group identifier of link object.
void | rtnl_link_set_addr (struct rtnl_link *link, struct nl_addr *addr)
| Set link layer address of link object.
struct nl_addr * | rtnl_link_get_addr (struct rtnl_link *link)
| Return link layer address of link object.
void | rtnl_link_set_broadcast (struct rtnl_link *link, struct nl_addr *addr)
| Set link layer broadcast address of link object.
struct nl_addr * | rtnl_link_get_broadcast (struct rtnl_link *link)
| Return link layer broadcast address of link object.
void | rtnl_link_set_flags (struct rtnl_link *link, unsigned int flags)
| Set flags of link object.
void | rtnl_link_unset_flags (struct rtnl_link *link, unsigned int flags)
| Unset flags of link object.
unsigned int | rtnl_link_get_flags (struct rtnl_link *link)
| Return flags of link object.
void | rtnl_link_set_family (struct rtnl_link *link, int family)
| Set address family of link object.
int | rtnl_link_get_family (struct rtnl_link *link)
| Return address family of link object.
void | rtnl_link_set_arptype (struct rtnl_link *link, unsigned int arptype)
| Set hardware type of link object.
unsigned int | rtnl_link_get_arptype (struct rtnl_link *link)
| Get hardware type of link object.
void | rtnl_link_set_ifindex (struct rtnl_link *link, int ifindex)
| Set interface index of link object.
int | rtnl_link_get_ifindex (struct rtnl_link *link)
| Return interface index of link object.
void | rtnl_link_set_mtu (struct rtnl_link *link, unsigned int mtu)
| Set Maximum Transmission Unit of link object.
unsigned int | rtnl_link_get_mtu (struct rtnl_link *link)
| Return maximum transmission unit of link object.
void | rtnl_link_set_txqlen (struct rtnl_link *link, unsigned int txqlen)
| Set transmission queue length.
unsigned int | rtnl_link_get_txqlen (struct rtnl_link *link)
| Return transmission queue length.
void | rtnl_link_set_link (struct rtnl_link *link, int ifindex)
int | rtnl_link_get_link (struct rtnl_link *link)
int | rtnl_link_set_link_netnsid (struct rtnl_link *link, int32_t link_netnsid)
| Set the netnsid of the link.
int | rtnl_link_get_link_netnsid (const struct rtnl_link *link, int32_t *out_link_netnsid)
| Get the netnsid of the link.
void | rtnl_link_set_master (struct rtnl_link *link, int ifindex)
| Set master link of link object.
int | rtnl_link_get_master (struct rtnl_link *link)
| Return master link of link object.
void | rtnl_link_set_carrier (struct rtnl_link *link, uint8_t status)
| Set carrier of link object.
uint8_t | rtnl_link_get_carrier (struct rtnl_link *link)
| Return carrier status of link object.
int | rtnl_link_get_carrier_changes (struct rtnl_link *link, uint32_t *carrier_changes)
| Return carrier on/off changes of link object.
void | rtnl_link_set_operstate (struct rtnl_link *link, uint8_t status)
| Set operational status of link object.
uint8_t | rtnl_link_get_operstate (struct rtnl_link *link)
| Return operational status of link object.
void | rtnl_link_set_linkmode (struct rtnl_link *link, uint8_t mode)
| Set link mode of link object.
uint8_t | rtnl_link_get_linkmode (struct rtnl_link *link)
| Return link mode of link object.
const char * | rtnl_link_get_ifalias (struct rtnl_link *link)
| Return alias name of link object (SNMP IfAlias)
void | rtnl_link_set_ifalias (struct rtnl_link *link, const char *alias)
| Set alias name of link object (SNMP IfAlias)
void | rtnl_link_set_qdisc (struct rtnl_link *link, const char *name)
| Set queueing discipline name of link object.
char * | rtnl_link_get_qdisc (struct rtnl_link *link)
| Return name of queueing discipline of link object.
int | rtnl_link_get_num_vf (struct rtnl_link *link, uint32_t *num_vf)
| Return number of PCI virtual functions of link object.
uint64_t | rtnl_link_get_stat (struct rtnl_link *link, rtnl_link_stat_id_t id)
| Return value of link statistics counter.
int | rtnl_link_set_stat (struct rtnl_link *link, rtnl_link_stat_id_t id, const uint64_t value)
| Set value of link statistics counter.
int | rtnl_link_set_type (struct rtnl_link *link, const char *type)
| Set type of link object.
char * | rtnl_link_get_type (struct rtnl_link *link)
| Return type of link.
int | rtnl_link_set_slave_type (struct rtnl_link *link, const char *type)
| Set type of slave link object.
const char * | rtnl_link_get_slave_type (const struct rtnl_link *link)
| Return type of enslaved link.
void | rtnl_link_set_promiscuity (struct rtnl_link *link, uint32_t count)
| Set link promiscuity count.
uint32_t | rtnl_link_get_promiscuity (struct rtnl_link *link)
| Return link promiscuity count.
void | rtnl_link_set_num_tx_queues (struct rtnl_link *link, uint32_t nqueues)
| Set number of TX queues.
uint32_t | rtnl_link_get_num_tx_queues (struct rtnl_link *link)
| Return number of TX queues.
void | rtnl_link_set_num_rx_queues (struct rtnl_link *link, uint32_t nqueues)
| Set number of RX queues.
uint32_t | rtnl_link_get_num_rx_queues (struct rtnl_link *link)
| Return number of RX queues.
int | rtnl_link_get_gso_max_segs (struct rtnl_link *link, uint32_t *gso_max_segs)
| Return maximum number of segments for generic segmentation offload.
int | rtnl_link_get_gso_max_size (struct rtnl_link *link, uint32_t *gso_max_size)
| Return maximum size for generic segmentation offload.
struct nl_data * | rtnl_link_get_phys_port_id (struct rtnl_link *link)
| Return physical port id of link object.
char * | rtnl_link_get_phys_port_name (struct rtnl_link *link)
| Return physical port name of link object.
struct nl_data * | rtnl_link_get_phys_switch_id (struct rtnl_link *link)
void | rtnl_link_set_ns_fd (struct rtnl_link *link, int fd)
int | rtnl_link_get_ns_fd (struct rtnl_link *link)
void | rtnl_link_set_ns_pid (struct rtnl_link *link, pid_t pid)
pid_t | rtnl_link_get_ns_pid (struct rtnl_link *link)

## Master/Slave
int | rtnl_link_enslave_ifindex (struct nl_sock *sock, int master, int slave)
| Enslave slave link to master link.
int | rtnl_link_enslave (struct nl_sock *sock, struct rtnl_link *master, struct rtnl_link *slave)
| Enslave slave link to master link.
int | rtnl_link_release_ifindex (struct nl_sock *sock, int slave)
| Release slave link from its master.
int | rtnl_link_release (struct nl_sock *sock, struct rtnl_link *slave)
| Release slave link from its master.

## Deprecated Functions
int | rtnl_link_set_info_type (struct rtnl_link *link, const char *type)
char * | rtnl_link_get_info_type (struct rtnl_link *link)
void | rtnl_link_set_weight (struct rtnl_link *link, unsigned int weight)
unsigned int | rtnl_link_get_weight (struct rtnl_link *link)

## Detailed Description

Link Documentation (Netlink Routing Development Guide)

## Enumeration Type Documentation

## ◆ rtnl_link_stat_id_t

enum rtnl_link_stat_id_t

Enumerator
RTNL_LINK_RX_PACKETS | Packets received
RTNL_LINK_TX_PACKETS | Packets sent
RTNL_LINK_RX_BYTES | Bytes received
RTNL_LINK_TX_BYTES | Bytes sent
RTNL_LINK_RX_ERRORS | Receive errors
RTNL_LINK_TX_ERRORS | Send errors
RTNL_LINK_RX_DROPPED | Received packets dropped
RTNL_LINK_TX_DROPPED | Packets dropped during transmit
RTNL_LINK_RX_COMPRESSED | Compressed packets received
RTNL_LINK_TX_COMPRESSED | Compressed packets sent
RTNL_LINK_RX_FIFO_ERR | Receive FIFO errors
RTNL_LINK_TX_FIFO_ERR | Send FIFO errors
RTNL_LINK_RX_LEN_ERR | Length errors
RTNL_LINK_RX_OVER_ERR | Over errors
RTNL_LINK_RX_CRC_ERR | CRC errors
RTNL_LINK_RX_FRAME_ERR | Frame errors
RTNL_LINK_RX_MISSED_ERR | Missed errors
RTNL_LINK_TX_ABORT_ERR | Aborted errors
RTNL_LINK_TX_CARRIER_ERR | Carrier errors
RTNL_LINK_TX_HBEAT_ERR | Heartbeat errors
RTNL_LINK_TX_WIN_ERR | Window errors
RTNL_LINK_COLLISIONS | Send collisions
RTNL_LINK_MULTICAST | Multicast
RTNL_LINK_IP6_INPKTS | IPv6 SNMP InReceives
RTNL_LINK_IP6_INHDRERRORS | IPv6 SNMP InHdrErrors
RTNL_LINK_IP6_INTOOBIGERRORS | IPv6 SNMP InTooBigErrors
RTNL_LINK_IP6_INNOROUTES | IPv6 SNMP InNoRoutes
RTNL_LINK_IP6_INADDRERRORS | IPv6 SNMP InAddrErrors
RTNL_LINK_IP6_INUNKNOWNPROTOS | IPv6 SNMP InUnknownProtos
RTNL_LINK_IP6_INTRUNCATEDPKTS | IPv6 SNMP InTruncatedPkts
RTNL_LINK_IP6_INDISCARDS | IPv6 SNMP InDiscards
RTNL_LINK_IP6_INDELIVERS | IPv6 SNMP InDelivers
RTNL_LINK_IP6_OUTFORWDATAGRAMS | IPv6 SNMP OutForwDatagrams
RTNL_LINK_IP6_OUTPKTS | IPv6 SNMP OutRequests
RTNL_LINK_IP6_OUTDISCARDS | IPv6 SNMP OutDiscards
RTNL_LINK_IP6_OUTNOROUTES | IPv6 SNMP OutNoRoutes
RTNL_LINK_IP6_REASMTIMEOUT | IPv6 SNMP ReasmTimeout
RTNL_LINK_IP6_REASMREQDS | IPv6 SNMP ReasmReqds
RTNL_LINK_IP6_REASMOKS | IPv6 SNMP ReasmOKs
RTNL_LINK_IP6_REASMFAILS | IPv6 SNMP ReasmFails
RTNL_LINK_IP6_FRAGOKS | IPv6 SNMP FragOKs
RTNL_LINK_IP6_FRAGFAILS | IPv6 SNMP FragFails
RTNL_LINK_IP6_FRAGCREATES | IPv6 SNMP FragCreates
RTNL_LINK_IP6_INMCASTPKTS | IPv6 SNMP InMcastPkts
RTNL_LINK_IP6_OUTMCASTPKTS | IPv6 SNMP OutMcastPkts
RTNL_LINK_IP6_INBCASTPKTS | IPv6 SNMP InBcastPkts
RTNL_LINK_IP6_OUTBCASTPKTS | IPv6 SNMP OutBcastPkts
RTNL_LINK_IP6_INOCTETS | IPv6 SNMP InOctets
RTNL_LINK_IP6_OUTOCTETS | IPv6 SNMP OutOctets
RTNL_LINK_IP6_INMCASTOCTETS | IPv6 SNMP InMcastOctets
RTNL_LINK_IP6_OUTMCASTOCTETS | IPv6 SNMP OutMcastOctets
RTNL_LINK_IP6_INBCASTOCTETS | IPv6 SNMP InBcastOctets
RTNL_LINK_IP6_OUTBCASTOCTETS | IPv6 SNMP OutBcastOctets
RTNL_LINK_ICMP6_INMSGS | ICMPv6 SNMP InMsgs
RTNL_LINK_ICMP6_INERRORS | ICMPv6 SNMP InErrors
RTNL_LINK_ICMP6_OUTMSGS | ICMPv6 SNMP OutMsgs
RTNL_LINK_ICMP6_OUTERRORS | ICMPv6 SNMP OutErrors
RTNL_LINK_ICMP6_CSUMERRORS | ICMPv6 SNMP InCsumErrors
RTNL_LINK_IP6_CSUMERRORS | IPv6 SNMP InCsumErrors
RTNL_LINK_IP6_NOECTPKTS | IPv6 SNMP InNoECTPkts
RTNL_LINK_IP6_ECT1PKTS | IPv6 SNMP InECT1Pkts
RTNL_LINK_IP6_ECT0PKTS | IPv6 SNMP InECT0Pkts
RTNL_LINK_IP6_CEPKTS | IPv6 SNMP InCEPkts
RTNL_LINK_RX_NOHANDLER | Received packets dropped on inactive device
RTNL_LINK_REASM_OVERLAPS | SNMP ReasmOverlaps

Definition at line 31 of file link.h.

## Function Documentation

## ◆ link_lookup()

struct rtnl_link * link_lookup | ( | struct nl_cache * | cache,
|  | int | ifindex )

Definition at line 81 of file link.c.

## ◆ rtnl_link_info_parse()

int rtnl_link_info_parse | ( | struct rtnl_link * | link,
|  | struct nlattr ** | tb )

Definition at line 402 of file link.c.

## ◆ rtnl_link_alloc_cache_flags()

int rtnl_link_alloc_cache_flags | ( | struct nl_sock * | sk,
|  | int | family,
|  | struct nl_cache ** | result,
|  | unsigned int | flags )

Allocate link cache and fill in all configured links.

Parameters

  sk | Netlink socket.
  family | Link address family or AF_UNSPEC
  result | Pointer to store resulting cache.
  flags | Flags to set in link cache before filling

Allocates and initializes a new link cache. If `sk` is valid, a netlink message is sent to the kernel requesting a full dump of all configured links. The returned messages are parsed and filled into the cache. If the operation succeeds, the resulting cache will contain a link object for each link configured in the kernel. If `sk` is NULL, returns 0 but the cache is still empty.

If `family` is set to an address family other than `AF_UNSPEC` the contents of the cache can be limited to a specific address family. Currently the following address families are supported:

- AF_BRIDGE
- AF_INET6

Get List of Links (Netlink Routing Development Guide)

See also
  rtnl_link_get()
  rtnl_link_get_by_name()

Returns
  0 on success or a negative error code.

Definition at line 1246 of file link.c.

References nl_cache_alloc(), nl_cache_free(), nl_cache_refill(), and nl_cache_set_flags().

Referenced by rtnl_link_alloc_cache().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ rtnl_link_alloc_cache()

int rtnl_link_alloc_cache | ( | struct nl_sock * | sk,
|  | int | family,
|  | struct nl_cache ** | result )

Allocate link cache and fill in all configured links.

Parameters

  sk | Netlink socket.
  family | Link address family or AF_UNSPEC
  result | Pointer to store resulting cache.

Allocates and initializes a new link cache. If `sk` is valid, a netlink message is sent to the kernel requesting a full dump of all configured links. The returned messages are parsed and filled into the cache. If the operation succeeds, the resulting cache will contain a link object for each link configured in the kernel. If `sk` is NULL, returns 0 but the cache is still empty.

If `family` is set to an address family other than `AF_UNSPEC` the contents of the cache can be limited to a specific address family. Currently the following address families are supported:

- AF_BRIDGE
- AF_INET6

Get List of Links (Netlink Routing Development Guide)

See also
  rtnl_link_get()
  rtnl_link_get_by_name()

Returns
  0 on success or a negative error code.

Definition at line 1294 of file link.c.

References rtnl_link_alloc_cache_flags().

Here is the call graph for this function:

## ◆ rtnl_link_get()

struct rtnl_link * rtnl_link_get | ( | struct nl_cache * | cache,
|  | int | ifindex )

Lookup link in cache by interface index.

Parameters

  cache | Link cache
  ifindex | Interface index

Searches through the provided cache looking for a link with matching interface index.

Attention
  The reference counter of the returned link object will be incremented. Use rtnl_link_put() to release the reference.

Get List of Links (Netlink Routing Development Guide)

See also
  rtnl_link_get_by_name()

Returns
  Link object or NULL if no match was found.

Definition at line 1315 of file link.c.

References nl_object_get().

Referenced by rtnl_link_i2name().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ rtnl_link_get_by_name()

struct rtnl_link * rtnl_link_get_by_name | ( | struct nl_cache * | cache,
|  | const char * | name )

Lookup link in cache by link name.

Parameters

  cache | Link cache
  name | Name of link

Searches through the provided cache looking for a link with matching link name

Attention
  The reference counter of the returned link object will be incremented. Use rtnl_link_put() to release the reference.

Get List of Links (Netlink Routing Development Guide)

See also
  rtnl_link_get()

Returns
  Link object or NULL if no match was found.

Definition at line 1347 of file link.c.

References nl_object_get().

Referenced by rtnl_link_name2i().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ rtnl_link_build_get_request()

int rtnl_link_build_get_request | ( | int | ifindex,
|  | const char * | name,
|  | struct nl_msg ** | result )

Construct RTM_GETLINK netlink message.

Parameters

  ifindex | Interface index
  name | Name of link
  result | Pointer to store resulting netlink message

The behaviour of this function is identical to rtnl_link_get_kernel() with the exception that it will not send the message but return it in the provided return pointer instead.

See also
  rtnl_link_get_kernel()

Returns
  0 on success or a negative error code.

Definition at line 1379 of file link.c.

References nla_put(), nla_put_string(), nlmsg_alloc_simple(), and nlmsg_append().

Referenced by rtnl_link_get_kernel().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ rtnl_link_get_kernel()

int rtnl_link_get_kernel | ( | struct nl_sock * | sk,
|  | int | ifindex,
|  | const char * | name,
|  | struct rtnl_link ** | result )

Get a link object directly from kernel.

Parameters

  sk | Netlink socket
  ifindex | Interface index
  name | Name of link
  result | Pointer to store resulting link object

This function builds a `RTM_GETLINK` netlink message to request a specific link directly from the kernel. The returned answer is parsed into a struct rtnl_link object and returned via the result pointer or -NLE_OBJ_NOTFOUND is returned if no matching link was found.

Older kernels do not support lookup by name. In that case, libnl will fail with -NLE_OPNOTSUPP. Note that previous version of libnl failed in this case with -NLE_INVAL. You can check libnl behavior using NL_CAPABILITY_ROUTE_LINK_GET_KERNEL_FAIL_OPNOTSUPP capability.

Lookup Single Link (Direct Lookup) (Netlink Routing Development Guide)

Returns
  0 on success or a negative error code.

Definition at line 1431 of file link.c.

References nl_pickup_keep_syserr(), nl_send_auto(), and rtnl_link_build_get_request().

Referenced by rtnl_link_bond_enslave_ifindex(), and rtnl_link_enslave_ifindex().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ rtnl_link_i2name()

char * rtnl_link_i2name | ( | struct nl_cache * | cache,
|  | int | ifindex,
|  | char * | dst,
|  | size_t | len )

Translate interface index to corresponding link name.

Parameters

  cache | Link cache
  ifindex | Interface index
  dst | String to store name
  len | Length of destination string

Translates the specified interface index to the corresponding link name and stores the name in the destination string.

Translating interface index to link name (Netlink Routing Development Guide)

See also
  rtnl_link_name2i()

Returns
  Name of link or NULL if no match was found.

Definition at line 1483 of file link.c.

References rtnl_link_get().

Here is the call graph for this function:

## ◆ rtnl_link_name2i()

int rtnl_link_name2i | ( | struct nl_cache * | cache,
|  | const char * | name )

Translate link name to corresponding interface index.

Parameters

  cache | Link cache
  name | Name of link

Translating interface index to link name (Netlink Routing Development Guide)

See also
  rtnl_link_i2name()

Returns
  Interface index or 0 if no match was found.

Definition at line 1506 of file link.c.

References rtnl_link_get_by_name().

Here is the call graph for this function:

## ◆ rtnl_link_fill_info()

int rtnl_link_fill_info | ( | struct nl_msg * | msg,
|  | struct rtnl_link * | link )

Definition at line 1519 of file link.c.

## ◆ rtnl_link_build_add_request()

int rtnl_link_build_add_request | ( | struct rtnl_link * | link,
|  | int | flags,
|  | struct nl_msg ** | result )

Build a netlink message requesting the addition of new virtual link.

Parameters

  link | new link to add
  flags | additional netlink message flags
  result | pointer to store resulting netlink message

The behaviour of this function is identical to rtnl_link_add() with the exception that it will not send the message but return it in the provided return pointer instead.

See also
  rtnl_link_add()

Note
  This operation is not supported on all kernel versions.

Returns
  0 on success or a negative error code.

Definition at line 1664 of file link.c.

Referenced by rtnl_link_add().

Here is the caller graph for this function:

## ◆ rtnl_link_add()

int rtnl_link_add | ( | struct nl_sock * | sk,
|  | struct rtnl_link * | link,
|  | int | flags )

Add virtual link.

Parameters

  sk | netlink socket.
  link | new link to add
  flags | additional netlink message flags

Builds a `RTM_NEWLINK` netlink message requesting the addition of a new virtual link.

After sending, the function will wait for the ACK or an eventual error message to be received and will therefore block until the operation has been completed.

Attention
  Disabling Auto-ACK (nl_socket_disable_auto_ack()) will cause this function to return immediately after sending the netlink message. The function will not wait for an eventual error message. It is the responsibility of the caller to handle any error messages or ACKs returned.

Returns
  0 on success or a negative error code.

Definition at line 1694 of file link.c.

References nl_send_sync(), and rtnl_link_build_add_request().

Referenced by rtnl_link_bond_add(), rtnl_link_bridge_add(), rtnl_link_ip6_tnl_add(), rtnl_link_ip6gre_add(), rtnl_link_ip6vti_add(), rtnl_link_ipgre_add(), rtnl_link_ipgretap_add(), rtnl_link_ipip_add(), rtnl_link_ipvti_add(), rtnl_link_sit_add(), rtnl_link_team_add(), and rtnl_link_veth_add().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ rtnl_link_build_change_request()

int rtnl_link_build_change_request | ( | struct rtnl_link * | orig,
|  | struct rtnl_link * | changes,
|  | int | flags,
|  | struct nl_msg ** | result )

Build a netlink message requesting the modification of link.

Parameters

  orig | original link to change
  changes | link containing the changes to be made
  flags | additional netlink message flags
  result | pointer to store resulting netlink message

The behaviour of this function is identical to rtnl_link_change() with the exception that it will not send the message but return it in the provided return pointer instead.

See also
  rtnl_link_change()

Note
  The resulting message will have message type set to RTM_NEWLINK which may not work with older kernels. You may have to modify it to RTM_SETLINK (does not allow changing link info attributes) to have the change request work with older kernels.

Returns
  0 on success or a negative error code.

Definition at line 1726 of file link.c.

Referenced by rtnl_link_change().

Here is the caller graph for this function:

## ◆ rtnl_link_change()

int rtnl_link_change | ( | struct nl_sock * | sk,
|  | struct rtnl_link * | orig,
|  | struct rtnl_link * | changes,
|  | int | flags )

Change link.

Parameters

  sk | netlink socket.
  orig | original link to be changed
  changes | link containing the changes to be made
  flags | additional netlink message flags

Builds a `RTM_NEWLINK` netlink message requesting the change of a network link. If -EOPNOTSUPP is returned by the kernel, the message type will be changed to `RTM_SETLINK` and the message is resent to work around older kernel versions.

The link to be changed is looked up based on the interface index supplied in the `orig` link. Optionaly the link name is used but only if no interface index is provided, otherwise providing an link name will result in the link name being changed.

If no matching link exists, the function will return -NLE_OBJ_NOTFOUND.

After sending, the function will wait for the ACK or an eventual error message to be received and will therefore block until the operation has been completed.

Attention
  Disabling Auto-ACK (nl_socket_disable_auto_ack()) will cause this function to return immediately after sending the netlink message. The function will not wait for an eventual error message. It is the responsibility of the caller to handle any error messages or ACKs returned.

Note
  The link name can only be changed if the link has been put in opertional down state. (~IF_UP)
  On versions up to 3.4.0, `NLE_SEQ_MISMATCH` would be returned if the kernel does not supports `RTM_NEWLINK`. It is advised to ignore the error code if you cannot upgrade the library.

Returns
  0 on success or a negative error code.

Definition at line 1797 of file link.c.

References NL_AUTO_SEQ, nl_send_auto_complete(), and rtnl_link_build_change_request().

Referenced by rtnl_link_bond_enslave_ifindex(), and rtnl_link_enslave_ifindex().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ rtnl_link_build_delete_request()

int rtnl_link_build_delete_request | ( | const struct rtnl_link * | link,
|  | struct nl_msg ** | result )

Build a netlink message requesting the deletion of a link.

Parameters

  link | Link to delete
  result | Pointer to store resulting netlink message

The behaviour of this function is identical to rtnl_link_delete() with the exception that it will not send the message but return it in the provided return pointer instead.

See also
  rtnl_link_delete()

Returns
  0 on success or a negative error code.

Definition at line 1847 of file link.c.

References nla_put_string(), nlmsg_alloc_simple(), and nlmsg_append().

Referenced by rtnl_link_delete().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ rtnl_link_delete()

int rtnl_link_delete | ( | struct nl_sock * | sk,
|  | const struct rtnl_link * | link )

Delete link.

Parameters

  sk | Netlink socket
  link | Link to delete

Builds a `RTM_DELLINK` netlink message requesting the deletion of a network link which has been previously added to the kernel and sends the message to the kernel.

If no matching link exists, the function will return -NLE_OBJ_NOTFOUND.

After sending, the function will wait for the ACK or an eventual error message to be received and will therefore block until the operation has been completed.

Attention
  Disabling Auto-ACK (nl_socket_disable_auto_ack()) will cause this function to return immediately after sending the netlink message. The function will not wait for an eventual error message. It is the responsibility of the caller to handle any error messages or ACKs returned.

Note
  Only virtual links such as dummy interface or vlan interfaces can be deleted. It is not possible to delete physical interfaces such as ethernet interfaces or the loopback device.

Returns
  0 on success or a negative error code.

Definition at line 1896 of file link.c.

References nl_send_sync(), and rtnl_link_build_delete_request().

Here is the call graph for this function:

## ◆ rtnl_link_alloc()

struct rtnl_link * rtnl_link_alloc | ( | void |  | ) |

Allocate link object.

See also
  rtnl_link_put()

Returns
  New link object or NULL if allocation failed

Definition at line 1920 of file link.c.

References nl_object_alloc().

Referenced by rtnl_link_bond_alloc(), rtnl_link_bridge_alloc(), rtnl_link_enslave_ifindex(), rtnl_link_geneve_alloc(), rtnl_link_ipvlan_alloc(), rtnl_link_macvlan_alloc(), rtnl_link_macvtap_alloc(), rtnl_link_ppp_alloc(), rtnl_link_team_alloc(), rtnl_link_veth_alloc(), rtnl_link_vlan_alloc(), rtnl_link_vrf_alloc(), and rtnl_link_vxlan_alloc().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ rtnl_link_put()

void rtnl_link_put | ( | struct rtnl_link * | link | ) |

Release a link object reference.

Parameters

  link | Link object

Definition at line 1929 of file link.c.

References nl_object_put().

Referenced by rtnl_link_bond_add(), rtnl_link_bond_alloc(), rtnl_link_bond_enslave_ifindex(), rtnl_link_bridge_add(), rtnl_link_bridge_alloc(), rtnl_link_enslave_ifindex(), rtnl_link_geneve_alloc(), rtnl_link_ip6_tnl_add(), rtnl_link_ip6gre_add(), rtnl_link_ip6vti_add(), rtnl_link_ipgre_add(), rtnl_link_ipgretap_add(), rtnl_link_ipip_add(), rtnl_link_ipvlan_alloc(), rtnl_link_ipvti_add(), rtnl_link_macvlan_alloc(), rtnl_link_macvtap_alloc(), rtnl_link_ppp_alloc(), rtnl_link_sit_add(), rtnl_link_team_add(), rtnl_link_team_alloc(), rtnl_link_veth_add(), rtnl_link_veth_alloc(), rtnl_link_veth_release(), rtnl_link_vlan_alloc(), rtnl_link_vrf_alloc(), rtnl_link_vxlan_alloc(), rtnl_tc_set_ifindex(), and rtnl_tc_set_link().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ rtnl_link_set_name()

void rtnl_link_set_name | ( | struct rtnl_link * | link,
|  | const char * | name )

Set name of link object.

Parameters

  link | Link object
  name | New name

Note
  To change the name of a link in the kernel, set the interface index to the link you wish to change, modify the link name using this function and pass the link object to rtnl_link_change() or rtnl_link_add().

Link Name (Netlink Routing Development Guide)

See also
  rtnl_link_get_name()
  rtnl_link_set_ifindex()

Definition at line 1948 of file link.c.

Referenced by rtnl_link_bond_add(), rtnl_link_bridge_add(), rtnl_link_ip6_tnl_add(), rtnl_link_ip6gre_add(), rtnl_link_ip6vti_add(), rtnl_link_ipgre_add(), rtnl_link_ipgretap_add(), rtnl_link_ipip_add(), rtnl_link_ipvti_add(), rtnl_link_sit_add(), rtnl_link_team_add(), and rtnl_link_veth_add().

Here is the caller graph for this function:

## ◆ rtnl_link_get_name()

char * rtnl_link_get_name | ( | struct rtnl_link * | link | ) |

Return name of link object.

Parameters

  link | Link object

Link Name (Netlink Routing Development Guide)

See also
  rtnl_link_set_name()

Returns
  Link name or NULL if name is not specified

Definition at line 1962 of file link.c.

Referenced by rtnl_link_bond_add(), and rtnl_link_team_add().

Here is the caller graph for this function:

## ◆ rtnl_link_set_group()

void rtnl_link_set_group | ( | struct rtnl_link * | link,
|  | uint32_t | group )

Set the group identifier of a link object.

Parameters

  link | Link object
  group | Group identifier

Definition at line 1972 of file link.c.

## ◆ rtnl_link_get_group()

uint32_t rtnl_link_get_group | ( | struct rtnl_link * | link | ) |

Return the group identifier of link object.

Parameters

  link | Link object

Returns
  Group identifier or 0 if not set.

Definition at line 1984 of file link.c.

## ◆ rtnl_link_set_addr()

void rtnl_link_set_addr | ( | struct rtnl_link * | link,
|  | struct nl_addr * | addr )

Set link layer address of link object.

Parameters

  link | Link object
  addr | New link layer address

The function increments the reference counter of the address object and overwrites any existing link layer address previously assigned.

Link layer address (Netlink Routing Development Guide)

See also
  rtnl_link_get_addr()

Definition at line 2012 of file link.c.

## ◆ rtnl_link_get_addr()

struct nl_addr * rtnl_link_get_addr | ( | struct rtnl_link * | link | ) |

Return link layer address of link object.

Parameters

  link | Link object

Attention
  The reference counter of the returned object is not incremented. Therefore, the returned pointer is only valid during the lifetime of the parent object. Increment the reference counter if the object is supposed to stay around after the parent object was freed. Link Layer Address (Netlink Routing Development Guide)

See also
  rtnl_link_set_addr()

Returns
  Link layer address or NULL if not set.

Definition at line 2026 of file link.c.

## ◆ rtnl_link_set_broadcast()

void rtnl_link_set_broadcast | ( | struct rtnl_link * | link,
|  | struct nl_addr * | addr )

Set link layer broadcast address of link object.

Parameters

  link | Link object
  addr | New broadcast address

The function increments the reference counter of the address object and overwrites any existing link layer broadcast address previously assigned.

Link Layer Broadcast Address (Netlink Routing Development Guide)

See also
  rtnl_link_get_broadcast()

Definition at line 2043 of file link.c.

## ◆ rtnl_link_get_broadcast()

struct nl_addr * rtnl_link_get_broadcast | ( | struct rtnl_link * | link | ) |

Return link layer broadcast address of link object.

Parameters

  link | Link object

Attention
  The reference counter of the returned object is not incremented. Therefore, the returned pointer is only valid during the lifetime of the parent object. Increment the reference counter if the object is supposed to stay around after the parent object was freed. Link Layer Address (Netlink Routing Development Guide)

See also
  rtnl_link_set_broadcast()

Returns
  Link layer address or NULL if not set.

Definition at line 2057 of file link.c.

## ◆ rtnl_link_set_flags()

void rtnl_link_set_flags | ( | struct rtnl_link * | link,
|  | unsigned int | flags )

Set flags of link object.

Parameters

  link | Link object
  flags | Flags

See also
  rtnl_link_get_flags()
  rtnl_link_unset_flags()

Definition at line 2070 of file link.c.

## ◆ rtnl_link_unset_flags()

void rtnl_link_unset_flags | ( | struct rtnl_link * | link,
|  | unsigned int | flags )

Unset flags of link object.

Parameters

  link | Link object
  flags | Flags

See also
  rtnl_link_set_flags()
  rtnl_link_get_flags()

Definition at line 2085 of file link.c.

## ◆ rtnl_link_get_flags()

unsigned int rtnl_link_get_flags | ( | struct rtnl_link * | link | ) |

Return flags of link object.

Parameters

  link | Link object

Link Flags (Netlink Routing Development Guide)

See also
  rtnl_link_set_flags()
  rtnl_link_unset_flags()

Returns
  Link flags or 0 if none have been set.

Definition at line 2101 of file link.c.

## ◆ rtnl_link_set_family()

void rtnl_link_set_family | ( | struct rtnl_link * | link,
|  | int | family )

Set address family of link object.

See also
  rtnl_link_get_family()

Definition at line 2111 of file link.c.

References rtnl_link_af_ops::ao_family.

## ◆ rtnl_link_get_family()

int rtnl_link_get_family | ( | struct rtnl_link * | link | ) |

Return address family of link object.

Parameters

  link | Link object

See also
  rtnl_link_set_family()

Returns
  Address family or `AF_UNSPEC` if not specified.

Definition at line 2133 of file link.c.

## ◆ rtnl_link_set_arptype()

void rtnl_link_set_arptype | ( | struct rtnl_link * | link,
|  | unsigned int | arptype )

Set hardware type of link object.

Parameters

  link | Link object
  arptype | New hardware type ``(ARPHRD_*)

Hardware Type (Netlink Routing Development Guide)

Note
  The attribute this accessor is modifying is a read-only attribute which can not be modified in the kernel. Any changes to the attribute only have an effect on the local copy of the object. The accessor function is provided solely for the purpose of creating objects for comparison and filtering.

See also
  rtnl_link_get_arptype()

Definition at line 2147 of file link.c.

## ◆ rtnl_link_get_arptype()

unsigned int rtnl_link_get_arptype | ( | struct rtnl_link * | link | ) |

Get hardware type of link object.

Parameters

  link | Link object

Hardware Type (Netlink Routing Development Guide)

See also
  rtnl_link_set_arptype()

Returns
  Hardware type ``(ARPHRD_ETHER *) or `ARPHRD_VOID`

Definition at line 2161 of file link.c.

## ◆ rtnl_link_set_ifindex()

void rtnl_link_set_ifindex | ( | struct rtnl_link * | link,
|  | int | ifindex )

Set interface index of link object.

Parameters

  link | Link object
  ifindex | Interface index

Interface Index (Netlink Routing Development Guide)

See also
  rtnl_link_get_ifindex()

Definition at line 2177 of file link.c.

Referenced by rtnl_link_bond_enslave_ifindex(), and rtnl_link_enslave_ifindex().

Here is the caller graph for this function:

## ◆ rtnl_link_get_ifindex()

int rtnl_link_get_ifindex | ( | struct rtnl_link * | link | ) |

Return interface index of link object.

Parameters

  link | Link object

Interface Index (Netlink Routing Development Guide)

See also
  rtnl_link_set_ifindex()

Returns
  Interface index or 0 if not set.

Definition at line 2192 of file link.c.

Referenced by rtnl_link_bond_enslave(), rtnl_link_bond_release(), rtnl_link_enslave(), and rtnl_link_release().

Here is the caller graph for this function:

## ◆ rtnl_link_set_mtu()

void rtnl_link_set_mtu | ( | struct rtnl_link * | link,
|  | unsigned int | mtu )

Set Maximum Transmission Unit of link object.

Parameters

  link | Link object
  mtu | New MTU value in number of bytes

Maximum Transmission Unit (Netlink Routing Development Guide)

See also
  rtnl_link_get_mtu()

Definition at line 2205 of file link.c.

## ◆ rtnl_link_get_mtu()

unsigned int rtnl_link_get_mtu | ( | struct rtnl_link * | link | ) |

Return maximum transmission unit of link object.

Parameters

  link | Link object

Maximum Transmission Unit (Netlink Routing Development Guide)

See also
  rtnl_link_set_mtu()

Returns
  MTU in bytes or 0 if not set

Definition at line 2219 of file link.c.

## ◆ rtnl_link_set_txqlen()

void rtnl_link_set_txqlen | ( | struct rtnl_link * | link,
|  | unsigned int | txqlen )

Set transmission queue length.

Parameters

  link | Link object
  txqlen | New queue length

The unit is dependant on the link type. The most common units is number of packets.

Transmission Queue Length (Netlink Routing Development Guide)

Definition at line 2234 of file link.c.

## ◆ rtnl_link_get_txqlen()

unsigned int rtnl_link_get_txqlen | ( | struct rtnl_link * | link | ) |

Return transmission queue length.

Parameters

  link | Link object

The unit is dependant on the link type. The most common units is number of packets.

Transmission Queue Length (Netlink Routing Development Guide)

Returns
  queue length or 0 if not specified.

Definition at line 2250 of file link.c.

## ◆ rtnl_link_set_link()

void rtnl_link_set_link | ( | struct rtnl_link * | link,
|  | int | ifindex )

Definition at line 2255 of file link.c.

## ◆ rtnl_link_get_link()

int rtnl_link_get_link | ( | struct rtnl_link * | link | ) |

Definition at line 2261 of file link.c.

## ◆ rtnl_link_set_link_netnsid()

int rtnl_link_set_link_netnsid | ( | struct rtnl_link * | link,
|  | int32_t | link_netnsid )

Set the netnsid of the link.

Parameters

  link | Link object @link_netnsid the netnsid to set

Sets the IFLA_LINK_NETNSID attribute of the link

Returns
  0 on success

Definition at line 2274 of file link.c.

## ◆ rtnl_link_get_link_netnsid()

int rtnl_link_get_link_netnsid | ( | const struct rtnl_link * | link,
|  | int32_t * | out_link_netnsid )

Get the netnsid of the link.

Parameters

  link | Link object @out_link_netnsid the netnsid

Gets the IFLA_LINK_NETNSID attribute of the link or returns an error if the value is unset.

Returns
  0 on success

Definition at line 2291 of file link.c.

## ◆ rtnl_link_set_master()

void rtnl_link_set_master | ( | struct rtnl_link * | link,
|  | int | ifindex )

Set master link of link object.

Parameters

  link | Link object
  ifindex | Interface index of master link

See also
  rtnl_link_get_master()

Definition at line 2307 of file link.c.

Referenced by rtnl_link_bond_enslave_ifindex(), and rtnl_link_enslave_ifindex().

Here is the caller graph for this function:

## ◆ rtnl_link_get_master()

int rtnl_link_get_master | ( | struct rtnl_link * | link | ) |

Return master link of link object.

Parameters

  link | Link object

See also
  rtnl_link_set_master()

Returns
  Interface index of master link or 0 if not specified

Definition at line 2320 of file link.c.

Referenced by rtnl_link_bond_enslave_ifindex(), and rtnl_link_enslave_ifindex().

Here is the caller graph for this function:

## ◆ rtnl_link_set_carrier()

void rtnl_link_set_carrier | ( | struct rtnl_link * | link,
|  | uint8_t | status )

Set carrier of link object.

Parameters

  link | Link object
  status | New carrier status

See also
  rtnl_link_get_carrier()

Definition at line 2332 of file link.c.

## ◆ rtnl_link_get_carrier()

uint8_t rtnl_link_get_carrier | ( | struct rtnl_link * | link | ) |

Return carrier status of link object.

Parameters

  link | Link object

See also
  rtnl_link_set_master()

Returns
  Carrier state.

Definition at line 2345 of file link.c.

## ◆ rtnl_link_get_carrier_changes()

int rtnl_link_get_carrier_changes | ( | struct rtnl_link * | link,
|  | uint32_t * | carrier_changes )

Return carrier on/off changes of link object.

Parameters

  link | Link object
  carrier_changes | Pointer to store number of carrier changes

Returns
  0 on success, negative error number otherwise

Definition at line 2357 of file link.c.

## ◆ rtnl_link_set_operstate()

void rtnl_link_set_operstate | ( | struct rtnl_link * | link,
|  | uint8_t | status )

Set operational status of link object.

Parameters

  link | Link object
  status | New opertional status

Operational Status (Netlink Routing Development Guide)}

See also
  rtnl_link_get_operstate()

Definition at line 2376 of file link.c.

## ◆ rtnl_link_get_operstate()

uint8_t rtnl_link_get_operstate | ( | struct rtnl_link * | link | ) |

Return operational status of link object.

Parameters

  link | Link object

Operational Status (Netlink Routing Development Guide)

See also
  rtnl_link_set_operstate()

Returns
  Opertional state or `IF_OPER_UNKNOWN`

Definition at line 2390 of file link.c.

## ◆ rtnl_link_set_linkmode()

void rtnl_link_set_linkmode | ( | struct rtnl_link * | link,
|  | uint8_t | mode )

Set link mode of link object.

Parameters

  link | Link object
  mode | New link mode

Mode (Netlink Routing Development Guide)

See also
  rtnl_link_get_linkmode()

Definition at line 2403 of file link.c.

## ◆ rtnl_link_get_linkmode()

uint8_t rtnl_link_get_linkmode | ( | struct rtnl_link * | link | ) |

Return link mode of link object.

Parameters

  link | Link object

Mode (Netlink Routing Development Guide)

See also
  rtnl_link_get_linkmode()

Returns
  Link mode or `IF_LINK_MODE_DEFAULT`

Definition at line 2417 of file link.c.

## ◆ rtnl_link_get_ifalias()

const char * rtnl_link_get_ifalias | ( | struct rtnl_link * | link | ) |

Return alias name of link object (SNMP IfAlias)

Parameters

  link | Link object

Alias (Netlink Routing Development Guide)

See also
  rtnl_link_set_ifalias()

Returns
  Alias name or NULL if not set.

Definition at line 2430 of file link.c.

## ◆ rtnl_link_set_ifalias()

void rtnl_link_set_ifalias | ( | struct rtnl_link * | link,
|  | const char * | alias )

Set alias name of link object (SNMP IfAlias)

Parameters

  link | Link object
  alias | Alias name or NULL to unset

Sets the alias name of the link to the specified name. The alias name can be unset by specyfing NULL as the alias. The name will be strdup()ed, so no need to provide a persistent character string.

Alias (Netlink Routing Development Guide)

See also
  rtnl_link_get_ifalias()

Definition at line 2447 of file link.c.

## ◆ rtnl_link_set_qdisc()

void rtnl_link_set_qdisc | ( | struct rtnl_link * | link,
|  | const char * | name )

Set queueing discipline name of link object.

Parameters

  link | Link object
  name | Name of queueing discipline

Note
  The attribute this accessor is modifying is a read-only attribute which can not be modified in the kernel. Any changes to the attribute only have an effect on the local copy of the object. The accessor function is provided solely for the purpose of creating objects for comparison and filtering.

For more information on how to modify the qdisc of a link, see section Traffic Control (Netlink Routing Development Guide).

Queueing Discipline Name (Netlink Routing Development Guide)

See also
  rtnl_link_get_qdisc()

Definition at line 2473 of file link.c.

## ◆ rtnl_link_get_qdisc()

char * rtnl_link_get_qdisc | ( | struct rtnl_link * | link | ) |

Return name of queueing discipline of link object.

Parameters

  link | Link object

Queueing Discipline Name (Netlink Routing Development Guide)

See also
  rtnl_link_set_qdisc()

Returns
  Name of qdisc or NULL if not specified.

Definition at line 2487 of file link.c.

## ◆ rtnl_link_get_num_vf()

int rtnl_link_get_num_vf | ( | struct rtnl_link * | link,
|  | uint32_t * | num_vf )

Return number of PCI virtual functions of link object.

Parameters

  link | Link object
  num_vf | Pointer to store number of VFs

Returns
  0 on success or -NLE_OPNOTSUPP if not available

Definition at line 2500 of file link.c.

## ◆ rtnl_link_get_stat()

uint64_t rtnl_link_get_stat | ( | struct rtnl_link * | link,
|  | rtnl_link_stat_id_t | id )

Return value of link statistics counter.

Parameters

  link | Link object
  id | Identifier of statistical counter

Returns
  Value of counter or 0 if not specified.

Definition at line 2516 of file link.c.

## ◆ rtnl_link_set_stat()

int rtnl_link_set_stat | ( | struct rtnl_link * | link,
|  | rtnl_link_stat_id_t | id,
|  | const uint64_t | value )

Set value of link statistics counter.

Parameters

  link | Link object
  id | Identifier of statistical counter
  value | New value

Note
  Changing the value of a statistical counter will not change the value in the kernel.

Returns
  0 on success or a negative error code

Definition at line 2535 of file link.c.

## ◆ rtnl_link_set_type()

int rtnl_link_set_type | ( | struct rtnl_link * | link,
|  | const char * | type )

Set type of link object.

Parameters

  link | Link object
  type | Name of link type

Looks up the link type module and prepares the link to store type specific attributes. If a type has been assigned already it will be released with all link type specific attributes lost.

Link Modules (Netlink Routing Development Guide)

Returns
  0 on success or a negative error code.

Definition at line 2558 of file link.c.

References rtnl_link_info_ops::io_alloc, and rtnl_link_info_ops_lookup().

Referenced by rtnl_link_bond_alloc(), rtnl_link_bridge_alloc(), rtnl_link_geneve_alloc(), rtnl_link_ipvlan_alloc(), rtnl_link_macvlan_alloc(), rtnl_link_macvtap_alloc(), rtnl_link_ppp_alloc(), rtnl_link_set_info_type(), rtnl_link_team_alloc(), rtnl_link_veth_alloc(), rtnl_link_vlan_alloc(), rtnl_link_vrf_alloc(), and rtnl_link_vxlan_alloc().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ rtnl_link_get_type()

char * rtnl_link_get_type | ( | struct rtnl_link * | link | ) |

Return type of link.

Parameters

  link | Link object

Link Modules (Netlink Routing Development Guide)

Returns
  Name of link type or NULL if not specified.

Definition at line 2598 of file link.c.

Referenced by rtnl_link_get_info_type().

Here is the caller graph for this function:

## ◆ rtnl_link_set_slave_type()

int rtnl_link_set_slave_type | ( | struct rtnl_link * | link,
|  | const char * | type )

Set type of slave link object.

Parameters

  link | Link object (slave)
  type | Name of link type

If a slave type has been assigned already it will be released.

Link Modules (Netlink Routing Development Guide)

Returns
  0 on success or a negative error code.

Definition at line 2613 of file link.c.

## ◆ rtnl_link_get_slave_type()

const char * rtnl_link_get_slave_type | ( | const struct rtnl_link * | link | ) |

Return type of enslaved link.

Parameters

  link | Link object

Link Modules (Netlink Routing Development Guide)

Returns
  Name of enslaved link type or NULL if not specified.

Definition at line 2640 of file link.c.

## ◆ rtnl_link_set_promiscuity()

void rtnl_link_set_promiscuity | ( | struct rtnl_link * | link,
|  | uint32_t | count )

Set link promiscuity count.

Parameters

  link | Link object
  count | New promiscuity count

Note
  The attribute this accessor is modifying is a read-only attribute which can not be modified in the kernel. Any changes to the attribute only have an effect on the local copy of the object. The accessor function is provided solely for the purpose of creating objects for comparison and filtering.

See also
  rtnl_link_get_promiscuity()

Definition at line 2655 of file link.c.

## ◆ rtnl_link_get_promiscuity()

uint32_t rtnl_link_get_promiscuity | ( | struct rtnl_link * | link | ) |

Return link promiscuity count.

Parameters

  link | Link object

See also
  rtnl_link_set_promiscuity()

Returns
  Link promiscuity count or 0

Definition at line 2668 of file link.c.

## ◆ rtnl_link_set_num_tx_queues()

void rtnl_link_set_num_tx_queues | ( | struct rtnl_link * | link,
|  | uint32_t | nqueues )

Set number of TX queues.

Parameters

  link | Link object
  nqueues | Number of queues

Sets the number of TX queues of the link object. The value is considered by the kernel when creating network devices that can be created via netlink. The value will be passed on to alloc_netdev_mqs()

Therefore use of rtnl_link_set_num_tx_queues() only makes sense in combination with rtnl_link_add() or if the link object is used as a filter.

See also
  rtnl_link_get_num_tx_queues()

Definition at line 2687 of file link.c.

## ◆ rtnl_link_get_num_tx_queues()

uint32_t rtnl_link_get_num_tx_queues | ( | struct rtnl_link * | link | ) |

Return number of TX queues.

Parameters

  link | Link object

Returns
  Number of TX queues or 0

Definition at line 2699 of file link.c.

## ◆ rtnl_link_set_num_rx_queues()

void rtnl_link_set_num_rx_queues | ( | struct rtnl_link * | link,
|  | uint32_t | nqueues )

Set number of RX queues.

Parameters

  link | Link object
  nqueues | Number of queues

Sets the number of RX queues of the link object. The value is considered by the kernel when creating network devices that can be created via netlink. The value will be passed on to alloc_netdev_mqs()

Therefore use of rtnl_link_set_num_rx_queues() only makes sense in combination with rtnl_link_add() or if the link object is used as a filter.

See also
  rtnl_link_get_num_rx_queues()

Definition at line 2718 of file link.c.

## ◆ rtnl_link_get_num_rx_queues()

uint32_t rtnl_link_get_num_rx_queues | ( | struct rtnl_link * | link | ) |

Return number of RX queues.

Parameters

  link | Link object

Returns
  Number of RX queues or 0

Definition at line 2730 of file link.c.

## ◆ rtnl_link_get_gso_max_segs()

int rtnl_link_get_gso_max_segs | ( | struct rtnl_link * | link,
|  | uint32_t * | gso_max_segs )

Return maximum number of segments for generic segmentation offload.

Parameters

  link | Link object
  gso_max_segs | Pointer to store maximum number GSO segments

Returns
  0 on success, negative error number otherwise

Definition at line 2742 of file link.c.

## ◆ rtnl_link_get_gso_max_size()

int rtnl_link_get_gso_max_size | ( | struct rtnl_link * | link,
|  | uint32_t * | gso_max_size )

Return maximum size for generic segmentation offload.

Parameters

  link | Link object
  gso_max_segs | Pointer to store maximum GSO size

Returns
  0 on success, negative error number otherwise

Definition at line 2760 of file link.c.

## ◆ rtnl_link_get_phys_port_id()

struct nl_data * rtnl_link_get_phys_port_id | ( | struct rtnl_link * | link | ) |

Return physical port id of link object.

Parameters

  link | Link object

Returns
  Physical port id or NULL if not set.

Definition at line 2777 of file link.c.

## ◆ rtnl_link_get_phys_port_name()

char * rtnl_link_get_phys_port_name | ( | struct rtnl_link * | link | ) |

Return physical port name of link object.

Parameters

  link | Link object

Returns
  Physical port name or NULL if not set.

Definition at line 2788 of file link.c.

## ◆ rtnl_link_get_phys_switch_id()

struct nl_data * rtnl_link_get_phys_switch_id | ( | struct rtnl_link * | link | ) |

Definition at line 2799 of file link.c.

## ◆ rtnl_link_set_ns_fd()

void rtnl_link_set_ns_fd | ( | struct rtnl_link * | link,
|  | int | fd )

Definition at line 2804 of file link.c.

## ◆ rtnl_link_get_ns_fd()

int rtnl_link_get_ns_fd | ( | struct rtnl_link * | link | ) |

Definition at line 2810 of file link.c.

## ◆ rtnl_link_set_ns_pid()

void rtnl_link_set_ns_pid | ( | struct rtnl_link * | link,
|  | pid_t | pid )

Definition at line 2815 of file link.c.

## ◆ rtnl_link_get_ns_pid()

pid_t rtnl_link_get_ns_pid | ( | struct rtnl_link * | link | ) |

Definition at line 2821 of file link.c.

## ◆ rtnl_link_enslave_ifindex()

int rtnl_link_enslave_ifindex | ( | struct nl_sock * | sock,
|  | int | master,
|  | int | slave )

Enslave slave link to master link.

Parameters

  sock | netlink socket
  master | ifindex of master link
  slave | ifindex of slave link

This function is identical to rtnl_link_enslave() except that it takes interface indices instead of rtnl_link objects.

See also
  rtnl_link_enslave()

Returns
  0 on success or a negative error code.

Definition at line 2846 of file link.c.

References rtnl_link_alloc(), rtnl_link_change(), rtnl_link_get_kernel(), rtnl_link_get_master(), rtnl_link_put(), rtnl_link_set_ifindex(), and rtnl_link_set_master().

Referenced by rtnl_link_enslave(), and rtnl_link_release_ifindex().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ rtnl_link_enslave()

int rtnl_link_enslave | ( | struct nl_sock * | sock,
|  | struct rtnl_link * | master,
|  | struct rtnl_link * | slave )

Enslave slave link to master link.

Parameters

  sock | netlink socket
  master | master link
  slave | slave link

Constructs a RTM_NEWLINK or RTM_SETLINK message adding the slave to the master and sends the request via the specified netlink socket.

Note
  The feature of enslaving/releasing via netlink has only been added recently to the kernel (Feb 2011). Also, the kernel does not signal if the operation is not supported. Therefore this function will verify if the master assignment has changed and will return -NLE_OPNOTSUPP if it did not.

See also
  rtnl_link_enslave_ifindex()
  rtnl_link_release()

Returns
  0 on success or a negative error code.

Definition at line 2898 of file link.c.

References rtnl_link_enslave_ifindex(), and rtnl_link_get_ifindex().

Here is the call graph for this function:

## ◆ rtnl_link_release_ifindex()

int rtnl_link_release_ifindex | ( | struct nl_sock * | sock,
|  | int | slave )

Release slave link from its master.

Parameters

  sock | netlink socket
  slave | slave link

This function is identical to rtnl_link_release() except that it takes an interface index instead of a rtnl_link object.

See also
  rtnl_link_release()

Returns
  0 on success or a negative error code.

Definition at line 2917 of file link.c.

References rtnl_link_enslave_ifindex().

Referenced by rtnl_link_release().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ rtnl_link_release()

int rtnl_link_release | ( | struct nl_sock * | sock,
|  | struct rtnl_link * | slave )

Release slave link from its master.

Parameters

  sock | netlink socket
  slave | slave link

Constructs a RTM_NEWLINK or RTM_SETLINK message releasing the slave from its master and sends the request via the specified netlink socket.

Note
  The feature of enslaving/releasing via netlink has only been added recently to the kernel (Feb 2011). Also, the kernel does not signal if the operation is not supported. Therefore this function will verify if the master assignment has changed and will return -NLE_OPNOTSUPP if it did not.

See also
  rtnl_link_release_ifindex()
  rtnl_link_enslave()

Returns
  0 on success or a negative error code.

Definition at line 2941 of file link.c.

References rtnl_link_get_ifindex(), and rtnl_link_release_ifindex().

Here is the call graph for this function:

## ◆ rtnl_link_flags2str()

char * rtnl_link_flags2str | ( | int | flags,
|  | char * | buf,
|  | size_t | len )

Definition at line 2975 of file link.c.

## ◆ rtnl_link_str2flags()

int rtnl_link_str2flags | ( | const char * | name | ) |

Definition at line 2981 of file link.c.

## ◆ rtnl_link_stat2str()

char * rtnl_link_stat2str | ( | int | st,
|  | char * | buf,
|  | size_t | len )

Definition at line 3054 of file link.c.

## ◆ rtnl_link_str2stat()

int rtnl_link_str2stat | ( | const char * | name | ) |

Definition at line 3059 of file link.c.

## ◆ rtnl_link_operstate2str()

char * rtnl_link_operstate2str | ( | uint8_t | st,
|  | char * | buf,
|  | size_t | len )

Definition at line 3074 of file link.c.

## ◆ rtnl_link_str2operstate()

int rtnl_link_str2operstate | ( | const char * | name | ) |

Definition at line 3080 of file link.c.

## ◆ rtnl_link_mode2str()

char * rtnl_link_mode2str | ( | uint8_t | st,
|  | char * | buf,
|  | size_t | len )

Definition at line 3096 of file link.c.

## ◆ rtnl_link_str2mode()

int rtnl_link_str2mode | ( | const char * | name | ) |

Definition at line 3101 of file link.c.

## ◆ rtnl_link_carrier2str()

char * rtnl_link_carrier2str | ( | uint8_t | st,
|  | char * | buf,
|  | size_t | len )

Definition at line 3106 of file link.c.

## ◆ rtnl_link_str2carrier()

int rtnl_link_str2carrier | ( | const char * | name | ) |

Definition at line 3112 of file link.c.

## ◆ rtnl_link_has_vf_list()

int rtnl_link_has_vf_list | ( | struct rtnl_link * | link | ) |

Definition at line 3117 of file link.c.

## ◆ rtnl_link_set_vf_list()

void rtnl_link_set_vf_list | ( | struct rtnl_link * | link | ) |

Definition at line 3124 of file link.c.

## ◆ rtnl_link_unset_vf_list()

void rtnl_link_unset_vf_list | ( | struct rtnl_link * | link | ) |

Definition at line 3130 of file link.c.

## ◆ rtnl_link_set_info_type()

int rtnl_link_set_info_type | ( | struct rtnl_link * | link,
|  | const char * | type )

Deprecated
  Use of this function is deprecated, use rtnl_link_set_type()

Definition at line 3145 of file link.c.

References rtnl_link_set_type().

Here is the call graph for this function:

## ◆ rtnl_link_get_info_type()

char * rtnl_link_get_info_type | ( | struct rtnl_link * | link | ) |

Deprecated
  Use of this function is deprecated, use rtnl_link_get_type()

Definition at line 3153 of file link.c.

References rtnl_link_get_type().

Here is the call graph for this function:

## ◆ rtnl_link_set_weight()

void rtnl_link_set_weight | ( | struct rtnl_link * | link,
|  | unsigned int | weight )

Deprecated
  The weight attribute is unused and obsoleted in all recent kernels

Definition at line 3161 of file link.c.

## ◆ rtnl_link_get_weight()

unsigned int rtnl_link_get_weight | ( | struct rtnl_link * | link | ) |

Deprecated
  The weight attribute is unused and obsoleted in all recent kernels

Definition at line 3170 of file link.c.

## Variable Documentation

## ◆ rtln_link_policy

struct nla_policy rtln_link_policy[IFLA_MAX+1]

Definition at line 361 of file link.c.