|
AquilaOS documentation
How it works, and its code
|
Network interfaces (see net/netif.h). More...
#include <core/system.h>#include <core/arch.h>#include <core/kargs.h>#include <core/module.h>#include <core/panic.h>#include <core/printk.h>#include <core/string.h>#include <net/byteorder.h>#include <net/netif.h>#include <net/inet.h>#include <sys/callout.h>#include <sys/kthread.h>#include <sys/sched.h>Go to the source code of this file.
Macros | |
| #define | NET_BUDGET 32 |
| #define | NET_BACKLOG 256 |
Functions | |
| static int | parse_ipv4 (const char **s, uint32_t *ip) |
| Parses an address "a.b.c.d" at *s into *ip, in network byte order, and moves *s past it. | |
| static void | netif_config (struct netif *netif) |
| Configures the first Ethernet interface from the kernel's command line: ip=address/prefix-length[:gateway]. | |
| static char * | mac_string (const uint8_t mac[6], char buf[18]) |
| Writes a MAC address into buf as "xx:xx:xx:xx:xx:xx" (printk() has no field widths) and returns buf. | |
| void | net_callout_set (struct callout *c, uint64_t ns, void(*fn)(void *), void *arg) |
| Sets a callout that the network's thread runs: fn(arg) is called once ns ns have passed. | |
| static void | net_main (void *arg) |
| Runs the network's thread: it takes the received frames up the stack and runs the network's callouts, then sleeps until the next frame or callout. | |
| struct netif * | netif_find (const char *name) |
| Finds an interface by its name. | |
| static void | loopback_init (void) |
| Sets up lo, the loopback interface, once. | |
| int | netif_register (struct netif *netif) |
| Registers a network interface. | |
| static int | loopback_transmit (struct netif *netif, struct netbuf *nb) |
| Sends a frame on lo: a copy of it comes back in. | |
| static int | loopback_module_init (void) |
| Sets up lo at boot, so that it is there even without a network card. | |
| static void | rx_queue (struct netif *netif, struct netbuf *nb) |
| Queues a received frame for the network's thread, and wakes it up. | |
| void | netif_input (struct netif *netif, struct netbuf *nb) |
| Hands the stack a frame that a driver received, possibly from an interrupt. | |
| void | netif_loopback (struct netif *netif, struct netbuf *nb) |
| Hands the stack an IPv4 packet sent to one of our own addresses, as if it had come in through an interface. | |
| int | netif_output (struct netif *netif, struct netbuf *nb) |
| Sends a frame through an interface's driver. | |
Variables | |
| struct netif * | netifs |
| static int | ethers_nr |
| static struct netif | loopback |
| static struct thread * | net_thread |
| static struct waitq | net_wait |
| static struct netbuf * | rx_head |
| static struct netbuf * | rx_tail |
| static size_t | rx_count |
| static struct callout_list | net_callouts |
Network interfaces (see net/netif.h).
A network driver registers its interface, hands it the frames it receives (netif_input()), and sends the frames the interface gives it (its transmit operation). lo, the loopback interface (127.0.0.1/8), is always there and comes first; the others are eth0, eth1, ..., in the order they are registered.
Received frames wait for the network's thread ([net], a kernel thread), which takes them up the stack, NET_BUDGET at a time before the other threads run again, and runs the network's callouts (net_callout_set()). It is an urgent thread: when a driver's interrupt wakes it, it runs as soon as the interrupt returns.
Definition in file netif.c.
| #define NET_BACKLOG 256 |
Definition at line 32 of file netif.c.
Referenced by rx_queue().
| #define NET_BUDGET 32 |
Definition at line 31 of file netif.c.
Referenced by net_main().
|
static |
Sets up lo, the loopback interface, once.
Definition at line 268 of file netif.c.
References netif::flags, htonl, netif::ip, loopback, loopback_init(), loopback_transmit(), netif::mtu, netif::name, NETIF_LOOPBACK, netif_register(), NETIF_RUNNING, NETIF_UP, netif::netmask, and netif::transmit.
Referenced by loopback_init(), loopback_module_init(), and netif_register().
|
static |
Sets up lo at boot, so that it is there even without a network card.
Definition at line 284 of file netif.c.
References loopback_init(), and loopback_module_init().
Referenced by loopback_module_init().
Sends a frame on lo: a copy of it comes back in.
Only frames sent through lo explicitly get here (a broadcast, SO_BINDTODEVICE): packets to 127.0.0.0/8 are turned around earlier, by ipv4_output().
Definition at line 255 of file netif.c.
References netbuf::data, netbuf::len, loopback_transmit(), memcpy(), netbuf_alloc(), and netif_input().
Referenced by loopback_init(), and loopback_transmit().
|
static |
Writes a MAC address into buf as "xx:xx:xx:xx:xx:xx" (printk() has no field widths) and returns buf.
Definition at line 115 of file netif.c.
References mac_string().
Referenced by mac_string(), and netif_register().
Sets a callout that the network's thread runs: fn(arg) is called once ns ns have passed.
TCP's timers use it.
| c | the callout |
| ns | the delay, in ns |
| fn | the function to call |
| arg | its argument |
Definition at line 137 of file netif.c.
References callout_set_on(), net_callout_set(), net_callouts, net_thread, and thread_wakeup().
Referenced by arp_resolve(), arp_retry(), keepalive_timeout(), net_callout_set(), rexmt_timeout(), tcp_dack(), tcp_fin_wait_2(), tcp_keepalive_reset(), tcp_output(), tcp_rexmt_start(), and tcp_time_wait().
|
static |
Runs the network's thread: it takes the received frames up the stack and runs the network's callouts, then sleeps until the next frame or callout.
Definition at line 149 of file netif.c.
References arch_rtime_ns(), arch_yield(), callout_list_next(), callout_list_run(), ether_input(), ipv4_input(), netbuf::loopback, netif::mac, NET_BUDGET, net_callouts, net_main(), net_wait, netbuf::netif, netbuf::next, NULL, rx_count, rx_head, rx_tail, and sched_wait().
Referenced by net_main(), and netif_register().
|
static |
Configures the first Ethernet interface from the kernel's command line: ip=address/prefix-length[:gateway].
Definition at line 73 of file netif.c.
References netif::flags, netif::gateway, htonl, netif::ip, kargs_get(), netif::name, netif_config(), NETIF_UP, netif::netmask, ntohl, NULL, parse_ipv4(), and printk().
Referenced by netif_config(), and netif_register().
| struct netif * netif_find | ( | const char * | name | ) |
Finds an interface by its name.
| name | the name (at most 16 characters, IFNAMSIZ) |
Definition at line 186 of file netif.c.
References netif::name, netif_find(), netifs, netif::next, and NULL.
Referenced by ifreq_request(), netif_find(), and socket_inet_setsockopt().
Hands the stack a frame that a driver received, possibly from an interrupt.
The netbuf is the stack's from now on.
| netif | the interface it came in on |
| nb | the frame |
Definition at line 323 of file netif.c.
References netbuf::len, netbuf::loopback, netbuf::netif, netif_input(), rx_queue(), and netif::stats.
Referenced by loopback_transmit(), netif_input(), and rx_poll().
Hands the stack an IPv4 packet sent to one of our own addresses, as if it had come in through an interface.
| netif | the interface it is received on |
| nb | the packet, from its IPv4 header |
Definition at line 340 of file netif.c.
References netbuf::len, netbuf::loopback, netbuf::netif, netif_loopback(), rx_queue(), and netif::stats.
Referenced by ipv4_output(), and netif_loopback().
Sends a frame through an interface's driver.
The netbuf stays the caller's.
| netif | the interface |
| nb | the frame |
Definition at line 358 of file netif.c.
References netbuf::len, netif_output(), netif::stats, and netif::transmit.
Referenced by ether_output(), and netif_output().
| int netif_register | ( | struct netif * | netif | ) |
Registers a network interface.
An interface without a name gets the next "ethN". The first Ethernet interface is configured from the kernel's ip= argument. The network's thread is started with the first interface.
| netif | the interface, with its MAC address and transmit set |
Definition at line 206 of file netif.c.
References ethers_nr, netif::flags, kthread_create(), loopback, loopback_init(), netif::mac, mac_string(), netif::mtu, netif::name, net_main(), net_thread, netif_config(), NETIF_LOOPBACK, netif_register(), netifs, netif::next, NULL, panic, printk(), snprintf(), netif::transmit, and thread::urgent.
Referenced by e1000_probe(), loopback_init(), and netif_register().
|
static |
Parses an address "a.b.c.d" at *s into *ip, in network byte order, and moves *s past it.
Returns 0, or -1 if it isn't an address.
Definition at line 49 of file netif.c.
References htonl, and parse_ipv4().
Referenced by netif_config(), and parse_ipv4().
Queues a received frame for the network's thread, and wakes it up.
The frame is dropped if the interface is down or too many frames wait.
Definition at line 294 of file netif.c.
References netif::flags, NET_BACKLOG, net_thread, NETIF_UP, netbuf::next, NULL, rx_count, rx_head, rx_queue(), rx_tail, and thread_wakeup().
Referenced by netif_input(), netif_loopback(), and rx_queue().
|
static |
Definition at line 35 of file netif.c.
Referenced by netif_register().
|
static |
Definition at line 37 of file netif.c.
Referenced by loopback_init(), and netif_register().
|
static |
Definition at line 45 of file netif.c.
Referenced by net_callout_set(), and net_main().
|
static |
Definition at line 39 of file netif.c.
Referenced by net_callout_set(), netif_register(), and rx_queue().
|
static |
Definition at line 40 of file netif.c.
Referenced by net_main().
| struct netif* netifs |
Definition at line 34 of file netif.c.
Referenced by ifconf(), ipv4_is_local(), ipv4_route(), netif_find(), netif_index(), netif_register(), and route().
|
static |
Definition at line 43 of file netif.c.
Referenced by net_main(), and rx_queue().
|
static |
Definition at line 42 of file netif.c.
Referenced by net_main(), and rx_queue().
|
static |
Definition at line 42 of file netif.c.
Referenced by net_main(), and rx_queue().