CNDP  22.08.0
cnet_netif.h File Reference
#include <net/if.h>
#include <cne_atomic.h>
#include <pktdev.h>
#include <cne_inet.h>
#include <stddef.h>
#include <stdint.h>
#include "cne_common.h"
#include "cne_log.h"
#include "cne_lport.h"
#include "cne_vec.h"
#include "cnet_const.h"
#include "cnet_stk.h"
#include "mempool.h"
#include "pktmbuf.h"

Go to the source code of this file.

Macros

#define _IFF_UP   0x00000001
 
#define _IFF_BROADCAST   0x00000002
 
#define _IFF_DEBUG   0x00000004
 
#define _IFF_LOOPBACK   0x00000008
 
#define _IFF_POINTOPOINT   0x00000010
 
#define _IFF_SMART   0x00000020
 
#define _IFF_RUNNING   0x00000040
 
#define _IFF_NOARP   0x00000080
 
#define _IFF_PROMISC   0x00000100
 
#define _IFF_ALLMULTI   0x00000200
 
#define _IFF_OACTIVE   0x00000400
 
#define _IFF_SIMPLEX   0x00000800
 
#define _IFF_LINK0   0x00001000
 
#define _IFF_LINK1   0x00002000
 
#define _IFF_LINK2   0x00004000
 
#define _IFF_MULTICAST   0x00008000
 
#define _IFF_NOTRAILERS   0x00020000
 
#define _IFF_INET_UP   0x00040000
 
#define _IFF_INET6_UP   0x00080000
 
#define _IFF_RARP   0x00100000
 
#define _IFF_DONT_FORWARD   0x00200000
 

Functions

static int cnet_ipv4_broadcast (struct netif *netif, struct in_addr *ip)
 
static struct netif * cnet_netif_from_index (uint8_t idx)
 
static struct netif * cnet_netif_match_subnet (struct in_addr *ipaddr)
 
static void cnet_netif_free (struct netif *netif)
 
static struct netif * cnet_netif_alloc (uint16_t lpid)
 
static int cnet_netif_get_flags (struct netif *netif, uint32_t *flags)
 
CNDP_API int cnet_netif_register (uint16_t lpid, char *ifname, char *netdev)
 Register lport, ifname and netdev to create a netif structure. More...
 
CNDP_API int cnet_netif_attach_ports (struct cnet *cnet)
 Attach ports to CNET and the netif structures. More...
 
CNDP_API struct netif * cnet_netif_from_name (const char *name, int typ)
 Locate the netif for the given interface name. More...
 
CNDP_API int cnet_netif_set_mtu (struct netif *netif, uint16_t mtu)
 Set the MTU for a given netif structure. More...
 
CNDP_API int cnet_netif_foreach (int(*func)(struct netif *netif, void *arg), void *arg)
 look over all netif structures calling the specified function More...
 
CNDP_API struct inet4_addr * cnet_ipv4_ipaddr_find (struct netif *netif, struct in_addr *ip)
 Find the given IPv4 address in a given netif structure. More...
 
CNDP_API int cnet_ipv4_ipaddr_delete (struct netif *netif, struct in_addr *ip)
 Delete the given IPv4 address from the given netif structure. More...
 
CNDP_API int cnet_ipv4_ipaddr_add (struct netif *netif, struct inet4_addr *ip)
 Add a new IPv4 address to the given netif structure. More...
 
CNDP_API int cnet_netif_set_flags (struct netif *netif, uint32_t flags)
 Add flags or set the flags to a netif structure. More...
 
CNDP_API struct netif * cnet_netif_find_by_name (char *ifname)
 Find the netif structure for the given interface name. More...
 
CNDP_API struct netif * cnet_netif_find_by_ifindex (int ifindex)
 Locate the netif structure by the ifindex value. More...
 
CNDP_API struct netif * cnet_netif_find_by_netdev (char *netdev_name)
 Find the netif structure by the netdev name. More...
 
CNDP_API struct netif * cnet_netif_find_by_lport (int lport)
 Find the netif structure by the lport id. More...
 
CNDP_API int cnet_is_ifname_valid (char *ifname)
 Is the ifname a valid interface name. More...
 
CNDP_API int cnet_is_netdev_valid (char *netdev_name)
 Is the netdev name a valid netdev. More...
 
CNDP_API int cnet_is_ifindex_valid (int ifindex)
 Is the ifindex valid interface index. More...
 

Detailed Description

CNET Network Interface routines and constants.

Definition in file cnet_netif.h.

Macro Definition Documentation

◆ _IFF_UP

#define _IFF_UP   0x00000001

interface link is up

Definition at line 91 of file cnet_netif.h.

◆ _IFF_BROADCAST

#define _IFF_BROADCAST   0x00000002

