libnl: IPv4 Link Module

libnl 3.10.0

Functions
IPv4 Link Module
Routing Library (libnl-route) » Links (Interfaces) » Link Modules API

## Functions
const char * | rtnl_link_inet_devconf2str (int type, char *buf, size_t len)
int | rtnl_link_inet_str2devconf (const char *name)
int | rtnl_link_inet_get_conf (struct rtnl_link *link, const unsigned int cfgid, uint32_t *res)
| Get value of a ipv4 link configuration setting.
int | rtnl_link_inet_set_conf (struct rtnl_link *link, const unsigned int cfgid, uint32_t value)
| Change value of a ipv4 link configuration setting.

## Detailed Description

Implementation of IPv4 specific link attributes

Example: Reading the value of IPV4_DEVCONF_FORWARDING
  struct nl_cache *cache;
  struct rtnl_link *link;
  uint32_t value;
  // Allocate a link cache
  rtnl_link_alloc_cache(sock, AF_UNSPEC, &cache);
  // Search for the link we wish to see the value from
  link = rtnl_link_get_by_name(cache, "eth0");
  // Read the value of the setting IPV4_DEVCONF_FORWARDING
  if (rtnl_link_inet_get_conf(link, IPV4_DEVCONF_FORWARDING, &value) < 0)
  // Error: Unable to read config setting
  printf("forwarding is %s\n", value ? "enabled" : "disabled");
  rtnl_link_inet_get_conf
  int rtnl_link_inet_get_conf(struct rtnl_link *link, const unsigned int cfgid, uint32_t *res)
  Get value of a ipv4 link configuration setting.
  Definition inet.c:236
  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.
  Definition link.c:1347
  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.
  Definition link.c:1294
  rtnl_link
  Link object.
  Definition nl-route.h:29

Example: Changing the value of IPV4_DEVCONF_FOWARDING
  //
  // ... Continueing from the previous example ...
  //
  struct rtnl_link *new;
  // Allocate a new link to store the changes we wish to make.
  new = rtnl_link_alloc();
  // Set IPV4_DEVCONF_FORWARDING to '1'
  rtnl_link_inet_set_conf(new, IPV4_DEVCONF_FORWARDING, 1);
  // Send the change request to the kernel.
  rtnl_link_change(sock, link, new, 0);
  rtnl_link_inet_set_conf
  int rtnl_link_inet_set_conf(struct rtnl_link *link, const unsigned int cfgid, uint32_t value)
  Change value of a ipv4 link configuration setting.
  Definition inet.c:266
  rtnl_link_alloc
  struct rtnl_link * rtnl_link_alloc(void)
  Allocate link object.
  Definition link.c:1920
  rtnl_link_change
  int rtnl_link_change(struct nl_sock *sk, struct rtnl_link *orig, struct rtnl_link *changes, int flags)
  Change link.
  Definition link.c:1797

## Function Documentation

## ◆ rtnl_link_inet_devconf2str()

const char * rtnl_link_inet_devconf2str | ( | int | type,
|  | char * | buf,
|  | size_t | len )

Definition at line 173 of file inet.c.

## ◆ rtnl_link_inet_str2devconf()

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

Definition at line 179 of file inet.c.

## ◆ rtnl_link_inet_get_conf()

int rtnl_link_inet_get_conf | ( | struct rtnl_link * | link,
|  | const unsigned int | cfgid,
|  | uint32_t * | res )

Get value of a ipv4 link configuration setting.

Parameters

  link | Link object
  cfgid | Configuration identifier
  res | Result pointer

Stores the value of the specified configuration setting in the provided result pointer.

Returns
  0 on success or a negative error code.
  -NLE_RANGE cfgid is out of range, 1..IPV4_DEVCONF_MAX
  -NLE_NOATTR configuration setting not available
  -NLE_INVAL cfgid not set. If the link was received via netlink, it means that the cfgid is not supported.

Definition at line 236 of file inet.c.

References rtnl_link_af_data().

Here is the call graph for this function:

## ◆ rtnl_link_inet_set_conf()

int rtnl_link_inet_set_conf | ( | struct rtnl_link * | link,
|  | const unsigned int | cfgid,
|  | uint32_t | value )

Change value of a ipv4 link configuration setting.

Parameters

  link | Link object
  cfgid | Configuration identifier
  value | New value

Changes the value in the per link ipv4 configuration array.

Returns
  0 on success or a negative error code.
  -NLE_RANGE cfgid is out of range, 1..IPV4_DEVCONF_MAX
  -NLE_NOMEM memory allocation failed

Definition at line 266 of file inet.c.

References rtnl_link_af_alloc().

Here is the call graph for this function: