516 lines
14 KiB
HTML
516 lines
14 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of NETDEVICE</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>NETDEVICE</H1>
|
|
Section: Linux Programmer's Manual (7)<BR>Updated: 2019-11-19<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
netdevice - low-level access to Linux network devices
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/sys/ioctl.h">sys/ioctl.h</A>></B>
|
|
|
|
<BR>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/net/if.h">net/if.h</A>></B>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
This man page describes the sockets interface which is used to configure
|
|
network devices.
|
|
<P>
|
|
|
|
Linux supports some standard ioctls to configure network devices.
|
|
They can be used on any socket's file descriptor regardless of the
|
|
family or type.
|
|
Most of them pass an
|
|
<I>ifreq</I>
|
|
|
|
structure:
|
|
<P>
|
|
|
|
|
|
|
|
struct ifreq {
|
|
<BR> char ifr_name[IFNAMSIZ]; /* Interface name */
|
|
<BR> union {
|
|
<BR> struct sockaddr ifr_addr;
|
|
<BR> struct sockaddr ifr_dstaddr;
|
|
<BR> struct sockaddr ifr_broadaddr;
|
|
<BR> struct sockaddr ifr_netmask;
|
|
<BR> struct sockaddr ifr_hwaddr;
|
|
<BR> short ifr_flags;
|
|
<BR> int ifr_ifindex;
|
|
<BR> int ifr_metric;
|
|
<BR> int ifr_mtu;
|
|
<BR> struct ifmap ifr_map;
|
|
<BR> char ifr_slave[IFNAMSIZ];
|
|
<BR> char ifr_newname[IFNAMSIZ];
|
|
<BR> char *ifr_data;
|
|
<BR> };
|
|
};
|
|
|
|
|
|
<P>
|
|
|
|
Normally, the user specifies which device to affect by setting
|
|
<I>ifr_name</I>
|
|
|
|
to the name of the interface.
|
|
All other members of the structure may
|
|
share memory.
|
|
<A NAME="lbAE"> </A>
|
|
<H3>Ioctls</H3>
|
|
|
|
If an ioctl is marked as privileged, then using it requires an effective
|
|
user ID of 0 or the
|
|
<B>CAP_NET_ADMIN</B>
|
|
|
|
capability.
|
|
If this is not the case,
|
|
<B>EPERM</B>
|
|
|
|
will be returned.
|
|
<DL COMPACT>
|
|
<DT id="1"><B>SIOCGIFNAME</B>
|
|
|
|
<DD>
|
|
Given the
|
|
<I>ifr_ifindex</I>,
|
|
|
|
return the name of the interface in
|
|
<I>ifr_name</I>.
|
|
|
|
This is the only ioctl which returns its result in
|
|
<I>ifr_name</I>.
|
|
|
|
<DT id="2"><B>SIOCGIFINDEX</B>
|
|
|
|
<DD>
|
|
Retrieve the interface index of the interface into
|
|
<I>ifr_ifindex</I>.
|
|
|
|
<DT id="3"><B>SIOCGIFFLAGS</B>, <B>SIOCSIFFLAGS</B>
|
|
|
|
<DD>
|
|
Get or set the active flag word of the device.
|
|
<I>ifr_flags</I>
|
|
|
|
contains a bit mask of the following values:
|
|
|
|
|
|
<TABLE>
|
|
<TR VALIGN=top><TD ALIGN=center COLSPAN=2>Device flags<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_UP</TD><TD>Interface is running.<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_BROADCAST</TD><TD>Valid broadcast address set.<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_DEBUG</TD><TD>Internal debugging flag.<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_LOOPBACK</TD><TD>Interface is a loopback interface.<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_POINTOPOINT</TD><TD>Interface is a point-to-point link.<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_RUNNING</TD><TD>Resources allocated.<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_NOARP</TD><TD>
|
|
No arp protocol, L2 destination address not set.
|
|
<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_PROMISC</TD><TD>Interface is in promiscuous mode.<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_NOTRAILERS</TD><TD>Avoid use of trailers.<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_ALLMULTI</TD><TD>Receive all multicast packets.<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_MASTER</TD><TD>Master of a load balancing bundle.<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_SLAVE</TD><TD>Slave of a load balancing bundle.<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_MULTICAST</TD><TD>Supports multicast<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_PORTSEL</TD><TD>Is able to select media type via ifmap.<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_AUTOMEDIA</TD><TD>Auto media selection active.<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_DYNAMIC</TD><TD>
|
|
The addresses are lost when the interface goes down.
|
|
<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_LOWER_UP</TD><TD>Driver signals L1 up (since Linux 2.6.17)<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_DORMANT</TD><TD>Driver signals dormant (since Linux 2.6.17)<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_ECHO</TD><TD>Echo sent packets (since Linux 2.6.25)<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
|
|
</DL>
|
|
<P>
|
|
|
|
Setting the active flag word is a privileged operation, but any
|
|
process may read it.
|
|
<DL COMPACT>
|
|
<DT id="4"><B>SIOCGIFPFLAGS</B>, <B>SIOCSIFPFLAGS</B>
|
|
|
|
<DD>
|
|
Get or set extended (private) flags for the device.
|
|
<I>ifr_flags</I>
|
|
|
|
contains a bit mask of the following values:
|
|
<TABLE>
|
|
<TR VALIGN=top><TD ALIGN=center COLSPAN=2>Private flags<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_802_1Q_VLAN</TD><TD>Interface is 802.1Q VLAN device.<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_EBRIDGE</TD><TD>Interface is Ethernet bridging device.<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_SLAVE_INACTIVE</TD><TD>Interface is inactive bonding slave.<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_MASTER_8023AD</TD><TD>Interface is 802.3ad bonding master.<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_MASTER_ALB</TD><TD>Interface is balanced-alb bonding master.<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_BONDING</TD><TD>Interface is a bonding master or slave.<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_SLAVE_NEEDARP</TD><TD>Interface needs ARPs for validation.<BR></TD></TR>
|
|
<TR VALIGN=top><TD>IFF_ISATAP</TD><TD>Interface is RFC4214 ISATAP interface.<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
</DL>
|
|
<P>
|
|
|
|
Setting the extended (private) interface flags is a privileged operation.
|
|
<DL COMPACT>
|
|
<DT id="5"><B>SIOCGIFADDR</B>, <B>SIOCSIFADDR</B>
|
|
|
|
<DD>
|
|
Get or set the address of the device using
|
|
<I>ifr_addr</I>.
|
|
|
|
Setting the interface address is a privileged operation.
|
|
For compatibility, only
|
|
<B>AF_INET</B>
|
|
|
|
addresses are accepted or returned.
|
|
<DT id="6"><B>SIOCGIFDSTADDR</B>, <B>SIOCSIFDSTADDR</B>
|
|
|
|
<DD>
|
|
Get or set the destination address of a point-to-point device using
|
|
<I>ifr_dstaddr</I>.
|
|
|
|
For compatibility, only
|
|
<B>AF_INET</B>
|
|
|
|
addresses are accepted or returned.
|
|
Setting the destination address is a privileged operation.
|
|
<DT id="7"><B>SIOCGIFBRDADDR</B>, <B>SIOCSIFBRDADDR</B>
|
|
|
|
<DD>
|
|
Get or set the broadcast address for a device using
|
|
<I>ifr_brdaddr</I>.
|
|
|
|
For compatibility, only
|
|
<B>AF_INET</B>
|
|
|
|
addresses are accepted or returned.
|
|
Setting the broadcast address is a privileged operation.
|
|
<DT id="8"><B>SIOCGIFNETMASK</B>, <B>SIOCSIFNETMASK</B>
|
|
|
|
<DD>
|
|
Get or set the network mask for a device using
|
|
<I>ifr_netmask</I>.
|
|
|
|
For compatibility, only
|
|
<B>AF_INET</B>
|
|
|
|
addresses are accepted or returned.
|
|
Setting the network mask is a privileged operation.
|
|
<DT id="9"><B>SIOCGIFMETRIC</B>, <B>SIOCSIFMETRIC</B>
|
|
|
|
<DD>
|
|
Get or set the metric of the device using
|
|
<I>ifr_metric</I>.
|
|
|
|
This is currently not implemented; it sets
|
|
<I>ifr_metric</I>
|
|
|
|
to 0 if you attempt to read it and returns
|
|
<B>EOPNOTSUPP</B>
|
|
|
|
if you attempt to set it.
|
|
<DT id="10"><B>SIOCGIFMTU</B>, <B>SIOCSIFMTU</B>
|
|
|
|
<DD>
|
|
Get or set the MTU (Maximum Transfer Unit) of a device using
|
|
<I>ifr_mtu</I>.
|
|
|
|
Setting the MTU is a privileged operation.
|
|
Setting the MTU to
|
|
too small values may cause kernel crashes.
|
|
<DT id="11"><B>SIOCGIFHWADDR</B>, <B>SIOCSIFHWADDR</B>
|
|
|
|
<DD>
|
|
Get or set the hardware address of a device using
|
|
<I>ifr_hwaddr</I>.
|
|
|
|
The hardware address is specified in a struct
|
|
<I>sockaddr</I>.
|
|
|
|
<I>sa_family</I>
|
|
|
|
contains the ARPHRD_* device type,
|
|
<I>sa_data</I>
|
|
|
|
the L2 hardware address starting from byte 0.
|
|
Setting the hardware address is a privileged operation.
|
|
<DT id="12"><B>SIOCSIFHWBROADCAST</B>
|
|
|
|
<DD>
|
|
Set the hardware broadcast address of a device from
|
|
<I>ifr_hwaddr</I>.
|
|
|
|
This is a privileged operation.
|
|
<DT id="13"><B>SIOCGIFMAP</B>, <B>SIOCSIFMAP</B>
|
|
|
|
<DD>
|
|
Get or set the interface's hardware parameters using
|
|
<I>ifr_map</I>.
|
|
|
|
Setting the parameters is a privileged operation.
|
|
<DT id="14"><DD>
|
|
|
|
|
|
struct ifmap {
|
|
<BR> unsigned long mem_start;
|
|
<BR> unsigned long mem_end;
|
|
<BR> unsigned short base_addr;
|
|
<BR> unsigned char irq;
|
|
<BR> unsigned char dma;
|
|
<BR> unsigned char port;
|
|
};
|
|
|
|
|
|
<DT id="15"><DD>
|
|
The interpretation of the ifmap structure depends on the device driver
|
|
and the architecture.
|
|
<DT id="16"><B>SIOCADDMULTI</B>, <B>SIOCDELMULTI</B>
|
|
|
|
<DD>
|
|
Add an address to or delete an address from the device's link layer
|
|
multicast filters using
|
|
<I>ifr_hwaddr</I>.
|
|
|
|
These are privileged operations.
|
|
See also
|
|
<B><A HREF="/cgi-bin/man/man2html?7+packet">packet</A></B>(7)
|
|
|
|
for an alternative.
|
|
<DT id="17"><B>SIOCGIFTXQLEN</B>, <B>SIOCSIFTXQLEN</B>
|
|
|
|
<DD>
|
|
Get or set the transmit queue length of a device using
|
|
<I>ifr_qlen</I>.
|
|
|
|
Setting the transmit queue length is a privileged operation.
|
|
<DT id="18"><B>SIOCSIFNAME</B>
|
|
|
|
<DD>
|
|
Changes the name of the interface specified in
|
|
<I>ifr_name</I>
|
|
|
|
to
|
|
<I>ifr_newname</I>.
|
|
|
|
This is a privileged operation.
|
|
It is allowed only when the interface
|
|
is not up.
|
|
<DT id="19"><B>SIOCGIFCONF</B>
|
|
|
|
<DD>
|
|
Return a list of interface (network layer) addresses.
|
|
This currently
|
|
means only addresses of the
|
|
<B>AF_INET</B>
|
|
|
|
(IPv4) family for compatibility.
|
|
Unlike the others, this ioctl passes an
|
|
<I>ifconf</I>
|
|
|
|
structure:
|
|
<DT id="20"><DD>
|
|
|
|
|
|
struct ifconf {
|
|
<BR> int ifc_len; /* size of buffer */
|
|
<BR> union {
|
|
<BR> char *ifc_buf; /* buffer address */
|
|
<BR> struct ifreq *ifc_req; /* array of structures */
|
|
<BR> };
|
|
};
|
|
|
|
|
|
<DT id="21"><DD>
|
|
If
|
|
<I>ifc_req</I>
|
|
|
|
is NULL,
|
|
<B>SIOCGIFCONF</B>
|
|
|
|
returns the necessary buffer size in bytes
|
|
for receiving all available addresses in
|
|
<I>ifc_len</I>.
|
|
|
|
Otherwise,
|
|
<I>ifc_req</I>
|
|
|
|
contains a pointer to an array of
|
|
<I>ifreq</I>
|
|
|
|
structures to be filled with all currently active L3 interface addresses.
|
|
<I>ifc_len</I>
|
|
|
|
contains the size of the array in bytes.
|
|
Within each
|
|
<I>ifreq</I>
|
|
|
|
structure,
|
|
<I>ifr_name</I>
|
|
|
|
will receive the interface name, and
|
|
<I>ifr_addr</I>
|
|
|
|
the address.
|
|
The actual number of bytes transferred is returned in
|
|
<I>ifc_len</I>.
|
|
|
|
<DT id="22"><DD>
|
|
If the size specified by
|
|
<I>ifc_len</I>
|
|
|
|
is insufficient to store all the addresses,
|
|
the kernel will skip the exceeding ones and return success.
|
|
There is no reliable way of detecting this condition once it has occurred.
|
|
It is therefore recommended to either determine the necessary buffer size
|
|
beforehand by calling
|
|
<B>SIOCGIFCONF</B>
|
|
|
|
with
|
|
<I>ifc_req</I>
|
|
|
|
set to NULL, or to retry the call with a bigger buffer whenever
|
|
<I>ifc_len</I>
|
|
|
|
upon return differs by less than
|
|
<I>sizeof(struct ifreq)</I>
|
|
|
|
from its original value.
|
|
<DT id="23"><DD>
|
|
If an error occurs accessing the
|
|
<I>ifconf</I>
|
|
|
|
or
|
|
<I>ifreq</I>
|
|
|
|
structures,
|
|
<B>EFAULT</B>
|
|
|
|
will be returned.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</DL>
|
|
<P>
|
|
|
|
Most protocols support their own ioctls to configure protocol-specific
|
|
interface options.
|
|
See the protocol man pages for a description.
|
|
For configuring IP addresses, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+ip">ip</A></B>(7).
|
|
|
|
<P>
|
|
|
|
In addition, some devices support private ioctls.
|
|
These are not described here.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
Strictly speaking,
|
|
<B>SIOCGIFCONF</B>
|
|
|
|
and the other ioctls that accept or return only
|
|
<B>AF_INET</B>
|
|
|
|
socket addresses,
|
|
are IP-specific and belong in
|
|
<B><A HREF="/cgi-bin/man/man2html?7+ip">ip</A></B>(7).
|
|
|
|
<P>
|
|
|
|
The names of interfaces with no addresses or that don't have the
|
|
<B>IFF_RUNNING</B>
|
|
|
|
flag set can be found via
|
|
<I>/proc/net/dev</I>.
|
|
|
|
<P>
|
|
|
|
Local IPv6 IP addresses can be found via
|
|
<I>/proc/net</I>
|
|
|
|
or via
|
|
<B><A HREF="/cgi-bin/man/man2html?7+rtnetlink">rtnetlink</A></B>(7).
|
|
|
|
<A NAME="lbAG"> </A>
|
|
<H2>BUGS</H2>
|
|
|
|
glibc 2.1 is missing the
|
|
<I>ifr_newname</I>
|
|
|
|
macro in
|
|
<I><<A HREF="file:///usr/include/net/if.h">net/if.h</A>></I>.
|
|
|
|
Add the following to your program as a workaround:
|
|
<P>
|
|
|
|
|
|
|
|
#ifndef ifr_newname
|
|
#define ifr_newname ifr_ifru.ifru_slave
|
|
#endif
|
|
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?5+proc">proc</A></B>(5),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+capabilities">capabilities</A></B>(7),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+ip">ip</A></B>(7),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+rtnetlink">rtnetlink</A></B>(7)
|
|
|
|
<A NAME="lbAI"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="24"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="25"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="26"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DL>
|
|
<DT id="27"><A HREF="#lbAE">Ioctls</A><DD>
|
|
</DL>
|
|
<DT id="28"><A HREF="#lbAF">NOTES</A><DD>
|
|
<DT id="29"><A HREF="#lbAG">BUGS</A><DD>
|
|
<DT id="30"><A HREF="#lbAH">SEE ALSO</A><DD>
|
|
<DT id="31"><A HREF="#lbAI">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:06:09 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|