AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
ifioctl.c File Reference

The network interfaces' ioctl() requests, made on an AF_INET socket. More...

#include <core/system.h>
#include <core/string.h>
#include <net/byteorder.h>
#include <net/inet.h>
#include <sys/proc.h>
#include <sys/sched.h>
#include <sys/uaccess.h>
#include <aquila/errno.h>
#include <aquila/if.h>
#include <aquila/in.h>
#include <aquila/ioctl.h>
#include <aquila/route.h>

Go to the source code of this file.

Functions

static int netif_index (struct netif *netif)
 Returns an interface's index: its place in the list, from 1.
static void ifaddr_put (struct sockaddr *a, uint32_t ip)
 Writes an IPv4 address into a struct sockaddr.
static int ifaddr_get (const struct sockaddr *a, uint32_t *ip)
 Reads an IPv4 address from a struct sockaddr.
static int ifconf (struct ifconf *uifc)
 Handles SIOCGIFCONF: lists as many interfaces as the buffer has room for, or says how much room is needed if there is no buffer.
static int route (int request, struct rtentry *urt)
 Handles SIOCADDRT and SIOCDELRT, for the default route only (0.0.0.0/0 through a gateway): the gateway is set on the interface whose link it is on, or removed from every interface.
static int ifreq_request (int request, struct ifreq *ifr)
 Handles a request about one interface, on the kernel's copy of the struct ifreq.
int inet_ifioctl (int request, void *argp)
 Handles an interface ioctl() request on an AF_INET socket.

Detailed Description

The network interfaces' ioctl() requests, made on an AF_INET socket.

They list the interfaces, read and set their flags and addresses, read their hardware address, MTU and index, and set the default route, as ifconfig and route need. Only root may set anything.

Definition in file ifioctl.c.

Function Documentation

◆ ifaddr_get()

int ifaddr_get ( const struct sockaddr * a,
uint32_t * ip )
static

Reads an IPv4 address from a struct sockaddr.

Returns 0, or -EAFNOSUPPORT if it isn't an AF_INET address.

Definition at line 46 of file ifioctl.c.

References ifaddr_get().

Referenced by ifaddr_get(), and ifreq_request().

◆ ifaddr_put()

void ifaddr_put ( struct sockaddr * a,
uint32_t ip )
static

Writes an IPv4 address into a struct sockaddr.

Definition at line 35 of file ifioctl.c.

References ifaddr_put(), and memset().

Referenced by ifaddr_put(), ifconf(), and ifreq_request().

◆ ifconf()

int ifconf ( struct ifconf * uifc)
static

Handles SIOCGIFCONF: lists as many interfaces as the buffer has room for, or says how much room is needed if there is no buffer.

Returns 0 or a negative errno.

Definition at line 60 of file ifioctl.c.

References ifaddr_put(), ifconf(), netif::ip, memcpy(), memset(), netif::name, netifs, and netif::next.

Referenced by ifconf(), and inet_ifioctl().

◆ ifreq_request()

int ifreq_request ( int request,
struct ifreq * ifr )
static

Handles a request about one interface, on the kernel's copy of the struct ifreq.

Returns 0 or a negative errno.

Definition at line 193 of file ifioctl.c.

References curproc, netif::flags, htonl, ifaddr_get(), ifaddr_put(), ifreq_request(), netif::ip, netif::mac, memcpy(), memset(), netif::mtu, netif_find(), netif_index(), NETIF_LOOPBACK, NETIF_RUNNING, NETIF_UP, and netif::netmask.

Referenced by ifreq_request(), and inet_ifioctl().

◆ inet_ifioctl()

int inet_ifioctl ( int request,
void * argp )

Handles an interface ioctl() request on an AF_INET socket.

Parameters
requestthe request (SIOC*)
argpits argument, in user memory
Returns
0, or a negative errno: -ENOTTY for another request, -EPERM to set something without being root, -ENODEV for no such interface, or -EFAULT

Definition at line 153 of file ifioctl.c.

References curproc, ifconf(), ifreq_request(), inet_ifioctl(), and route().

Referenced by inet_ifioctl(), socket_inet_ioctl(), and socket_tcp_ioctl().

◆ netif_index()

int netif_index ( struct netif * netif)
static

Returns an interface's index: its place in the list, from 1.

Definition at line 24 of file ifioctl.c.

References netif_index(), netifs, and netif::next.

Referenced by ifreq_request(), and netif_index().

◆ route()

int route ( int request,
struct rtentry * urt )
static

Handles SIOCADDRT and SIOCDELRT, for the default route only (0.0.0.0/0 through a gateway): the gateway is set on the interface whose link it is on, or removed from every interface.

Returns 0 or a negative errno.

Definition at line 106 of file ifioctl.c.

References netif::gateway, netif::ip, netifs, netif::netmask, netif::next, and route().

Referenced by inet_ifioctl(), and route().