broadcast address valid

Definition at line 92 of file cnet_netif.h.

◆ _IFF_DEBUG

#define _IFF_DEBUG   0x00000004

turn on debugging

Definition at line 93 of file cnet_netif.h.

◆ _IFF_LOOPBACK

#define _IFF_LOOPBACK   0x00000008

is a loopback net

Definition at line 94 of file cnet_netif.h.

◆ _IFF_POINTOPOINT

#define _IFF_POINTOPOINT   0x00000010

interface is p2p link

Definition at line 95 of file cnet_netif.h.

◆ _IFF_SMART

#define _IFF_SMART   0x00000020

interface manages own routes

Definition at line 96 of file cnet_netif.h.

◆ _IFF_RUNNING

#define _IFF_RUNNING   0x00000040

resources allocated

Definition at line 97 of file cnet_netif.h.

◆ _IFF_NOARP

#define _IFF_NOARP   0x00000080

no address resolution protocol

Definition at line 98 of file cnet_netif.h.

◆ _IFF_PROMISC

#define _IFF_PROMISC   0x00000100

receive all packets

Definition at line 99 of file cnet_netif.h.

◆ _IFF_ALLMULTI

#define _IFF_ALLMULTI   0x00000200

receive all multicast packets

Definition at line 100 of file cnet_netif.h.

◆ _IFF_OACTIVE

#define _IFF_OACTIVE   0x00000400

transmission in progress

Definition at line 101 of file cnet_netif.h.

◆ _IFF_SIMPLEX

#define _IFF_SIMPLEX   0x00000800

can't hear own transmissions

Definition at line 102 of file cnet_netif.h.

◆ _IFF_LINK0

#define _IFF_LINK0   0x00001000

forwarding disabled

Definition at line 103 of file cnet_netif.h.

◆ _IFF_LINK1

#define _IFF_LINK1   0x00002000

per link layer defined bit

Definition at line 104 of file cnet_netif.h.

◆ _IFF_LINK2

#define _IFF_LINK2   0x00004000

per link layer defined bit

Definition at line 105 of file cnet_netif.h.

◆ _IFF_MULTICAST

#define _IFF_MULTICAST   0x00008000

supports multicast

Definition at line 106 of file cnet_netif.h.

◆ _IFF_NOTRAILERS

#define _IFF_NOTRAILERS   0x00020000

avoid use of trailers

Definition at line 107 of file cnet_netif.h.

◆ _IFF_INET_UP

#define _IFF_INET_UP   0x00040000

interface is up for ipv4

Definition at line 108 of file cnet_netif.h.

◆ _IFF_INET6_UP

#define _IFF_INET6_UP   0x00080000

interface is up for ipv6

Definition at line 109 of file cnet_netif.h.

◆ _IFF_RARP

#define _IFF_RARP   0x00100000

RARP enabled on this interface

Definition at line 110 of file cnet_netif.h.

◆ _IFF_DONT_FORWARD

#define _IFF_DONT_FORWARD   0x00200000

Not allowed to forward packets

Definition at line 111 of file cnet_netif.h.

Function Documentation

◆ cnet_ipv4_broadcast()

static int cnet_ipv4_broadcast ( struct netif *  netif,
struct in_addr *  ip 
)
inlinestatic

Check if an IP address matches one of the netif subnets.

Definition at line 125 of file cnet_netif.h.

◆ cnet_netif_from_index()

static struct netif* cnet_netif_from_index ( uint8_t  idx)
inlinestatic

Using the netif index return the netif structure pointer.

Definition at line 171 of file cnet_netif.h.

◆ cnet_netif_match_subnet()

static struct netif* cnet_netif_match_subnet ( struct in_addr *  ipaddr)
inlinestatic

Locate the closest matching IP address in all of the netif structures.

Definition at line 180 of file cnet_netif.h.

◆ cnet_netif_free()

static void cnet_netif_free ( struct netif *  netif)
inlinestatic

Free the given netif pointer back to the netif free list.

Definition at line 195 of file cnet_netif.h.

◆ cnet_netif_alloc()

static struct netif* cnet_netif_alloc ( uint16_t  lpid)
inlinestatic

Allocate a netif structure and return the pointer.

Definition at line 208 of file cnet_netif.h.

◆ cnet_netif_get_flags()

static int cnet_netif_get_flags ( struct netif *  netif,
uint32_t *  flags 
)
inlinestatic

Get the flags for the given netif structure pointer.

Definition at line 228 of file cnet_netif.h.

◆ cnet_netif_register()

CNDP_API int cnet_netif_register ( uint16_t  lpid,
char *  ifname,
char *  netdev 
)

Register lport, ifname and netdev to create a netif structure.

