xref: /xnu-12377.41.6/bsd/net/if.h (revision bbb1b6f9e71b8cdde6e5cd6f4841f207dee3d828)
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 #if __has_ptrcheck
79 #include <netinet/in.h>
80 #endif
81 #include <sys/types.h>
82 #include <sys/socket.h>
83 
84 #endif
85 #endif /* DRIVERKIT */
86 
87 #ifndef IFNAMSIZ
88 #define IFNAMSIZ        IF_NAMESIZE
89 #endif
90 
91 #ifndef DRIVERKIT
92 struct if_clonereq {
93 	int     ifcr_total;             /* total cloners (out) */
94 	int     ifcr_count;             /* room for this many in user buffer */
95 	char    *ifcr_buffer;           /* buffer for cloner names */
96 };
97 
98 #define IFF_UP          0x1             /* interface is up */
99 #define IFF_BROADCAST   0x2             /* broadcast address valid */
100 #define IFF_DEBUG       0x4             /* turn on debugging */
101 #define IFF_LOOPBACK    0x8             /* is a loopback net */
102 #define IFF_POINTOPOINT 0x10            /* interface is point-to-point link */
103 #define IFF_NOTRAILERS  0x20            /* obsolete: avoid use of trailers */
104 #define IFF_RUNNING     0x40            /* resources allocated */
105 #define IFF_NOARP       0x80            /* no address resolution protocol */
106 #define IFF_PROMISC     0x100           /* receive all packets */
107 #define IFF_ALLMULTI    0x200           /* receive all multicast packets */
108 #define IFF_OACTIVE     0x400           /* transmission in progress */
109 #define IFF_SIMPLEX     0x800           /* can't hear own transmissions */
110 #define IFF_LINK0       0x1000          /* per link layer defined bit */
111 #define IFF_LINK1       0x2000          /* per link layer defined bit */
112 #define IFF_LINK2       0x4000          /* per link layer defined bit */
113 #define IFF_ALTPHYS     IFF_LINK2       /* use alternate physical connection */
114 #define IFF_MULTICAST   0x8000          /* supports multicast */
115 
116 #ifdef PRIVATE
117 /* See if_private.h for extended flags */
118 #endif /* PRIVATE */
119 
120 /*
121  * Capabilities that interfaces can advertise.
122  *
123  * struct ifnet.if_capabilities
124  *   contains the optional features & capabilities a particular interface
125  *   supports (not only the driver but also the detected hw revision).
126  *   Capabilities are defined by IFCAP_* below.
127  * struct ifnet.if_capenable
128  *   contains the enabled (either by default or through ifconfig) optional
129  *   features & capabilities on this interface.
130  *   Capabilities are defined by IFCAP_* below.
131  * struct if_data.ifi_hwassist in IFNET_* form, defined in net/kpi_interface.h,
132  *   contains the enabled optional features & capabilites that can be used
133  *   individually per packet and are specified in the mbuf pkthdr.csum_flags
134  *   field.  IFCAP_* and IFNET_* do not match one to one and IFNET_* may be
135  *   more detailed or differentiated than IFCAP_*.
136  *   IFNET_* hwassist flags have corresponding CSUM_* in sys/mbuf.h
137  */
138 #define IFCAP_RXCSUM            0x00001 /* can offload checksum on RX */
139 #define IFCAP_TXCSUM            0x00002 /* can offload checksum on TX */
140 #define IFCAP_VLAN_MTU          0x00004 /* VLAN-compatible MTU */
141 #define IFCAP_VLAN_HWTAGGING    0x00008 /* hardware VLAN tag support */
142 #define IFCAP_JUMBO_MTU         0x00010 /* 9000 byte MTU supported */
143 #define IFCAP_TSO4              0x00020 /* can do TCP Segmentation Offload */
144 #define IFCAP_TSO6              0x00040 /* can do TCP6 Segmentation Offload */
145 #define IFCAP_LRO               0x00080 /* can do Large Receive Offload */
146 #define IFCAP_AV                0x00100 /* can do 802.1 AV Bridging */
147 #define IFCAP_TXSTATUS          0x00200 /* can return linklevel xmit status */
148 #define IFCAP_SKYWALK           0x00400 /* Skywalk mode supported/enabled */
149 #define IFCAP_HW_TIMESTAMP      0x00800 /* Time stamping in hardware */
150 #define IFCAP_SW_TIMESTAMP      0x01000 /* Time stamping in software */
151 #define IFCAP_CSUM_PARTIAL      0x02000 /* can offload partial checksum */
152 #define IFCAP_CSUM_ZERO_INVERT  0x04000 /* can invert 0 to -0 (0xffff) */
153 #define IFCAP_LRO_NUM_SEG       0x08000 /* NIC & driver can set the num of segments a LRO-packet is built of */
154 
155 #define IFCAP_HWCSUM    (IFCAP_RXCSUM | IFCAP_TXCSUM)
156 #define IFCAP_TSO       (IFCAP_TSO4 | IFCAP_TSO6)
157 
158 #define IFCAP_VALID (IFCAP_HWCSUM | IFCAP_TSO | IFCAP_LRO | IFCAP_VLAN_MTU | \
159 	IFCAP_VLAN_HWTAGGING | IFCAP_JUMBO_MTU | IFCAP_AV | IFCAP_TXSTATUS | \
160 	IFCAP_SKYWALK | IFCAP_SW_TIMESTAMP | IFCAP_HW_TIMESTAMP | \
161 	IFCAP_CSUM_PARTIAL | IFCAP_CSUM_ZERO_INVERT | IFCAP_LRO_NUM_SEG)
162 
163 #define IFQ_MAXLEN      128
164 #define IFNET_SLOWHZ    1       /* granularity is 1 second */
165 /*
166  * Message format for use in obtaining information about interfaces
167  * from sysctl and the routing socket
168  */
169 struct if_msghdr {
170 	unsigned short  ifm_msglen;     /* to skip non-understood messages */
171 	unsigned char   ifm_version;    /* future binary compatability */
172 	unsigned char   ifm_type;       /* message type */
173 	int             ifm_addrs;      /* like rtm_addrs */
174 	int             ifm_flags;      /* value of if_flags */
175 	unsigned short  ifm_index;      /* index for associated ifp */
176 	struct  if_data ifm_data;       /* statistics and other data about if */
177 };
178 
179 /*
180  * Message format for use in obtaining information about interface addresses
181  * from sysctl and the routing socket
182  */
183 struct ifa_msghdr {
184 	unsigned short  ifam_msglen;    /* to skip non-understood messages */
185 	unsigned char   ifam_version;   /* future binary compatability */
186 	unsigned char   ifam_type;      /* message type */
187 	int             ifam_addrs;     /* like rtm_addrs */
188 	int             ifam_flags;     /* value of ifa_flags */
189 	unsigned short  ifam_index;     /* index for associated ifp */
190 	int             ifam_metric;    /* value of ifa_metric */
191 };
192 
193 /*
194  * Message format for use in obtaining information about multicast addresses
195  * from the routing socket
196  */
197 struct ifma_msghdr {
198 	unsigned short  ifmam_msglen;   /* to skip non-understood messages */
199 	unsigned char   ifmam_version;  /* future binary compatability */
200 	unsigned char   ifmam_type;     /* message type */
201 	int             ifmam_addrs;    /* like rtm_addrs */
202 	int             ifmam_flags;    /* value of ifa_flags */
203 	unsigned short  ifmam_index;    /* index for associated ifp */
204 };
205 
206 /*
207  * Message format for use in obtaining information about interfaces
208  * from sysctl
209  */
210 struct if_msghdr2 {
211 	u_short ifm_msglen;     /* to skip over non-understood messages */
212 	u_char  ifm_version;    /* future binary compatability */
213 	u_char  ifm_type;       /* message type */
214 	int     ifm_addrs;      /* like rtm_addrs */
215 	int     ifm_flags;      /* value of if_flags */
216 	u_short ifm_index;      /* index for associated ifp */
217 	int     ifm_snd_len;    /* instantaneous length of send queue */
218 	int     ifm_snd_maxlen; /* maximum length of send queue */
219 	int     ifm_snd_drops;  /* number of drops in send queue */
220 	int     ifm_timer;      /* time until if_watchdog called */
221 	struct if_data64        ifm_data;       /* statistics and other data */
222 };
223 
224 /*
225  * Message format for use in obtaining information about multicast addresses
226  * from sysctl
227  */
228 struct ifma_msghdr2 {
229 	u_short ifmam_msglen;   /* to skip over non-understood messages */
230 	u_char  ifmam_version;  /* future binary compatability */
231 	u_char  ifmam_type;     /* message type */
232 	int     ifmam_addrs;    /* like rtm_addrs */
233 	int     ifmam_flags;    /* value of ifa_flags */
234 	u_short ifmam_index;    /* index for associated ifp */
235 	int32_t ifmam_refcount;
236 };
237 
238 /*
239  * ifdevmtu: interface device mtu
240  *    Used with SIOCGIFDEVMTU to get the current mtu in use by the device,
241  *    as well as the minimum and maximum mtu allowed by the device.
242  */
243 struct ifdevmtu {
244 	int     ifdm_current;
245 	int     ifdm_min;
246 	int     ifdm_max;
247 };
248 
249 #pragma pack(4)
250 
251 /*
252  *  ifkpi: interface kpi ioctl
253  *  Used with SIOCSIFKPI and SIOCGIFKPI.
254  *
255  *  ifk_module_id - From in the kernel, a value from kev_vendor_code_find. From
256  *       user space, a value from SIOCGKEVVENDOR ioctl on a kernel event socket.
257  *  ifk_type - The type. Types are specific to each module id.
258  *  ifk_data - The data. ifk_ptr may be a 64bit pointer for 64 bit processes.
259  *
260  *  Copying data between user space and kernel space is done using copyin
261  *  and copyout. A process may be running in 64bit mode. In such a case,
262  *  the pointer will be a 64bit pointer, not a 32bit pointer. The following
263  *  sample is a safe way to copy the data in to the kernel from either a
264  *  32bit or 64bit process:
265  *
266  *  user_addr_t tmp_ptr;
267  *  if (IS_64BIT_PROCESS(current_proc())) {
268  *       tmp_ptr = CAST_USER_ADDR_T(ifkpi.ifk_data.ifk_ptr64);
269  *  }
270  *  else {
271  *       tmp_ptr = CAST_USER_ADDR_T(ifkpi.ifk_data.ifk_ptr);
272  *  }
273  *  error = copyin(tmp_ptr, allocated_dst_buffer, size of allocated_dst_buffer);
274  */
275 
276 struct ifkpi {
277 	unsigned int    ifk_module_id;
278 	unsigned int    ifk_type;
279 	union {
280 		void            *ifk_ptr;
281 		int             ifk_value;
282 #ifdef KERNEL
283 		u_int64_t       ifk_ptr64;
284 #endif /* KERNEL */
285 	} ifk_data;
286 };
287 
288 /* Wake capabilities of a interface */
289 #define IF_WAKE_ON_MAGIC_PACKET         0x01
290 
291 
292 #pragma pack()
293 
294 #ifdef PRIVATE
295 /*
296  * IFREQ_OPAQUE means that ifreq is an opaque structure
297  * in the public header, and redeclared in if_private.h.
298  */
299 #define IFREQ_OPAQUE
300 #endif /* PRIVATE */
301 
302 /*
303  * Interface request structure used for socket
304  * ioctl's.  All interface ioctl's must have parameter
305  * definitions which begin with ifr_name.  The
306  * remainder may be interface specific.
307  */
308 #ifdef IFREQ_OPAQUE
309 struct  ifreq;
310 #else
311 #ifdef PRIVATE
312 /*
313  * This is the public version of the ifreq structure, the
314  * private version lives in if_private.h. If you make any
315  * changes here, you must also make them in if_private.h!
316  */
317 #endif
318 struct  ifreq {
319 	char    ifr_name[IFNAMSIZ];             /* if name, e.g. "en0" */
320 	union {
321 		struct  sockaddr ifru_addr;
322 		struct  sockaddr ifru_dstaddr;
323 		struct  sockaddr ifru_broadaddr;
324 		short   ifru_flags;
325 		int     ifru_metric;
326 		int     ifru_mtu;
327 		int     ifru_phys;
328 		int     ifru_media;
329 		int     ifru_intval;
330 		caddr_t ifru_data;
331 		struct  ifdevmtu ifru_devmtu;
332 		struct  ifkpi   ifru_kpi;
333 		u_int32_t ifru_wake_flags;
334 		u_int32_t ifru_route_refcnt;
335 		int     ifru_cap[2];
336 		u_int32_t ifru_functional_type;
337 		u_int32_t ifru_peer_egress_functional_type;
338 #define IFRTYPE_FUNCTIONAL_UNKNOWN              0
339 #define IFRTYPE_FUNCTIONAL_LOOPBACK             1
340 #define IFRTYPE_FUNCTIONAL_WIRED                2
341 #define IFRTYPE_FUNCTIONAL_WIFI_INFRA           3
342 #define IFRTYPE_FUNCTIONAL_WIFI_AWDL            4
343 #define IFRTYPE_FUNCTIONAL_CELLULAR             5
344 #define IFRTYPE_FUNCTIONAL_INTCOPROC            6
345 #define IFRTYPE_FUNCTIONAL_COMPANIONLINK        7
346 #define IFRTYPE_FUNCTIONAL_MANAGEMENT           8
347 #define IFRTYPE_FUNCTIONAL_LAST                 8
348 		u_int8_t ifru_is_directlink;
349 		u_int8_t ifru_is_vpn;
350 		u_int8_t ifru_is_companionlink;
351 	} ifr_ifru;
352 #define ifr_addr        ifr_ifru.ifru_addr      /* address */
353 #define ifr_dstaddr     ifr_ifru.ifru_dstaddr   /* other end of p-to-p link */
354 #define ifr_broadaddr   ifr_ifru.ifru_broadaddr /* broadcast address */
355 #ifdef __APPLE__
356 #define ifr_flags       ifr_ifru.ifru_flags     /* flags */
357 #else
358 #define ifr_flags       ifr_ifru.ifru_flags[0]  /* flags */
359 #define ifr_prevflags   ifr_ifru.ifru_flags[1]  /* flags */
360 #endif /* __APPLE__ */
361 #define ifr_metric      ifr_ifru.ifru_metric    /* metric */
362 #define ifr_mtu         ifr_ifru.ifru_mtu       /* mtu */
363 #define ifr_phys        ifr_ifru.ifru_phys      /* physical wire */
364 #define ifr_media       ifr_ifru.ifru_media     /* physical media */
365 #define ifr_data        ifr_ifru.ifru_data      /* for use by interface */
366 #define ifr_devmtu      ifr_ifru.ifru_devmtu
367 #define ifr_intval      ifr_ifru.ifru_intval    /* integer value */
368 #define ifr_kpi         ifr_ifru.ifru_kpi
369 #define ifr_wake_flags  ifr_ifru.ifru_wake_flags /* wake capabilities */
370 #define ifr_route_refcnt ifr_ifru.ifru_route_refcnt /* route references count */
371 #define ifr_reqcap      ifr_ifru.ifru_cap[0]    /* requested capabilities */
372 #define ifr_curcap      ifr_ifru.ifru_cap[1]    /* current capabilities */
373 };
374 
375 #define _SIZEOF_ADDR_IFREQ(ifr) \
376 	((ifr).ifr_addr.sa_len > sizeof (struct sockaddr) ? \
377 	(sizeof (struct ifreq) - sizeof (struct sockaddr) + \
378 	(ifr).ifr_addr.sa_len) : sizeof (struct ifreq))
379 #endif /* IFREQ_OPAQUE */
380 
381 struct ifaliasreq {
382 	char    ifra_name[IFNAMSIZ];            /* if name, e.g. "en0" */
383 #if __has_ptrcheck
384 	struct  sockaddr_in ifra_addr;
385 	struct  sockaddr_in ifra_broadaddr;
386 	struct  sockaddr_in ifra_mask;
387 #else
388 	struct  sockaddr ifra_addr;
389 	struct  sockaddr ifra_broadaddr;
390 	struct  sockaddr ifra_mask;
391 #endif /* __has_ptrcheck */
392 };
393 
394 struct rslvmulti_req {
395 	struct sockaddr *sa;
396 	struct sockaddr **llsa;
397 };
398 
399 #if !defined(KERNEL) || defined(KERNEL_PRIVATE)
400 #pragma pack(4)
401 
402 struct ifmediareq {
403 	char    ifm_name[IFNAMSIZ];     /* if name, e.g. "en0" */
404 	int     ifm_current;            /* current media options */
405 	int     ifm_mask;               /* don't care mask */
406 	int     ifm_status;             /* media status */
407 	int     ifm_active;             /* active options */
408 	int     ifm_count;              /* # entries in ifm_ulist array */
409 	int     *ifm_ulist;             /* media words */
410 };
411 
412 #pragma pack()
413 #endif /* !KERNEL || KERNEL_PRIVATE */
414 
415 #endif /* DRIVERKIT */
416 
417 #pragma pack(4)
418 struct  ifdrv {
419 	char            ifd_name[IFNAMSIZ];     /* if name, e.g. "en0" */
420 	unsigned long   ifd_cmd;
421 	size_t          ifd_len;                /* length of ifd_data buffer */
422 	void            *ifd_data;
423 };
424 #pragma pack()
425 
426 #ifndef DRIVERKIT
427 
428 /*
429  * Structure used to retrieve aux status data from interfaces.
430  * Kernel suppliers to this interface should respect the formatting
431  * needed by ifconfig(8): each line starts with a TAB and ends with
432  * a newline.
433  */
434 
435 #define IFSTATMAX       800             /* 10 lines of text */
436 struct ifstat {
437 	char    ifs_name[IFNAMSIZ];     /* if name, e.g. "en0" */
438 	char    ascii[IFSTATMAX + 1];
439 };
440 
441 #if !defined(KERNEL) || defined(KERNEL_PRIVATE)
442 /*
443  * Structure used in SIOCGIFCONF request.
444  * Used to retrieve interface configuration
445  * for machine (useful for programs which
446  * must know all networks accessible).
447  */
448 #pragma pack(4)
449 struct  ifconf {
450 	int     ifc_len;                /* size of associated buffer */
451 	union {
452 		caddr_t ifcu_buf;
453 		struct  ifreq *ifcu_req;
454 	} ifc_ifcu;
455 };
456 #pragma pack()
457 #define ifc_buf ifc_ifcu.ifcu_buf       /* buffer address */
458 #define ifc_req ifc_ifcu.ifcu_req       /* array of structures returned */
459 #endif /* !KERNEL || KERNEL_PRIVATE */
460 
461 /*
462  * DLIL KEV_DL_PROTO_ATTACHED/DETACHED structure
463  */
464 struct kev_dl_proto_data {
465 	struct net_event_data           link_data;
466 	u_int32_t                       proto_family;
467 	u_int32_t                       proto_remaining_count;
468 };
469 
470 #ifdef KERNEL
471 #ifdef MALLOC_DECLARE
472 MALLOC_DECLARE(M_IFADDR);
473 #endif
474 #endif
475 #endif /* DRIVERKIT */
476 #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
477 
478 #ifndef DRIVERKIT
479 #ifndef KERNEL
480 struct if_nameindex {
481 	unsigned int     if_index;      /* 1, 2, ... */
482 	char            *if_name;       /* null terminated name: "le0", ... */
483 };
484 
485 __BEGIN_DECLS
486 unsigned int     if_nametoindex(const char *);
487 char            *if_indextoname(unsigned int, char *);
488 struct           if_nameindex *if_nameindex(void);
489 void             if_freenameindex(struct if_nameindex *);
490 __END_DECLS
491 #endif /* KERNEL */
492 #endif /* DRIVERKIT */
493 
494 #ifdef KERNEL
495 #include <net/kpi_interface.h>
496 #endif
497 
498 #ifdef PRIVATE
499 #include <net/if_private.h>
500 #endif /* PRIVATE */
501 
502 #endif /* !_NET_IF_H_ */
503