The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
netif.h File Reference

network interfaces: the devices that send and receive frames. More...

Go to the source code of this file.

Data Structures

struct  netif
struct  kifreq_t

Macros

#define NETIF_MAX   4
#define NETIF_NAME_MAX   8
#define ETH_ADDR_LEN   6
#define ETH_MTU   1500
#define SIOCGIFFLAGS   0x8913
#define SIOCSIFFLAGS   0x8914
#define SIOCGIFADDR   0x8915
#define SIOCSIFADDR   0x8916
#define SIOCGIFBRDADDR   0x8919
#define SIOCGIFNETMASK   0x891B
#define SIOCSIFNETMASK   0x891C
#define SIOCGIFMTU   0x8921
#define SIOCGIFHWADDR   0x8927
#define SIOCGIFGATEWAY   0x89F0
#define SIOCSIFGATEWAY   0x89F1
#define IFF_UP   0x0001
#define IFF_BROADCAST   0x0002
#define IFF_LOOPBACK   0x0008
#define IFF_RUNNING   0x0040
#define IFNAMSIZ   16

Typedefs

typedef bool(*) netif_send_fn(struct netif *netif, const void *frame, uint32_t length)
 send one frame (for Ethernet: from the destination address to the end of the payload, no checksum; for loopback: an IPv4 packet).
typedef struct netif netif_t

Functions

void net_init (void)
 set up the network layer and the loopback interface (lo).
uint32_t net_lock (void)
 take and release the network lock.
void net_unlock (uint32_t flags)
void net_wait (wait_queue_t *wq)
 sleep on a wait queue with net_lock held (interruptibly): the lock is let go while the process sleeps and held again on return.
netif_t * netif_register (const char *prefix, const uint8_t mac[ETH_ADDR_LEN], uint32_t mtu, netif_send_fn send, void *driver)
 add an interface.
void netif_receive (netif_t *netif, const void *frame, uint32_t length)
 a frame from the device (called with net_lock held, often from an interrupt).
bool netif_send (netif_t *netif, const void *frame, uint32_t length)
 send a frame on an interface and count it (net_lock held).
netif_t * netif_at (uint32_t index)
 the interfaces, for /proc/net and the configuration calls.
netif_t * netif_find (const char *name)
 the interface with this name, or NULL.
int32_t netif_ioctl (uint32_t request, void *arg)
 an interface ioctl (from a socket).

Detailed Description

network interfaces: the devices that send and receive frames.

a driver registers an interface with a send function, and gives each frame it receives to netif_receive, which gives it to Ethernet (or, on the loopback interface, which has no Ethernet header, to IPv4).

locking: all network state is under one spinlock (net_lock, irqsave). frames are received in the device's interrupt handler, and the stack handles them there, with the lock held. on one CPU that is simple and safe: a syscall that sends holds the lock with interrupts off, so the receive path cannot run at the same time.

Macro Definition Documentation

◆ NETIF_MAX

#define NETIF_MAX   4

◆ NETIF_NAME_MAX

#define NETIF_NAME_MAX   8

◆ ETH_ADDR_LEN

#define ETH_ADDR_LEN   6

◆ ETH_MTU

#define ETH_MTU   1500

◆ SIOCGIFFLAGS

#define SIOCGIFFLAGS   0x8913

◆ SIOCSIFFLAGS

#define SIOCSIFFLAGS   0x8914

◆ SIOCGIFADDR

#define SIOCGIFADDR   0x8915

◆ SIOCSIFADDR

#define SIOCSIFADDR   0x8916

◆ SIOCGIFBRDADDR

#define SIOCGIFBRDADDR   0x8919

◆ SIOCGIFNETMASK

#define SIOCGIFNETMASK   0x891B

◆ SIOCSIFNETMASK

#define SIOCSIFNETMASK   0x891C

◆ SIOCGIFMTU

#define SIOCGIFMTU   0x8921

◆ SIOCGIFHWADDR

#define SIOCGIFHWADDR   0x8927

◆ SIOCGIFGATEWAY

#define SIOCGIFGATEWAY   0x89F0

◆ SIOCSIFGATEWAY

#define SIOCSIFGATEWAY   0x89F1

◆ IFF_UP

#define IFF_UP   0x0001

◆ IFF_BROADCAST

#define IFF_BROADCAST   0x0002

◆ IFF_LOOPBACK

#define IFF_LOOPBACK   0x0008

◆ IFF_RUNNING

#define IFF_RUNNING   0x0040

◆ IFNAMSIZ

#define IFNAMSIZ   16

Typedef Documentation

◆ netif_send_fn

typedef bool(*) netif_send_fn(struct netif *netif, const void *frame, uint32_t length)

send one frame (for Ethernet: from the destination address to the end of the payload, no checksum; for loopback: an IPv4 packet).

called with net_lock held.

Returns
false if the device has no room (the frame is dropped).

◆ netif_t

typedef struct netif netif_t

Function Documentation

◆ net_init()

void net_init ( void )

set up the network layer and the loopback interface (lo).

◆ net_lock()

uint32_t net_lock ( void )

take and release the network lock.

◆ net_unlock()

void net_unlock ( uint32_t flags)

◆ net_wait()

void net_wait ( wait_queue_t * wq)

sleep on a wait queue with net_lock held (interruptibly): the lock is let go while the process sleeps and held again on return.

the caller checks its condition and signal_pending in a loop.

◆ netif_register()

netif_t * netif_register ( const char * prefix,
const uint8_t mac[ETH_ADDR_LEN],
uint32_t mtu,
netif_send_fn send,
void * driver )

add an interface.

the name is made from prefix and a number (eth0).

Returns
the interface, or NULL if there are already NETIF_MAX.

◆ netif_receive()

void netif_receive ( netif_t * netif,
const void * frame,
uint32_t length )

a frame from the device (called with net_lock held, often from an interrupt).

the data is only valid during the call.

◆ netif_send()

bool netif_send ( netif_t * netif,
const void * frame,
uint32_t length )

send a frame on an interface and count it (net_lock held).

◆ netif_at()

netif_t * netif_at ( uint32_t index)

the interfaces, for /proc/net and the configuration calls.

Returns
NULL after the last one.

◆ netif_find()

netif_t * netif_find ( const char * name)

the interface with this name, or NULL.

◆ netif_ioctl()

int32_t netif_ioctl ( uint32_t request,
void * arg )

an interface ioctl (from a socket).

Parameters
arga struct ifreq in user memory.
Returns
0, or -ENODEV (no interface with the name), -EPERM, -EINVAL, -EFAULT, or -ENOTTY for another request.