Parameters
lpidThe lport value to register
ifnameThe interface name
netdevThe netdev name to assign to the netif structure
Returns
-1 on failure or 0 on success
Examples
examples/cnet-graph/parse-args.c, and examples/cnet-quic/parse-args.c.

◆ cnet_netif_attach_ports()

CNDP_API int cnet_netif_attach_ports ( struct cnet *  cnet)

Attach ports to CNET and the netif structures.

Parameters
cnetThe CNET structure pointer
Returns
-1 on failure or 0 on success

◆ cnet_netif_from_name()

CNDP_API struct netif* cnet_netif_from_name ( const char *  name,
int  typ 
)

Locate the netif for the given interface name.

Parameters
nameThe name of the interface to find
typThe type of netif to find.
Returns
NULL on error or pointer to netif structure

◆ cnet_netif_set_mtu()

CNDP_API int cnet_netif_set_mtu ( struct netif *  netif,
uint16_t  mtu 
)

Set the MTU for a given netif structure.

Parameters
netifThe netif structure pointer
mtuThe MTU value to set
Returns
-1 on error or 0 on success

◆ cnet_netif_foreach()

CNDP_API int cnet_netif_foreach ( int(*)(struct netif *netif, void *arg)  func,
void *  arg 
)

look over all netif structures calling the specified function

Parameters
funcThe function to call
argThe argument to pass to the function
Returns
-1 on error or 0 on success

◆ cnet_ipv4_ipaddr_find()

CNDP_API struct inet4_addr* cnet_ipv4_ipaddr_find ( struct netif *  netif,
struct in_addr *  ip 
)

Find the given IPv4 address in a given netif structure.

Parameters
netifThe netif structure to search for the giben IPv4 address
ipThe IPv4 address to search
Returns
NULL on error or pointer to inet4_addr structure

◆ cnet_ipv4_ipaddr_delete()

CNDP_API int cnet_ipv4_ipaddr_delete ( struct netif *  netif,
struct in_addr *  ip 
)

Delete the given IPv4 address from the given netif structure.

Parameters
netifThe netif structure to search for the giben IPv4 address
ipThe IPv4 address to search
Returns
-1 on error or 0 on success

◆ cnet_ipv4_ipaddr_add()

CNDP_API int cnet_ipv4_ipaddr_add ( struct netif *  netif,
struct inet4_addr *  ip 
)

Add a new IPv4 address to the given netif structure.

Parameters
netifThe netif structure to search for the giben IPv4 address
ipThe IPv4 address to search
Returns
-1 on error or 0 on success

◆ cnet_netif_set_flags()

CNDP_API int cnet_netif_set_flags ( struct netif *  netif,
uint32_t  flags 
)

Add flags or set the flags to a netif structure.

Parameters
netifThe netif structure to search for the giben IPv4 address
flagsThe flags to set in the netif structure
Returns
-1 on error or 0 on success

◆ cnet_netif_find_by_name()

CNDP_API struct netif* cnet_netif_find_by_name ( char *  ifname)

Find the netif structure for the given interface name.

Parameters
ifnameThe interface name to search for in the system
Returns
NULL on error or pointer to netif structure

◆ cnet_netif_find_by_ifindex()

CNDP_API struct netif* cnet_netif_find_by_ifindex ( int  ifindex)

Locate the netif structure by the ifindex value.

Parameters
ifindexThe ifindex value for the netif structure
Returns
NULL on error or pointer to netif structure

◆ cnet_netif_find_by_netdev()

CNDP_API struct netif* cnet_netif_find_by_netdev ( char *  netdev_name)

Find the netif structure by the netdev name.

Parameters
netdev_nameThe netdev name to search for in system
Returns
NULL on error or pointer to netif structure

◆ cnet_netif_find_by_lport()

CNDP_API struct netif* cnet_netif_find_by_lport ( int  lport)

Find the netif structure by the lport id.

Parameters
lportThe lport id value to help locate the netif pointer.
Returns
NULL on error or pointer to netif structure.

◆ cnet_is_ifname_valid()

CNDP_API int cnet_is_ifname_valid ( char *  ifname)

Is the ifname a valid interface name.

Parameters
ifnameLocate and see if the interface name is known
Returns
0 on not found or 1 on found

◆ cnet_is_netdev_valid()

CNDP_API int cnet_is_netdev_valid ( char *  netdev_name)

Is the netdev name a valid netdev.

Parameters
netdev_nameLocate and see if the netdev name is known
Returns
0 on not found or 1 on found

◆ cnet_is_ifindex_valid()

CNDP_API int cnet_is_ifindex_valid ( int  ifindex)

Is the ifindex valid interface index.

Parameters
ifindexThe ifindex to validate
Returns
0 on not found or 1 on found