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

the interface table and the loopback interface (see netif.h). More...

#include "netif.h"
#include "common/memory.h"
#include "common/string.h"
#include "ethernet.h"
#include "ipv4.h"
#include "tcp.h"
#include "kernel/errno.h"
#include "kernel/memory/heap.h"
#include "kernel/process/process.h"
#include "kernel/usermode/uaccess.h"
#include "kernel/sync/spinlock.h"
#include "kernel/sync/wait_queue.h"

Macros

#define LOOPBACK_QUEUE   16
#define AF_INET_K   2
#define ARPHRD_ETHER   1
#define ARPHRD_LOOPBACK   772

Functions

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.
void net_init (void)
 set up the network layer and the loopback interface (lo).
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

the interface table and the loopback interface (see netif.h).

Macro Definition Documentation

◆ LOOPBACK_QUEUE

#define LOOPBACK_QUEUE   16

◆ AF_INET_K

#define AF_INET_K   2

◆ ARPHRD_ETHER

#define ARPHRD_ETHER   1

◆ ARPHRD_LOOPBACK

#define ARPHRD_LOOPBACK   772

Function Documentation

◆ 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.

◆ net_init()

void net_init ( void )

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

◆ 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.