Blame man7/netdevice.7

Packit 7cfc04
'\" t
Packit 7cfc04
.\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM_ONE_PARA)
Packit 7cfc04
.\" Permission is granted to distribute possibly modified copies
Packit 7cfc04
.\" of this page provided the header is included verbatim,
Packit 7cfc04
.\" and in case of nontrivial modification author and date
Packit 7cfc04
.\" of the modification is added to the header.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" $Id: netdevice.7,v 1.10 2000/08/17 10:09:54 ak Exp $
Packit 7cfc04
.\"
Packit 7cfc04
.\" Modified, 2004-11-25, mtk, formatting and a few wording fixes
Packit 7cfc04
.\"
Packit 7cfc04
.\" Modified, 2011-11-02, <bidulock@openss7.org>, added many basic
Packit 7cfc04
.\"  but missing ioctls, such as SIOCGIFADDR.
Packit 7cfc04
.\"
Packit 7cfc04
.TH NETDEVICE  7 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
netdevice \- low-level access to Linux network devices
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.B "#include <sys/ioctl.h>"
Packit 7cfc04
.br
Packit 7cfc04
.B "#include <net/if.h>"
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
This man page describes the sockets interface which is used to configure
Packit 7cfc04
network devices.
Packit 7cfc04
.PP
Packit 7cfc04
Linux supports some standard ioctls to configure network devices.
Packit 7cfc04
They can be used on any socket's file descriptor regardless of the
Packit 7cfc04
family or type.
Packit 7cfc04
Most of them pass an
Packit 7cfc04
.I ifreq
Packit 7cfc04
structure:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
struct ifreq {
Packit 7cfc04
    char ifr_name[IFNAMSIZ]; /* Interface name */
Packit 7cfc04
    union {
Packit 7cfc04
        struct sockaddr ifr_addr;
Packit 7cfc04
        struct sockaddr ifr_dstaddr;
Packit 7cfc04
        struct sockaddr ifr_broadaddr;
Packit 7cfc04
        struct sockaddr ifr_netmask;
Packit 7cfc04
        struct sockaddr ifr_hwaddr;
Packit 7cfc04
        short           ifr_flags;
Packit 7cfc04
        int             ifr_ifindex;
Packit 7cfc04
        int             ifr_metric;
Packit 7cfc04
        int             ifr_mtu;
Packit 7cfc04
        struct ifmap    ifr_map;
Packit 7cfc04
        char            ifr_slave[IFNAMSIZ];
Packit 7cfc04
        char            ifr_newname[IFNAMSIZ];
Packit 7cfc04
        char           *ifr_data;
Packit 7cfc04
    };
Packit 7cfc04
};
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
Normally, the user specifies which device to affect by setting
Packit 7cfc04
.I ifr_name
Packit 7cfc04
to the name of the interface.
Packit 7cfc04
All other members of the structure may
Packit 7cfc04
share memory.
Packit 7cfc04
.SS Ioctls
Packit 7cfc04
If an ioctl is marked as privileged, then using it requires an effective
Packit 7cfc04
user ID of 0 or the
Packit 7cfc04
.B CAP_NET_ADMIN
Packit 7cfc04
capability.
Packit 7cfc04
If this is not the case,
Packit 7cfc04
.B EPERM
Packit 7cfc04
will be returned.
Packit 7cfc04
.TP
Packit 7cfc04
.B SIOCGIFNAME
Packit 7cfc04
Given the
Packit 7cfc04
.IR ifr_ifindex ,
Packit 7cfc04
return the name of the interface in
Packit 7cfc04
.IR ifr_name .
Packit 7cfc04
This is the only ioctl which returns its result in
Packit 7cfc04
.IR ifr_name .
Packit 7cfc04
.TP
Packit 7cfc04
.B SIOCGIFINDEX
Packit 7cfc04
Retrieve the interface index of the interface into
Packit 7cfc04
.IR ifr_ifindex .
Packit 7cfc04
.TP
Packit 7cfc04
.BR SIOCGIFFLAGS ", " SIOCSIFFLAGS
Packit 7cfc04
Get or set the active flag word of the device.
Packit 7cfc04
.I ifr_flags
Packit 7cfc04
contains a bit mask of the following values:
Packit 7cfc04
.\" Do not right adjust text blocks in tables
Packit 7cfc04
.na
Packit 7cfc04
.TS
Packit 7cfc04
tab(:);
Packit 7cfc04
c s
Packit 7cfc04
l l.
Packit 7cfc04
Device flags
Packit 7cfc04
IFF_UP:Interface is running.
Packit 7cfc04
IFF_BROADCAST:Valid broadcast address set.
Packit 7cfc04
IFF_DEBUG:Internal debugging flag.
Packit 7cfc04
IFF_LOOPBACK:Interface is a loopback interface.
Packit 7cfc04
IFF_POINTOPOINT:Interface is a point-to-point link.
Packit 7cfc04
IFF_RUNNING:Resources allocated.
Packit 7cfc04
IFF_NOARP:T{
Packit 7cfc04
No arp protocol, L2 destination address not set.
Packit 7cfc04
T}
Packit 7cfc04
IFF_PROMISC:Interface is in promiscuous mode.
Packit 7cfc04
IFF_NOTRAILERS:Avoid use of trailers.
Packit 7cfc04
IFF_ALLMULTI:Receive all multicast packets.
Packit 7cfc04
IFF_MASTER:Master of a load balancing bundle.
Packit 7cfc04
IFF_SLAVE:Slave of a load balancing bundle.
Packit 7cfc04
IFF_MULTICAST:Supports multicast
Packit 7cfc04
IFF_PORTSEL:Is able to select media type via ifmap.
Packit 7cfc04
IFF_AUTOMEDIA:Auto media selection active.
Packit 7cfc04
IFF_DYNAMIC:T{
Packit 7cfc04
The addresses are lost when the interface goes down.
Packit 7cfc04
T}
Packit 7cfc04
IFF_LOWER_UP:Driver signals L1 up (since Linux 2.6.17)
Packit 7cfc04
IFF_DORMANT:Driver signals dormant (since Linux 2.6.17)
Packit 7cfc04
IFF_ECHO:Echo sent packets (since Linux 2.6.25)
Packit 7cfc04
.TE
Packit 7cfc04
.ad
Packit 7cfc04
.PP
Packit 7cfc04
Setting the active flag word is a privileged operation, but any
Packit 7cfc04
process may read it.
Packit 7cfc04
.TP
Packit 7cfc04
.BR SIOCGIFPFLAGS ", " SIOCSIFPFLAGS
Packit 7cfc04
Get or set extended (private) flags for the device.
Packit 7cfc04
.I ifr_flags
Packit 7cfc04
contains a bit mask of the following values:
Packit 7cfc04
.TS
Packit 7cfc04
tab(:);
Packit 7cfc04
c s
Packit 7cfc04
l l.
Packit 7cfc04
Private flags
Packit 7cfc04
IFF_802_1Q_VLAN:Interface is 802.1Q VLAN device.
Packit 7cfc04
IFF_EBRIDGE:Interface is Ethernet bridging device.
Packit 7cfc04
IFF_SLAVE_INACTIVE:Interface is inactive bonding slave.
Packit 7cfc04
IFF_MASTER_8023AD:Interface is 802.3ad bonding master.
Packit 7cfc04
IFF_MASTER_ALB:Interface is balanced-alb bonding master.
Packit 7cfc04
IFF_BONDING:Interface is a bonding master or slave.
Packit 7cfc04
IFF_SLAVE_NEEDARP:Interface needs ARPs for validation.
Packit 7cfc04
IFF_ISATAP:Interface is RFC4214 ISATAP interface.
Packit 7cfc04
.TE
Packit 7cfc04
.PP
Packit 7cfc04
Setting the extended (private) interface flags is a privileged operation.
Packit 7cfc04
.TP
Packit 7cfc04
.BR SIOCGIFADDR ", " SIOCSIFADDR
Packit 7cfc04
Get or set the address of the device using
Packit 7cfc04
.IR ifr_addr .
Packit 7cfc04
Setting the interface address is a privileged operation.
Packit 7cfc04
For compatibility, only
Packit 7cfc04
.B AF_INET
Packit 7cfc04
addresses are accepted or returned.
Packit 7cfc04
.TP
Packit 7cfc04
.BR SIOCGIFDSTADDR ", " SIOCSIFDSTADDR
Packit 7cfc04
Get or set the destination address of a point-to-point device using
Packit 7cfc04
.IR ifr_dstaddr .
Packit 7cfc04
For compatibility, only
Packit 7cfc04
.B AF_INET
Packit 7cfc04
addresses are accepted or returned.
Packit 7cfc04
Setting the destination address is a privileged operation.
Packit 7cfc04
.TP
Packit 7cfc04
.BR SIOCGIFBRDADDR ", " SIOCSIFBRDADDR
Packit 7cfc04
Get or set the broadcast address for a device using
Packit 7cfc04
.IR ifr_brdaddr .
Packit 7cfc04
For compatibility, only
Packit 7cfc04
.B AF_INET
Packit 7cfc04
addresses are accepted or returned.
Packit 7cfc04
Setting the broadcast address is a privileged operation.
Packit 7cfc04
.TP
Packit 7cfc04
.BR SIOCGIFNETMASK ", " SIOCSIFNETMASK
Packit 7cfc04
Get or set the network mask for a device using
Packit 7cfc04
.IR ifr_netmask .
Packit 7cfc04
For compatibility, only
Packit 7cfc04
.B AF_INET
Packit 7cfc04
addresses are accepted or returned.
Packit 7cfc04
Setting the network mask is a privileged operation.
Packit 7cfc04
.TP
Packit 7cfc04
.BR SIOCGIFMETRIC ", " SIOCSIFMETRIC
Packit 7cfc04
Get or set the metric of the device using
Packit 7cfc04
.IR ifr_metric .
Packit 7cfc04
This is currently not implemented; it sets
Packit 7cfc04
.I ifr_metric
Packit 7cfc04
to 0 if you attempt to read it and returns
Packit 7cfc04
.B EOPNOTSUPP
Packit 7cfc04
if you attempt to set it.
Packit 7cfc04
.TP
Packit 7cfc04
.BR SIOCGIFMTU ", " SIOCSIFMTU
Packit 7cfc04
Get or set the MTU (Maximum Transfer Unit) of a device using
Packit 7cfc04
.IR ifr_mtu .
Packit 7cfc04
Setting the MTU is a privileged operation.
Packit 7cfc04
Setting the MTU to
Packit 7cfc04
too small values may cause kernel crashes.
Packit 7cfc04
.TP
Packit 7cfc04
.BR SIOCGIFHWADDR ", " SIOCSIFHWADDR
Packit 7cfc04
Get or set the hardware address of a device using
Packit 7cfc04
.IR ifr_hwaddr .
Packit 7cfc04
The hardware address is specified in a struct
Packit 7cfc04
.IR sockaddr .
Packit 7cfc04
.I sa_family
Packit 7cfc04
contains the ARPHRD_* device type,
Packit 7cfc04
.I sa_data
Packit 7cfc04
the L2 hardware address starting from byte 0.
Packit 7cfc04
Setting the hardware address is a privileged operation.
Packit 7cfc04
.TP
Packit 7cfc04
.B SIOCSIFHWBROADCAST
Packit 7cfc04
Set the hardware broadcast address of a device from
Packit 7cfc04
.IR ifr_hwaddr .
Packit 7cfc04
This is a privileged operation.
Packit 7cfc04
.TP
Packit 7cfc04
.BR SIOCGIFMAP ", " SIOCSIFMAP
Packit 7cfc04
Get or set the interface's hardware parameters using
Packit 7cfc04
.IR ifr_map .
Packit 7cfc04
Setting the parameters is a privileged operation.
Packit 7cfc04
.IP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
struct ifmap {
Packit 7cfc04
    unsigned long   mem_start;
Packit 7cfc04
    unsigned long   mem_end;
Packit 7cfc04
    unsigned short  base_addr;
Packit 7cfc04
    unsigned char   irq;
Packit 7cfc04
    unsigned char   dma;
Packit 7cfc04
    unsigned char   port;
Packit 7cfc04
};
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.IP
Packit 7cfc04
The interpretation of the ifmap structure depends on the device driver
Packit 7cfc04
and the architecture.
Packit 7cfc04
.TP
Packit 7cfc04
.BR SIOCADDMULTI ", " SIOCDELMULTI
Packit 7cfc04
Add an address to or delete an address from the device's link layer
Packit 7cfc04
multicast filters using
Packit 7cfc04
.IR ifr_hwaddr .
Packit 7cfc04
These are privileged operations.
Packit 7cfc04
See also
Packit 7cfc04
.BR packet (7)
Packit 7cfc04
for an alternative.
Packit 7cfc04
.TP
Packit 7cfc04
.BR SIOCGIFTXQLEN ", " SIOCSIFTXQLEN
Packit 7cfc04
Get or set the transmit queue length of a device using
Packit 7cfc04
.IR ifr_qlen .
Packit 7cfc04
Setting the transmit queue length is a privileged operation.
Packit 7cfc04
.TP
Packit 7cfc04
.B SIOCSIFNAME
Packit 7cfc04
Changes the name of the interface specified in
Packit 7cfc04
.I ifr_name
Packit 7cfc04
to
Packit 7cfc04
.IR ifr_newname .
Packit 7cfc04
This is a privileged operation.
Packit 7cfc04
It is allowed only when the interface
Packit 7cfc04
is not up.
Packit 7cfc04
.TP
Packit 7cfc04
.B SIOCGIFCONF
Packit 7cfc04
Return a list of interface (transport layer) addresses.
Packit 7cfc04
This currently
Packit 7cfc04
means only addresses of the
Packit 7cfc04
.B AF_INET
Packit 7cfc04
(IPv4) family for compatibility.
Packit 7cfc04
Unlike the others, this ioctl passes an
Packit 7cfc04
.I ifconf
Packit 7cfc04
structure:
Packit 7cfc04
.IP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
struct ifconf {
Packit 7cfc04
    int                 ifc_len; /* size of buffer */
Packit 7cfc04
    union {
Packit 7cfc04
        char           *ifc_buf; /* buffer address */
Packit 7cfc04
        struct ifreq   *ifc_req; /* array of structures */
Packit 7cfc04
    };
Packit 7cfc04
};
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.IP
Packit 7cfc04
If
Packit 7cfc04
.I ifc_req
Packit 7cfc04
is NULL,
Packit 7cfc04
.B SIOCGIFCONF
Packit 7cfc04
returns the necessary buffer size in bytes
Packit 7cfc04
for receiving all available addresses in
Packit 7cfc04
.IR ifc_len .
Packit 7cfc04
Otherwise,
Packit 7cfc04
.I ifc_req
Packit 7cfc04
contains a pointer to an array of
Packit 7cfc04
.I ifreq
Packit 7cfc04
structures to be filled with all currently active L3 interface addresses.
Packit 7cfc04
.I ifc_len
Packit 7cfc04
contains the size of the array in bytes.
Packit 7cfc04
Within each
Packit 7cfc04
.I ifreq
Packit 7cfc04
structure,
Packit 7cfc04
.I ifr_name
Packit 7cfc04
will receive the interface name, and
Packit 7cfc04
.I ifr_addr
Packit 7cfc04
the address.
Packit 7cfc04
The actual number of bytes transferred is returned in
Packit 7cfc04
.IR ifc_len .
Packit 7cfc04
.IP
Packit 7cfc04
If the size specified by
Packit 7cfc04
.I ifc_len
Packit 7cfc04
is insufficient to store all the addresses,
Packit 7cfc04
the kernel will skip the exceeding ones and return success.
Packit 7cfc04
There is no reliable way of detecting this condition once it has occurred.
Packit 7cfc04
It is therefore recommended to either determine the necessary buffer size
Packit 7cfc04
beforehand by calling
Packit 7cfc04
.B SIOCGIFCONF
Packit 7cfc04
with
Packit 7cfc04
.I ifc_req
Packit 7cfc04
set to NULL, or to retry the call with a bigger buffer whenever
Packit 7cfc04
.I ifc_len
Packit 7cfc04
upon return differs by less than
Packit 7cfc04
.I sizeof(struct ifreq)
Packit 7cfc04
from its original value.
Packit 7cfc04
.IP
Packit 7cfc04
If an error occurs accessing the
Packit 7cfc04
.I ifconf
Packit 7cfc04
or
Packit 7cfc04
.I ifreq
Packit 7cfc04
structures,
Packit 7cfc04
.B EFAULT
Packit 7cfc04
will be returned.
Packit 7cfc04
.\" Slaving isn't supported in 2.2
Packit 7cfc04
.\" .
Packit 7cfc04
.\" .TP
Packit 7cfc04
.\" .BR SIOCGIFSLAVE ", " SIOCSIFSLAVE
Packit 7cfc04
.\" Get or set the slave device using
Packit 7cfc04
.\" .IR ifr_slave .
Packit 7cfc04
.\" Setting the slave device is a privileged operation.
Packit 7cfc04
.\" .PP
Packit 7cfc04
.\" FIXME . add amateur radio stuff.
Packit 7cfc04
.PP
Packit 7cfc04
Most protocols support their own ioctls to configure protocol-specific
Packit 7cfc04
interface options.
Packit 7cfc04
See the protocol man pages for a description.
Packit 7cfc04
For configuring IP addresses, see
Packit 7cfc04
.BR ip (7).
Packit 7cfc04
.PP
Packit 7cfc04
In addition, some devices support private ioctls.
Packit 7cfc04
These are not described here.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
Strictly speaking,
Packit 7cfc04
.B SIOCGIFCONF
Packit 7cfc04
and the other ioctls that accept or return only
Packit 7cfc04
.B AF_INET
Packit 7cfc04
socket addresses,
Packit 7cfc04
are IP-specific and belong in
Packit 7cfc04
.BR ip (7).
Packit 7cfc04
.PP
Packit 7cfc04
The names of interfaces with no addresses or that don't have the
Packit 7cfc04
.B IFF_RUNNING
Packit 7cfc04
flag set can be found via
Packit 7cfc04
.IR /proc/net/dev .
Packit 7cfc04
.PP
Packit 7cfc04
Local IPv6 IP addresses can be found via
Packit 7cfc04
.I /proc/net
Packit 7cfc04
or via
Packit 7cfc04
.BR rtnetlink (7).
Packit 7cfc04
.SH BUGS
Packit 7cfc04
glibc 2.1 is missing the
Packit 7cfc04
.I ifr_newname
Packit 7cfc04
macro in
Packit 7cfc04
.IR <net/if.h> .
Packit 7cfc04
Add the following to your program as a workaround:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
#ifndef ifr_newname
Packit 7cfc04
#define ifr_newname     ifr_ifru.ifru_slave
Packit 7cfc04
#endif
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR proc (5),
Packit 7cfc04
.BR capabilities (7),
Packit 7cfc04
.BR ip (7),
Packit 7cfc04
.BR rtnetlink (7)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.