|
ginnOS
The reference: libc, the libraries and the kernel
|
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). | |
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.
| #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 |
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.
| 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.
the caller checks its condition and signal_pending in a loop.
| 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).
a frame from the device (called with net_lock held, often from an interrupt).
the data is only valid during the call.
send a frame on an interface and count it (net_lock held).
the interfaces, for /proc/net and the configuration calls.
| netif_t * netif_find | ( | const char * | name | ) |
the interface with this name, or NULL.