Lely core libraries  2.3.4
rtnl.h File Reference

This is the internal header file of the rtnetlink declarations. More...

#include "io.h"
#include <linux/rtnetlink.h>
Include dependency graph for rtnl.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define RTA_TAIL(rta)    (struct rtattr *)((char *)(rta) + RTA_ALIGN((rta)->rta_len))
 Returns the address of the next attribute. More...
 

Typedefs

typedef int io_rtnl_newlink_func_t(struct ifinfomsg *ifi, struct rtattr *rta, unsigned short rtalen, void *data)
 The type of a callback function invoked when an RTM_NEWLINK response is received. More...
 

Functions

int io_rtnl_socket (__u32 pid, __u32 groups)
 Opens an rtnetlink socket. More...
 
int io_rtnl_newlink (int fd, __u32 seq, __u32 pid, int ifi_index, unsigned int ifi_flags, struct rtattr *rta, unsigned short rtalen)
 Sends an RTM_NEWLINK request and waits until the acknowledgment is received. More...
 
int io_rtnl_getlink (int fd, __u32 seq, __u32 pid, io_rtnl_newlink_func_t *func, void *data)
 Sends an RTM_GETLINK request and invokes the specified callback function for each received network interface. More...
 
int io_rtnl_getattr (int fd, __u32 seq, __u32 pid, int ifi_index, unsigned int *pifi_flags, unsigned short type, void *data, unsigned short payload)
 Invokes io_rtnl_getlink() and retrieves a single attribute of the specified network interface. More...
 
int io_rtnl_setattr (int fd, __u32 seq, __u32 pid, int ifi_index, unsigned int ifi_flags, unsigned short type, const void *data, unsigned short payload)
 Invokes io_rtnl_newlink() to set at most one attribute of the specified network interface. More...
 
static struct rtattr * io_rta_find (struct rtattr *rta, unsigned short len, unsigned short type)
 Finds an attribute in a list of attributes. More...
 

Detailed Description

This is the internal header file of the rtnetlink declarations.

Author
J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file rtnl.h.

Macro Definition Documentation

◆ RTA_TAIL

#define RTA_TAIL (   rta)     (struct rtattr *)((char *)(rta) + RTA_ALIGN((rta)->rta_len))

Returns the address of the next attribute.

This macro is useful for constructing a list of attributes, since RTA_NEXT() only works for complete lists.

Definition at line 35 of file rtnl.h.

Typedef Documentation

◆ io_rtnl_newlink_func_t

typedef int io_rtnl_newlink_func_t(struct ifinfomsg *ifi, struct rtattr *rta, unsigned short rtalen, void *data)

The type of a callback function invoked when an RTM_NEWLINK response is received.

Parameters
ifia pointer to an ifinfomsg struct describing the network interface.
rtaa pointer to a list of attributes.
rtalenthe length (in bytes) of the attribute list.
dataa pointer to used-specified data.
Returns
0 on success, or -1 on error.

Definition at line 54 of file rtnl.h.

Function Documentation

◆ io_rtnl_socket()

int io_rtnl_socket ( __u32  pid,
__u32  groups 
)

Opens an rtnetlink socket.

Parameters
pida unique id identifying the netlink socket. This can be equal to the process id only for at most one socket. If pid is 0, the kernel assigns a unique id.
groupsa bitmask specifying to which of the 32 multicast groups the socket should listen. Sending or receiving multicast messages requires the CAP_NET_ADMIN capability.
Returns
a socket file descriptor, or -1 on error. In the latter case, the error number is stored in errno.

Definition at line 55 of file rtnl.c.

◆ io_rtnl_newlink()

int io_rtnl_newlink ( int  fd,
__u32  seq,
__u32  pid,
int  ifi_index,
unsigned int  ifi_flags,
struct rtattr *  rta,
unsigned short  rtalen 
)

Sends an RTM_NEWLINK request and waits until the acknowledgment is received.

This operation requires the CAP_NET_ADMIN capability.

Parameters
fdan rtnetlink socket file descriptor.
seqthe sequence number identifying the request (can be 0).
pidthe (process) ID identifying the sender (can be 0).
ifi_indexthe interface index.
ifi_flagsthe active flag word of the device.
rtaa pointer to a list of attributes (can be NULL).
rtalenthe length of the attribute list (in bytes).
Returns
0 on success, or -1 on error. In the latter case, the error number is stored in errno.

Definition at line 84 of file rtnl.c.

◆ io_rtnl_getlink()

int io_rtnl_getlink ( int  fd,
__u32  seq,
__u32  pid,
io_rtnl_newlink_func_t func,
void *  data 
)

Sends an RTM_GETLINK request and invokes the specified callback function for each received network interface.

Parameters
fdan rtnetlink socket file descriptor.
seqthe sequence number identifying the request (can be 0).
pidthe (process) ID identifying the sender (can be 0).
funca pointer to the function to be invoked for each network interface.
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to func.
Returns
0 on success, or -1 on error. In the latter case, the error number is stored in errno.

Definition at line 97 of file rtnl.c.

◆ io_rtnl_getattr()

int io_rtnl_getattr ( int  fd,
__u32  seq,
__u32  pid,
int  ifi_index,
unsigned int *  pifi_flags,
unsigned short  type,
void *  data,
unsigned short  payload 
)

Invokes io_rtnl_getlink() and retrieves a single attribute of the specified network interface.

Parameters
fdan rtnetlink socket file descriptor.
seqthe sequence number identifying the request (can be 0).
pidthe (process) ID identifying the sender (can be 0).
ifi_indexthe interface index.
pifi_flagsthe address at which to store the active flag word of the device (can be NULL).
typethe type of the attribute.
datathe address at which to store the payload of the attribute.
payloadthe size of the buffer at data (in bytes).
Returns
length of the payload (in bytes) of the attribute on success, or -1 on error. In the latter case, the error number is stored in errno. Note that the result can be larger than payload, but at most payload bytes will be copied to data.
See also
io_rtnl_setattr()

Definition at line 106 of file rtnl.c.

◆ io_rtnl_setattr()

int io_rtnl_setattr ( int  fd,
__u32  seq,
__u32  pid,
int  ifi_index,
unsigned int  ifi_flags,
unsigned short  type,
const void *  data,
unsigned short  payload 
)

Invokes io_rtnl_newlink() to set at most one attribute of the specified network interface.

This operation requires the CAP_NET_ADMIN capability.

Parameters
fdan rtnetlink socket file descriptor.
seqthe sequence number identifying the request (can be 0).
pidthe (process) ID identifying the sender (can be 0).
ifi_indexthe interface index.
ifi_flagsthe active flag word of the device.
typethe type of the attribute.
dataa pointer to the payload of the attribute (can be NULL).
payloadthe length of the payload (in bytes).
Returns
0 on success, or -1 on error. In the latter case, the error number is stored in errno.
See also
io_rtnl_getattr()

Definition at line 179 of file rtnl.c.

◆ io_rta_find()

static struct rtattr * io_rta_find ( struct rtattr *  rta,
unsigned short  len,
unsigned short  type 
)
inlinestatic

Finds an attribute in a list of attributes.

Parameters
rtaa pointer to a list of attributes.
lenthe length of the attribute list (in bytes).
typethe type of the attribute to be found.
Returns
a pointer to the attribute if found, or NULL if not.

Definition at line 169 of file rtnl.h.