netdef.h

Functions for manipulating NetplanNetDefinition objects and querying properties of individual Netplan IDs.

Functions

ssize_t netplan_netdef_get_output_filename(const NetplanNetDefinition *netdef, const char *ssid, char *out_buffer, size_t out_buf_size)

Get the full path that a NetplanNetDefinition will be written to by its backend renderer.

Copies a NUL-terminated string into a sized out_buffer. If the buffer is too small, its content is not NUL-terminated.

Note

Used by the NetworkManager YAML backend but also applicable to the systemd-networkd renderer.

Parameters:
  • netdef -- [in] The NetplanNetDefinition to query

  • ssid -- [in] Wi-Fi SSID of this connection, or NULL

  • out_buffer -- [out] A pre-allocated buffer to write the output string into, owned by the caller

  • out_buf_size -- [in] The maximum size (in bytes) available for out_buffer

Returns:

The size of the copied string, including the final NUL character. If the buffer is too small, returns NETPLAN_BUFFER_TOO_SMALL instead.

ssize_t netplan_netdef_get_filepath(const NetplanNetDefinition *netdef, char *out_buffer, size_t out_buffer_size)

Get the origin filepath of a given NetplanNetDefinition.

Copies a NUL-terminated string into a sized out_buffer. If the buffer is too small, its content is not NUL-terminated.

Parameters:
  • netdef -- [in] The NetplanNetDefinition to query

  • out_buffer -- [out] A pre-allocated buffer to write the output string into, owned by the caller

  • out_buffer_size -- [in] The maximum size (in bytes) available for out_buffer

Returns:

The size of the copied string, including the final NUL character. If the buffer is too small, returns NETPLAN_BUFFER_TOO_SMALL instead.

NetplanBackend netplan_netdef_get_backend(const NetplanNetDefinition *netdef)

Get the specific NetplanBackend defined for this NetplanNetDefinition.

Parameters:
Returns:

Enumeration value, specifiying the NetplanBackend

NetplanDefType netplan_netdef_get_type(const NetplanNetDefinition *netdef)

Get the interface type for a given NetplanNetDefinition.

Parameters:
Returns:

Enumeration value of NetplanDefType, specifiying the interface type

ssize_t netplan_netdef_get_id(const NetplanNetDefinition *netdef, char *out_buffer, size_t out_buffer_size)

Get the Netplan ID of a given NetplanNetDefinition.

Copies a NUL-terminated string into a sized out_buffer. If the buffer is too small, its content is not NUL-terminated.

Parameters:
  • netdef -- [in] The NetplanNetDefinition to query

  • out_buffer -- [out] A pre-allocated buffer to write the output string into, owned by the caller

  • out_buffer_size -- [in] The maximum size (in bytes) available for out_buffer

Returns:

The size of the copied string, including the final NUL character. If the buffer is too small, returns NETPLAN_BUFFER_TOO_SMALL instead.

Get a reference to a linked NetplanNetDefinition for a given netdef.

This defines the parent-child relationship between bridged interfaces.

Parameters:
Returns:

Reference to the parent of netdef

Get a reference to a linked NetplanNetDefinition for a given netdef.

This defines the parent-child relationship between bonded interfaces.

Parameters:
Returns:

Reference to the parent of netdef

Get a reference to a linked NetplanNetDefinition for a given netdef.

This defines the peer relationship between veth or Open vSwitch interfaces.

Parameters:
Returns:

Reference to the peer of netdef

Get a reference to a linked NetplanNetDefinition for a given netdef.

This defines the parent-child relationship of VLAN interfaces.

Parameters:
Returns:

Reference to the parent of netdef

Get a reference to a linked NetplanNetDefinition for a given netdef.

This defines the parent-child relationship of SR-IOV virtual functions.

Parameters:
Returns:

Reference to the physical function of netdef

Get a reference to a linked NetplanNetDefinition for a given netdef.

This defines the parent-child relationship of VRF interfaces.

Parameters:
Returns:

Reference to the parent of netdef

ssize_t netplan_netdef_get_set_name(const NetplanNetDefinition *netdef, char *out_buffer, size_t out_buffer_size)

Get the set-name setting of a given NetplanNetDefinition.

Copies a NUL-terminated string into a sized out_buffer. If the buffer is too small, its content is not NUL-terminated.

Note

This is unrelated to the match.name setting.

Parameters:
  • netdef -- [in] The NetplanNetDefinition to query

  • out_buffer -- [out] A pre-allocated buffer to write the output string into, owned by the caller

  • out_buffer_size -- [in] The maximum size (in bytes) available for out_buffer

Returns:

The size of the copied string, including the final NUL character. If the buffer is too small, returns NETPLAN_BUFFER_TOO_SMALL instead.

gboolean netplan_netdef_has_match(const NetplanNetDefinition *netdef)

Query a NetplanNetDefinition for a match stanza in its configuration.

In the absence of a match stanza, the Netplan ID can be considered to be the interface name of a single interface. Otherwise, it could match multiple interfaces.

Parameters:
Returns:

Indication if netdef uses custom interface matching rules

gboolean netplan_netdef_match_interface(const NetplanNetDefinition *netdef, const char *name, const char *mac, const char *driver_name)

Check if a NetplanNetDefinition matches on given interface parameters.

If defined in netdef, calculate if it would match on given mac AND name AND driver_name parameters.

Note

Matching a single driver out of a list given in the YAML configuration is enough to satisfy the condition.

Parameters:
  • netdef -- [in] The NetplanNetDefinition to query

  • name -- [in] The interface name match, optionally using shell wildcard patterns (fnmatch())

  • mac -- [in] The exact, case insensitive match on the interface MAC address

  • driver_name -- [in] The driver match, optionally using shell wildcard patterns (fnmatch())

Returns:

Indication if netdef uses custom interface matching rules

gboolean netplan_netdef_get_dhcp4(const NetplanNetDefinition *netdef)

Query a NetplanNetDefinition for the value of its dhcp4 setting.

Parameters:
Returns:

Indication if netdef is configured to enable DHCP for IPv4

gboolean netplan_netdef_get_dhcp6(const NetplanNetDefinition *netdef)

Query a NetplanNetDefinition for the value of its dhcp6 setting.

Parameters:
Returns:

Indication if netdef is configured to enable DHCP for IPv6

Query a NetplanNetDefinition for the value of its link-local setting for IPv4.

Parameters:
Returns:

Indication if netdef is configured to enable the link-local address for IPv4

Query a NetplanNetDefinition for the value of its link-local setting for IPv6.

Parameters:
Returns:

Indication if netdef is configured to enable the link-local address for IPv6

ssize_t netplan_netdef_get_macaddress(const NetplanNetDefinition *netdef, char *out_buffer, size_t out_buffer_size)

Get the macaddress setting of a given NetplanNetDefinition.

Copies a NUL-terminated string into a sized out_buffer. If the buffer is too small, its content is not NUL-terminated.

Note

This is unrelated to the match.macaddress setting.

Parameters:
  • netdef -- [in] The NetplanNetDefinition to query

  • out_buffer -- [out] A pre-allocated buffer to write the output string into, owned by the caller

  • out_buffer_size -- [in] The maximum size (in bytes) available for out_buffer

Returns:

The size of the copied string, including the final NUL character. If the buffer is too small, returns NETPLAN_BUFFER_TOO_SMALL instead.