OSDN Git Service

(split) LDP: Update original to LDP v3.40.
[linuxjm/LDP_man-pages.git] / original / man7 / netdevice.7
1 '\" t
2 .\" Don't change the first line, it tells man that tbl is needed.
3 .\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
4 .\" Permission is granted to distribute possibly modified copies
5 .\" of this page provided the header is included verbatim,
6 .\" and in case of nontrivial modification author and date
7 .\" of the modification is added to the header.
8 .\" $Id: netdevice.7,v 1.10 2000/08/17 10:09:54 ak Exp $
9 .\"
10 .\" Modified, 2004-11-25, mtk, formatting and a few wording fixes
11 .\"
12 .\" Modified, 2011-11-02, <bidulock@openss7.org>, added many basic
13 .\"  but missing ioctls, such as SIOCGIFADDR.
14 .\"
15 .TH NETDEVICE  7 2012-04-26 "Linux" "Linux Programmer's Manual"
16 .SH NAME
17 netdevice \- Low level access to Linux network devices
18 .SH SYNOPSIS
19 .B "#include <sys/ioctl.h>"
20 .br
21 .B "#include <net/if.h>"
22 .SH DESCRIPTION
23 This man page describes the sockets interface which is used to configure
24 network devices.
25
26 Linux supports some standard ioctls to configure network devices.
27 They can be used on any socket's file descriptor regardless of the
28 family or type.
29 They pass an
30 .I ifreq
31 structure:
32
33 .in +4n
34 .nf
35 struct ifreq {
36     char ifr_name[IFNAMSIZ]; /* Interface name */
37     union {
38         struct sockaddr ifr_addr;
39         struct sockaddr ifr_dstaddr;
40         struct sockaddr ifr_broadaddr;
41         struct sockaddr ifr_netmask;
42         struct sockaddr ifr_hwaddr;
43         short           ifr_flags;
44         int             ifr_ifindex;
45         int             ifr_metric;
46         int             ifr_mtu;
47         struct ifmap    ifr_map;
48         char            ifr_slave[IFNAMSIZ];
49         char            ifr_newname[IFNAMSIZ];
50         char           *ifr_data;
51     };
52 };
53
54 struct ifconf {
55     int                 ifc_len; /* size of buffer */
56     union {
57         char           *ifc_buf; /* buffer address */
58         struct ifreq   *ifc_req; /* array of structures */
59     };
60 };
61 .fi
62 .in
63
64 Normally, the user specifies which device to affect by setting
65 .I ifr_name
66 to the name of the interface.
67 All other members of the structure may
68 share memory.
69 .SS Ioctls
70 If an ioctl is marked as privileged then using it requires an effective
71 user ID of 0 or the
72 .B CAP_NET_ADMIN
73 capability.
74 If this is not the case
75 .B EPERM
76 will be returned.
77 .TP
78 .B SIOCGIFNAME
79 Given the
80 .IR ifr_ifindex ,
81 return the name of the interface in
82 .IR ifr_name .
83 This is the only ioctl which returns its result in
84 .IR ifr_name .
85 .TP
86 .B SIOCGIFINDEX
87 Retrieve the interface index of the interface into
88 .IR ifr_ifindex .
89 .TP
90 .BR SIOCGIFFLAGS ", " SIOCSIFFLAGS
91 Get or set the active flag word of the device.
92 .I ifr_flags
93 contains a bit mask of the following values:
94 .TS
95 tab(:);
96 c s
97 l l.
98 Device flags
99 IFF_UP:Interface is running.
100 IFF_BROADCAST:Valid broadcast address set.
101 IFF_DEBUG:Internal debugging flag.
102 IFF_LOOPBACK:Interface is a loopback interface.
103 IFF_POINTOPOINT:Interface is a point-to-point link.
104 IFF_RUNNING:Resources allocated.
105 IFF_NOARP:No arp protocol, L2 destination address not set.
106 IFF_PROMISC:Interface is in promiscuous mode.
107 IFF_NOTRAILERS:Avoid use of trailers.
108 IFF_ALLMULTI:Receive all multicast packets.
109 IFF_MASTER:Master of a load balancing bundle.
110 IFF_SLAVE:Slave of a load balancing bundle.
111 IFF_MULTICAST:Supports multicast
112 IFF_PORTSEL:Is able to select media type via ifmap.
113 IFF_AUTOMEDIA:Auto media selection active.
114 IFF_DYNAMIC:T{
115 The addresses are lost when the interface goes down.
116 T}
117 IFF_LOWER_UP:Driver signals L1 up (since Linux 2.6.17)
118 IFF_DORMANT:Driver signals dormant (since Linux 2.6.17)
119 IFF_ECHO:Echo sent packets (since Linux 2.6.25)
120
121
122 .TE
123 Setting the active flag word is a privileged operation, but any
124 process may read it.
125 .TP
126 .BR SIOCGIFPFLAGS ", " SIOCSIFPFLAGS
127 Get or set extended (private) flags for the device.
128 .I ifr_flags
129 contains a bit mask of the following values:
130 .TS
131 tab(:);
132 c s
133 l l.
134 Private flags
135 IFF_802_1Q_VLAN:Interface is 802.1Q VLAN device.
136 IFF_EBRIDGE:Interface is Ethernet bridging device.
137 IFF_SLAVE_INACTIVE:Interface is inactive bonding slave.
138 IFF_MASTER_8023AD:Interface is 802.3ad bonding master.
139 IFF_MASTER_ALB:Interface is balanced-alb bonding master.
140 IFF_BONDING:Interface is a bonding master or slave.
141 IFF_SLAVE_NEEDARP:Interface needs ARPs for validation.
142 IFF_ISATAP:Interface is RFC4214 ISATAP interface.
143 .TE
144 .sp
145 Setting the extended (private) interface flags is a privileged operation.
146 .TP
147 .BR SIOCGIFADDR ", " SIOCSIFADDR
148 Get or set the address of the device using
149 .IR ifr_addr .
150 Setting the interface address is a privileged operation.
151 For compatibility, only
152 .B AF_INET
153 addresses are accepted or returned.
154 .TP
155 .BR SIOCGIFDSTADDR ", " SIOCSIFDSTADDR
156 Get or set the destination address of a point-to-point device using
157 .IR ifr_dstaddr .
158 For compatibility, only
159 .B AF_INET
160 addresses are accepted or returned.
161 Setting the destination address is a privileged operation.
162 .TP
163 .BR SIOCGIFBRDADDR ", " SIOCSIFBRDADDR
164 Get or set the broadcast address for a device using
165 .IR ifr_brdaddr .
166 For compatibility, only
167 .B AF_INET
168 addresses are accepted or returned.
169 Setting the broadcast address is a privileged operation.
170 .TP
171 .BR SIOCGIFNETMASK ", " SIOCSIFNETMASK
172 Get or set the network mask for a device using
173 .IR ifr_netmask .
174 For compatibility, only
175 .B AF_INET
176 addresses are accepted or returned.
177 Setting the network mask is a privileged operation.
178 .TP
179 .BR SIOCGIFMETRIC ", " SIOCSIFMETRIC
180 Get or set the metric of the device using
181 .IR ifr_metric .
182 This is currently not implemented; it sets
183 .I ifr_metric
184 to 0 if you attempt to read it and returns
185 .B EOPNOTSUPP
186 if you attempt to set it.
187 .TP
188 .BR SIOCGIFMTU ", " SIOCSIFMTU
189 Get or set the MTU (Maximum Transfer Unit) of a device using
190 .IR ifr_mtu .
191 Setting the MTU is a privileged operation.
192 Setting the MTU to
193 too small values may cause kernel crashes.
194 .TP
195 .BR SIOCGIFHWADDR ", " SIOCSIFHWADDR
196 Get or set the hardware address of a device using
197 .IR ifr_hwaddr .
198 The hardware address is specified in a struct
199 .IR sockaddr .
200 .I sa_family
201 contains the ARPHRD_* device type,
202 .I sa_data
203 the L2 hardware address starting from byte 0.
204 Setting the hardware address is a privileged operation.
205 .TP
206 .B SIOCSIFHWBROADCAST
207 Set the hardware broadcast address of a device from
208 .IR ifr_hwaddr .
209 This is a privileged operation.
210 .TP
211 .BR SIOCGIFMAP ", " SIOCSIFMAP
212 Get or set the interface's hardware parameters using
213 .IR ifr_map .
214 Setting the parameters is a privileged operation.
215
216 .in +4n
217 .nf
218 struct ifmap {
219     unsigned long   mem_start;
220     unsigned long   mem_end;
221     unsigned short  base_addr;
222     unsigned char   irq;
223     unsigned char   dma;
224     unsigned char   port;
225 };
226 .fi
227 .in
228
229 The interpretation of the ifmap structure depends on the device driver
230 and the architecture.
231 .TP
232 .BR SIOCADDMULTI ", " SIOCDELMULTI
233 Add an address to or delete an address from the device's link layer
234 multicast filters using
235 .IR ifr_hwaddr .
236 These are privileged operations.
237 See also
238 .BR packet (7)
239 for an alternative.
240 .TP
241 .BR SIOCGIFTXQLEN ", " SIOCSIFTXQLEN
242 Get or set the transmit queue length of a device using
243 .IR ifr_qlen .
244 Setting the transmit queue length is a privileged operation.
245 .TP
246 .B SIOCSIFNAME
247 Changes the name of the interface specified in
248 .I ifr_name
249 to
250 .IR ifr_newname .
251 This is a privileged operation.
252 It is only allowed when the interface
253 is not up.
254 .TP
255 .B SIOCGIFCONF
256 Return a list of interface (transport layer) addresses.
257 This currently
258 means only addresses of the
259 .B AF_INET
260 (IPv4) family for compatibility.
261 The user passes a
262 .I ifconf
263 structure as argument to the ioctl.
264 It contains a pointer to an array of
265 .I ifreq
266 structures in
267 .I ifc_req
268 and its length in bytes in
269 .IR ifc_len .
270 The kernel fills the ifreqs with all current L3 interface addresses that
271 are running:
272 .I ifr_name
273 contains the interface name (eth0:1 etc.),
274 .I ifr_addr
275 the address.
276 The kernel returns with the actual length in
277 .IR ifc_len .
278 If
279 .I ifc_len
280 is equal to the original length the buffer probably has overflowed
281 and you should retry with a bigger buffer to get all addresses.
282 When no error occurs the ioctl returns 0;
283 otherwise \-1.
284 Overflow is not an error.
285 .\" Slaving isn't supported in 2.2
286 .\" .
287 .\" .TP
288 .\" .BR SIOCGIFSLAVE ", " SIOCSIFSLAVE
289 .\" Get or set the slave device using
290 .\" .IR ifr_slave .
291 .\" Setting the slave device is a privileged operation.
292 .\" .PP
293 .\" FIXME add amateur radio stuff.
294 .PP
295 Most protocols support their own ioctls to configure protocol-specific
296 interface options.
297 See the protocol man pages for a description.
298 For configuring IP addresses see
299 .BR ip (7).
300 .PP
301 In addition some devices support private ioctls.
302 These are not described here.
303 .SH NOTES
304 Strictly speaking,
305 .B SIOCGIFCONF
306 and the other ioctls that only accept or return
307 .B AF_INET
308 socket addresses,
309 are IP specific and belong in
310 .BR ip (7).
311 .LP
312 The names of interfaces with no addresses or that don't have the
313 .B IFF_RUNNING
314 flag set can be found via
315 .IR /proc/net/dev .
316 .LP
317 Local IPv6 IP addresses can be found via
318 .I /proc/net
319 or via
320 .BR rtnetlink (7).
321 .SH BUGS
322 glibc 2.1 is missing the
323 .I ifr_newname
324 macro in
325 .IR <net/if.h> .
326 Add the following to your program as a workaround:
327 .sp
328 .in +4n
329 .nf
330 #ifndef ifr_newname
331 #define ifr_newname     ifr_ifru.ifru_slave
332 #endif
333 .fi
334 .in
335 .SH "SEE ALSO"
336 .BR proc (5),
337 .BR capabilities (7),
338 .BR ip (7),
339 .BR rtnetlink (7)