xref: /xnu-8792.61.2/bsd/net/if.h (revision 42e220869062b56f8d7d0726fd4c88954f87902c)
1 /*
2  * Copyright (c) 2000-2021 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
6  * This file contains Original Code and/or Modifications of Original Code
7  * as defined in and that are subject to the Apple Public Source License
8  * Version 2.0 (the 'License'). You may not use this file except in
9  * compliance with the License. The rights granted to you under the License
10  * may not be used to create, or enable the creation or redistribution of,
11  * unlawful or unlicensed copies of an Apple operating system, or to
12  * circumvent, violate, or enable the circumvention or violation of, any
13  * terms of an Apple operating system software license agreement.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
18  * The Original Code and all software distributed under the License are
19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23  * Please see the License for the specific language governing rights and
24  * limitations under the License.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 /*
29  * Copyright (c) 1982, 1986, 1989, 1993
30  *	The Regents of the University of California.  All rights reserved.
31  *
32  * Redistribution and use in source and binary forms, with or without
33  * modification, are permitted provided that the following conditions
34  * are met:
35  * 1. Redistributions of source code must retain the above copyright
36  *    notice, this list of conditions and the following disclaimer.
37  * 2. Redistributions in binary form must reproduce the above copyright
38  *    notice, this list of conditions and the following disclaimer in the
39  *    documentation and/or other materials provided with the distribution.
40  * 3. All advertising materials mentioning features or use of this software
41  *    must display the following acknowledgement:
42  *	This product includes software developed by the University of
43  *	California, Berkeley and its contributors.
44  * 4. Neither the name of the University nor the names of its contributors
45  *    may be used to endorse or promote products derived from this software
46  *    without specific prior written permission.
47  *
48  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58  * SUCH DAMAGE.
59  *
60  *	@(#)if.h	8.1 (Berkeley) 6/10/93
61  */
62 
63 #ifndef _NET_IF_H_
64 #define _NET_IF_H_
65 
66 #define IF_NAMESIZE     16
67 
68 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
69 #ifdef DRIVERKIT
70 #include <stddef.h>
71 #else
72 #include <sys/cdefs.h>
73 #include <sys/appleapiopts.h>
74 #ifdef __APPLE__
75 
76 #include <net/if_var.h>
77 #include <net/net_kev.h>
78 #include <sys/types.h>
79 #include <sys/socket.h>
80 
81 #endif
82 #endif /* DRIVERKIT */
83 
84 #ifndef IFNAMSIZ
85 #define IFNAMSIZ        IF_NAMESIZE
86 #endif
87 
88 #ifndef DRIVERKIT
89 struct if_clonereq {
90 	int     ifcr_total;             /* total cloners (out) */
91 	int     ifcr_count;             /* room for this many in user buffer */
92 	char    *ifcr_buffer;           /* buffer for cloner names */
93 };
94 
95 #define IFF_UP          0x1             /* interface is up */
96 #define IFF_BROADCAST   0x2             /* broadcast address valid */
97 #define IFF_DEBUG       0x4             /* turn on debugging */
98 #define IFF_LOOPBACK    0x8             /* is a loopback net */
99 #define IFF_POINTOPOINT 0x10            /* interface is point-to-point link */
100 #define IFF_NOTRAILERS  0x20            /* obsolete: avoid use of trailers */
101 #define IFF_RUNNING     0x40            /* resources allocated */
102 #define IFF_NOARP       0x80            /* no address resolution protocol */
103 #define IFF_PROMISC     0x100           /* receive all packets */
104 #define IFF_ALLMULTI    0x200           /* receive all multicast packets */
105 #define IFF_OACTIVE     0x400           /* transmission in progress */
106 #define IFF_SIMPLEX     0x800           /* can't hear own transmissions */
107 #define IFF_LINK0       0x1000          /* per link layer defined bit */
108 #define IFF_LINK1       0x2000          /* per link layer defined bit */
109 #define IFF_LINK2       0x4000          /* per link layer defined bit */
110 #define IFF_ALTPHYS     IFF_LINK2       /* use alternate physical connection */
111 #define IFF_MULTICAST   0x8000          /* supports multicast */
112 
113 #ifdef PRIVATE
114 /* See if_private.h for extended flags */
115 #endif /* PRIVATE */
116 
117 /*
118  * Capabilities that interfaces can advertise.
119  *
120  * struct ifnet.if_capabilities
121  *   contains the optional features & capabilities a particular interface
122  *   supports (not only the driver but also the detected hw revision).
123  *   Capabilities are defined by IFCAP_* below.
124  * struct ifnet.if_capenable
125  *   contains the enabled (either by default or through ifconfig) optional
126  *   features & capabilities on this interface.
127  *   Capabilities are defined by IFCAP_* below.
128  * struct if_data.ifi_hwassist in IFNET_* form, defined in net/kpi_interface.h,
129  *   contains the enabled optional features & capabilites that can be used
130  *   individually per packet and are specified in the mbuf pkthdr.csum_flags
131  *   field.  IFCAP_* and IFNET_* do not match one to one and IFNET_* may be
132  *   more detailed or differentiated than IFCAP_*.
133  *   IFNET_* hwassist flags have corresponding CSUM_* in sys/mbuf.h
134  */
135 #define IFCAP_RXCSUM            0x00001 /* can offload checksum on RX */
136 #define IFCAP_TXCSUM            0x00002 /* can offload checksum on TX */
137 #define IFCAP_VLAN_MTU          0x00004 /* VLAN-compatible MTU */
138 #define IFCAP_VLAN_HWTAGGING    0x00008 /* hardware VLAN tag support */
139 #define IFCAP_JUMBO_MTU         0x00010 /* 9000 byte MTU supported */
140 #define IFCAP_TSO4              0x00020 /* can do TCP Segmentation Offload */
141 #define IFCAP_TSO6              0x00040 /* can do TCP6 Segmentation Offload */
142 #define IFCAP_LRO               0x00080 /* can do Large Receive Offload */
143 #define IFCAP_AV                0x00100 /* can do 802.1 AV Bridging */
144 #define IFCAP_TXSTATUS          0x00200 /* can return linklevel xmit status */
145 #define IFCAP_SKYWALK           0x00400 /* Skywalk mode supported/enabled */
146 #define IFCAP_HW_TIMESTAMP      0x00800 /* Time stamping in hardware */
147 #define IFCAP_SW_TIMESTAMP      0x01000 /* Time stamping in software */
148 #define IFCAP_CSUM_PARTIAL      0x02000 /* can offload partial checksum */
149 #define IFCAP_CSUM_ZERO_INVERT  0x04000 /* can invert 0 to -0 (0xffff) */
150 
151 #define IFCAP_HWCSUM    (IFCAP_RXCSUM | IFCAP_TXCSUM)
152 #define IFCAP_TSO       (IFCAP_TSO4 | IFCAP_TSO6)
153 
154 #define IFCAP_VALID (IFCAP_HWCSUM | IFCAP_TSO | IFCAP_LRO | IFCAP_VLAN_MTU | \
155 	IFCAP_VLAN_HWTAGGING | IFCAP_JUMBO_MTU | IFCAP_AV | IFCAP_TXSTATUS | \
156 	IFCAP_SKYWALK | IFCAP_SW_TIMESTAMP | IFCAP_HW_TIMESTAMP | \
157 	IFCAP_CSUM_PARTIAL | IFCAP_CSUM_ZERO_INVERT)
158 
159 #define IFQ_MAXLEN      128
160 #define IFNET_SLOWHZ    1       /* granularity is 1 second */
161 #define IFQ_DEF_C_TARGET_DELAY        (10ULL * 1000 * 1000)   /* 10 ms */
162 #define IFQ_DEF_C_UPDATE_INTERVAL     (100ULL * 1000 * 1000)  /* 100 ms */
163 #define IFQ_DEF_L4S_TARGET_DELAY        (2ULL * 1000 * 1000)   /* 2 ms */
164 #define IFQ_DEF_L4S_UPDATE_INTERVAL     (100ULL * 1000 * 1000)  /* 100 ms */
165 #define IFQ_LL_C_TARGET_DELAY     (10ULL * 1000 * 1000)   /* 10 ms */
166 #define IFQ_LL_C_UPDATE_INTERVAL  (100ULL * 1000 * 1000)  /* 100 ms */
167 #define IFQ_LL_L4S_TARGET_DELAY     (10ULL * 1000 * 1000)   /* 10 ms */
168 #define IFQ_LL_L4S_UPDATE_INTERVAL  (100ULL * 1000 * 1000)  /* 100 ms */
169 /*
170  * Message format for use in obtaining information about interfaces
171  * from sysctl and the routing socket
172  */
173 struct if_msghdr {
174 	unsigned short  ifm_msglen;     /* to skip non-understood messages */
175 	unsigned char   ifm_version;    /* future binary compatability */
176 	unsigned char   ifm_type;       /* message type */
177 	int             ifm_addrs;      /* like rtm_addrs */
178 	int             ifm_flags;      /* value of if_flags */
179 	unsigned short  ifm_index;      /* index for associated ifp */
180 	struct  if_data ifm_data;       /* statistics and other data about if */
181 };
182 
183 /*
184  * Message format for use in obtaining information about interface addresses
185  * from sysctl and the routing socket
186  */
187 struct ifa_msghdr {
188 	unsigned short  ifam_msglen;    /* to skip non-understood messages */
189 	unsigned char   ifam_version;   /* future binary compatability */
190 	unsigned char   ifam_type;      /* message type */
191 	int             ifam_addrs;     /* like rtm_addrs */
192 	int             ifam_flags;     /* value of ifa_flags */
193 	unsigned short  ifam_index;     /* index for associated ifp */
194 	int             ifam_metric;    /* value of ifa_metric */
195 };
196 
197 /*
198  * Message format for use in obtaining information about multicast addresses
199  * from the routing socket
200  */
201 struct ifma_msghdr {
202 	unsigned short  ifmam_msglen;   /* to skip non-understood messages */
203 	unsigned char   ifmam_version;  /* future binary compatability */
204 	unsigned char   ifmam_type;     /* message type */
205 	int             ifmam_addrs;    /* like rtm_addrs */
206 	int             ifmam_flags;    /* value of ifa_flags */
207 	unsigned short  ifmam_index;    /* index for associated ifp */
208 };
209 
210 /*
211  * Message format for use in obtaining information about interfaces
212  * from sysctl
213  */
214 struct if_msghdr2 {
215 	u_short ifm_msglen;     /* to skip over non-understood messages */
216 	u_char  ifm_version;    /* future binary compatability */
217 	u_char  ifm_type;       /* message type */
218 	int     ifm_addrs;      /* like rtm_addrs */
219 	int     ifm_flags;      /* value of if_flags */
220 	u_short ifm_index;      /* index for associated ifp */
221 	int     ifm_snd_len;    /* instantaneous length of send queue */
222 	int     ifm_snd_maxlen; /* maximum length of send queue */
223 	int     ifm_snd_drops;  /* number of drops in send queue */
224 	int     ifm_timer;      /* time until if_watchdog called */
225 	struct if_data64        ifm_data;       /* statistics and other data */
226 };
227 
228 /*
229  * Message format for use in obtaining information about multicast addresses
230  * from sysctl
231  */
232 struct ifma_msghdr2 {
233 	u_short ifmam_msglen;   /* to skip over non-understood messages */
234 	u_char  ifmam_version;  /* future binary compatability */
235 	u_char  ifmam_type;     /* message type */
236 	int     ifmam_addrs;    /* like rtm_addrs */
237 	int     ifmam_flags;    /* value of ifa_flags */
238 	u_short ifmam_index;    /* index for associated ifp */
239 	int32_t ifmam_refcount;
240 };
241 
242 /*
243  * ifdevmtu: interface device mtu
244  *    Used with SIOCGIFDEVMTU to get the current mtu in use by the device,
245  *    as well as the minimum and maximum mtu allowed by the device.
246  */
247 struct ifdevmtu {
248 	int     ifdm_current;
249 	int     ifdm_min;
250 	int     ifdm_max;
251 };
252 
253 #pragma pack(4)
254 
255 /*
256  *  ifkpi: interface kpi ioctl
257  *  Used with SIOCSIFKPI and SIOCGIFKPI.
258  *
259  *  ifk_module_id - From in the kernel, a value from kev_vendor_code_find. From
260  *       user space, a value from SIOCGKEVVENDOR ioctl on a kernel event socket.
261  *  ifk_type - The type. Types are specific to each module id.
262  *  ifk_data - The data. ifk_ptr may be a 64bit pointer for 64 bit processes.
263  *
264  *  Copying data between user space and kernel space is done using copyin
265  *  and copyout. A process may be running in 64bit mode. In such a case,
266  *  the pointer will be a 64bit pointer, not a 32bit pointer. The following
267  *  sample is a safe way to copy the data in to the kernel from either a
268  *  32bit or 64bit process:
269  *
270  *  user_addr_t tmp_ptr;
271  *  if (IS_64BIT_PROCESS(current_proc())) {
272  *       tmp_ptr = CAST_USER_ADDR_T(ifkpi.ifk_data.ifk_ptr64);
273  *  }
274  *  else {
275  *       tmp_ptr = CAST_USER_ADDR_T(ifkpi.ifk_data.ifk_ptr);
276  *  }
277  *  error = copyin(tmp_ptr, allocated_dst_buffer, size of allocated_dst_buffer);
278  */
279 
280 struct ifkpi {
281 	unsigned int    ifk_module_id;
282 	unsigned int    ifk_type;
283 	union {
284 		void            *ifk_ptr;
285 		int             ifk_value;
286 #ifdef KERNEL
287 		u_int64_t       ifk_ptr64;
288 #endif /* KERNEL */
289 	} ifk_data;
290 };
291 
292 /* Wake capabilities of a interface */
293 #define IF_WAKE_ON_MAGIC_PACKET         0x01
294 
295 
296 #pragma pack()
297 
298 #ifdef PRIVATE
299 /*
300  * IFREQ_OPAQUE means that ifreq is an opaque structure
301  * in the public header, and redeclared in if_private.h.
302  */
303 #define IFREQ_OPAQUE
304 #endif /* PRIVATE */
305 
306 /*
307  * Interface request structure used for socket
308  * ioctl's.  All interface ioctl's must have parameter
309  * definitions which begin with ifr_name.  The
310  * remainder may be interface specific.
311  */
312 #ifdef IFREQ_OPAQUE
313 struct  ifreq;
314 #else
315 #ifdef PRIVATE
316 /*
317  * This is the public version of the ifreq structure, the
318  * private version lives in if_private.h. If you make any
319  * changes here, you must also make them in if_private.h!
320  */
321 #endif
322 struct  ifreq {
323 	char    ifr_name[IFNAMSIZ];             /* if name, e.g. "en0" */
324 	union {
325 		struct  sockaddr ifru_addr;
326 		struct  sockaddr ifru_dstaddr;
327 		struct  sockaddr ifru_broadaddr;
328 		short   ifru_flags;
329 		int     ifru_metric;
330 		int     ifru_mtu;
331 		int     ifru_phys;
332 		int     ifru_media;
333 		int     ifru_intval;
334 		caddr_t ifru_data;
335 		struct  ifdevmtu ifru_devmtu;
336 		struct  ifkpi   ifru_kpi;
337 		u_int32_t ifru_wake_flags;
338 		u_int32_t ifru_route_refcnt;
339 		int     ifru_cap[2];
340 		u_int32_t ifru_functional_type;
341 #define IFRTYPE_FUNCTIONAL_UNKNOWN              0
342 #define IFRTYPE_FUNCTIONAL_LOOPBACK             1
343 #define IFRTYPE_FUNCTIONAL_WIRED                2
344 #define IFRTYPE_FUNCTIONAL_WIFI_INFRA           3
345 #define IFRTYPE_FUNCTIONAL_WIFI_AWDL            4
346 #define IFRTYPE_FUNCTIONAL_CELLULAR             5
347 #define IFRTYPE_FUNCTIONAL_INTCOPROC            6
348 #define IFRTYPE_FUNCTIONAL_COMPANIONLINK        7
349 #define IFRTYPE_FUNCTIONAL_LAST                 7
350 	} ifr_ifru;
351 #define ifr_addr        ifr_ifru.ifru_addr      /* address */
352 #define ifr_dstaddr     ifr_ifru.ifru_dstaddr   /* other end of p-to-p link */
353 #define ifr_broadaddr   ifr_ifru.ifru_broadaddr /* broadcast address */
354 #ifdef __APPLE__
355 #define ifr_flags       ifr_ifru.ifru_flags     /* flags */
356 #else
357 #define ifr_flags       ifr_ifru.ifru_flags[0]  /* flags */
358 #define ifr_prevflags   ifr_ifru.ifru_flags[1]  /* flags */
359 #endif /* __APPLE__ */
360 #define ifr_metric      ifr_ifru.ifru_metric    /* metric */
361 #define ifr_mtu         ifr_ifru.ifru_mtu       /* mtu */
362 #define ifr_phys        ifr_ifru.ifru_phys      /* physical wire */
363 #define ifr_media       ifr_ifru.ifru_media     /* physical media */
364 #define ifr_data        ifr_ifru.ifru_data      /* for use by interface */
365 #define ifr_devmtu      ifr_ifru.ifru_devmtu
366 #define ifr_intval      ifr_ifru.ifru_intval    /* integer value */
367 #define ifr_kpi         ifr_ifru.ifru_kpi
368 #define ifr_wake_flags  ifr_ifru.ifru_wake_flags /* wake capabilities */
369 #define ifr_route_refcnt ifr_ifru.ifru_route_refcnt /* route references count */
370 #define ifr_reqcap      ifr_ifru.ifru_cap[0]    /* requested capabilities */
371 #define ifr_curcap      ifr_ifru.ifru_cap[1]    /* current capabilities */
372 };
373 
374 #define _SIZEOF_ADDR_IFREQ(ifr) \
375 	((ifr).ifr_addr.sa_len > sizeof (struct sockaddr) ? \
376 	(sizeof (struct ifreq) - sizeof (struct sockaddr) + \
377 	(ifr).ifr_addr.sa_len) : sizeof (struct ifreq))
378 #endif /* IFREQ_OPAQUE */
379 
380 struct ifaliasreq {
381 	char    ifra_name[IFNAMSIZ];            /* if name, e.g. "en0" */
382 #if __has_ptrcheck
383 	struct  sockaddr_in ifra_addr;
384 	struct  sockaddr_in ifra_broadaddr;
385 	struct  sockaddr_in ifra_mask;
386 #else
387 	struct  sockaddr ifra_addr;
388 	struct  sockaddr ifra_broadaddr;
389 	struct  sockaddr ifra_mask;
390 #endif /* __has_ptrcheck */
391 };
392 
393 struct rslvmulti_req {
394 	struct sockaddr *sa;
395 	struct sockaddr **llsa;
396 };
397 
398 #if !defined(KERNEL) || defined(KERNEL_PRIVATE)
399 #pragma pack(4)
400 
401 struct ifmediareq {
402 	char    ifm_name[IFNAMSIZ];     /* if name, e.g. "en0" */
403 	int     ifm_current;            /* current media options */
404 	int     ifm_mask;               /* don't care mask */
405 	int     ifm_status;             /* media status */
406 	int     ifm_active;             /* active options */
407 	int     ifm_count;              /* # entries in ifm_ulist array */
408 	int     *ifm_ulist;             /* media words */
409 };
410 
411 #pragma pack()
412 #endif /* !KERNEL || KERNEL_PRIVATE */
413 
414 #endif /* DRIVERKIT */
415 
416 #pragma pack(4)
417 struct  ifdrv {
418 	char            ifd_name[IFNAMSIZ];     /* if name, e.g. "en0" */
419 	unsigned long   ifd_cmd;
420 	size_t          ifd_len;                /* length of ifd_data buffer */
421 	void            *ifd_data;
422 };
423 #pragma pack()
424 
425 #ifndef DRIVERKIT
426 
427 /*
428  * Structure used to retrieve aux status data from interfaces.
429  * Kernel suppliers to this interface should respect the formatting
430  * needed by ifconfig(8): each line starts with a TAB and ends with
431  * a newline.
432  */
433 
434 #define IFSTATMAX       800             /* 10 lines of text */
435 struct ifstat {
436 	char    ifs_name[IFNAMSIZ];     /* if name, e.g. "en0" */
437 	char    ascii[IFSTATMAX + 1];
438 };
439 
440 #if !defined(KERNEL) || defined(KERNEL_PRIVATE)
441 /*
442  * Structure used in SIOCGIFCONF request.
443  * Used to retrieve interface configuration
444  * for machine (useful for programs which
445  * must know all networks accessible).
446  */
447 #pragma pack(4)
448 struct  ifconf {
449 	int     ifc_len;                /* size of associated buffer */
450 	union {
451 		caddr_t ifcu_buf;
452 		struct  ifreq *ifcu_req;
453 	} ifc_ifcu;
454 };
455 #pragma pack()
456 #define ifc_buf ifc_ifcu.ifcu_buf       /* buffer address */
457 #define ifc_req ifc_ifcu.ifcu_req       /* array of structures returned */
458 #endif /* !KERNEL || KERNEL_PRIVATE */
459 
460 /*
461  * DLIL KEV_DL_PROTO_ATTACHED/DETACHED structure
462  */
463 struct kev_dl_proto_data {
464 	struct net_event_data           link_data;
465 	u_int32_t                       proto_family;
466 	u_int32_t                       proto_remaining_count;
467 };
468 
469 #ifdef KERNEL
470 #ifdef MALLOC_DECLARE
471 MALLOC_DECLARE(M_IFADDR);
472 #endif
473 #endif
474 #endif /* DRIVERKIT */
475 #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
476 
477 #ifndef DRIVERKIT
478 #ifndef KERNEL
479 struct if_nameindex {
480 	unsigned int     if_index;      /* 1, 2, ... */
481 	char            *if_name;       /* null terminated name: "le0", ... */
482 };
483 
484 __BEGIN_DECLS
485 unsigned int     if_nametoindex(const char *);
486 char            *if_indextoname(unsigned int, char *);
487 struct           if_nameindex *if_nameindex(void);
488 void             if_freenameindex(struct if_nameindex *);
489 __END_DECLS
490 #endif /* KERNEL */
491 #endif /* DRIVERKIT */
492 
493 #ifdef KERNEL
494 #include <net/kpi_interface.h>
495 #endif
496 
497 #ifdef PRIVATE
498 #include <net/if_private.h>
499 #endif /* PRIVATE */
500 
501 #endif /* !_NET_IF_H_ */
502