netfilter
firewalling, NAT, and packet mangling for linux
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
iftable.c File Reference
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <assert.h>
#include <linux/netdevice.h>
#include <libnfnetlink/libnfnetlink.h>
#include "rtnl.h"
#include "linux_list.h"
Include dependency graph for iftable.c:

Data Structures

struct  ifindex_node
 
struct  nlif_handle
 

Functions

int nlif_index2name (struct nlif_handle *h, unsigned int index, char *name)
 Get the name for an ifindex. More...
 
int nlif_get_ifflags (const struct nlif_handle *h, unsigned int index, unsigned int *flags)
 Get the flags for an ifindex. More...
 
struct nlif_handlenlif_open (void)
 Initialize interface table. More...
 
void nlif_close (struct nlif_handle *h)
 Destructor of interface table. More...
 
int nlif_catch (struct nlif_handle *h)
 Receive message from netlink and update interface table. More...
 
int nlif_query (struct nlif_handle *h)
 nlif_query - request a dump of interfaces available in the system : pointer to a valid nlif_handler More...
 
int nlif_fd (struct nlif_handle *h)
 Returns socket descriptor for the netlink socket. More...
 

Function Documentation

int nlif_catch ( struct nlif_handle h)

Receive message from netlink and update interface table.

Parameters
nlif_handleA pointer to a nlif_handle created
Returns
0 if OK

References NULL, nlif_handle::rtnl_handle, and rtnl_receive().

Here is the call graph for this function:

void nlif_close ( struct nlif_handle h)

Destructor of interface table.

Parameters
nlif_handleA pointer to a nlif_handle created via nlif_open()

References ifindex_node::head, nlif_handle::ifadd_handler, nlif_handle::ifdel_handler, nlif_handle::ifindex_hash, list_for_each_entry_safe, NULL, rtnl_close(), nlif_handle::rtnl_handle, and rtnl_handler_unregister().

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

int nlif_fd ( struct nlif_handle h)

Returns socket descriptor for the netlink socket.

Parameters
nlif_handleA pointer to a nlif_handle created
Returns
The fd or -1 if there's an error

References NULL, rtnl_handle::rtnl_fd, and nlif_handle::rtnl_handle.

Referenced by nl_init_interface_handler().

Here is the caller graph for this function:

int nlif_get_ifflags ( const struct nlif_handle h,
unsigned int  index,
unsigned int *  flags 
)

Get the flags for an ifindex.

Parameters
nlif_handleA pointer to a nlif_handle created
indexifindex to be resolved
flagspointer to variable used to store the interface flags
Returns
-1 on error, 1 on success

References flags, ifindex_node::head, nlif_handle::ifindex_hash, list_for_each_entry, and NULL.

Referenced by main().

Here is the caller graph for this function:

int nlif_index2name ( struct nlif_handle h,
unsigned int  index,
char *  name 
)

Get the name for an ifindex.

Parameters
nlif_handleA pointer to a nlif_handle created
indexifindex to be resolved
nameinterface name, pass a buffer of IFNAMSIZ size
Returns
-1 on error, 1 on success

References ifindex_node::head, nlif_handle::ifindex_hash, list_for_each_entry, and NULL.

Referenced by main(), nfq_get_indev_name(), nfq_get_outdev_name(), nfq_get_physindev_name(), and nfq_get_physoutdev_name().

Here is the caller graph for this function:

struct nlif_handle* nlif_open ( void  )

Initialize interface table.

Initialize rtnl interface and interface table Call this before any nlif_* function

Returns
file descriptor to netlink socket

References rtnl_handler::arg, rtnl_handler::handlefn, nlif_handle::ifadd_handler, nlif_handle::ifdel_handler, nlif_handle::ifindex_hash, INIT_LIST_HEAD, rtnl_handler::nlmsg_type, NULL, RTM_DELLINK, RTM_NEWLINK, rtnl_close(), nlif_handle::rtnl_handle, rtnl_handler_register(), rtnl_handler_unregister(), and rtnl_open().

Referenced by main(), and nl_init_interface_handler().

Here is the call graph for this function:

Here is the caller graph for this function:

int nlif_query ( struct nlif_handle h)

nlif_query - request a dump of interfaces available in the system : pointer to a valid nlif_handler

References NULL, RTM_GETLINK, rtnl_dump_type(), and nlif_handle::rtnl_handle.

Referenced by main(), and nl_init_interface_handler().

Here is the call graph for this function:

Here is the caller graph for this function: