]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/if_var.h
xnu-1504.15.3.tar.gz
[apple/xnu.git] / bsd / net / if_var.h
1 /*
2 * Copyright (c) 2000-2010 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 * From: @(#)if.h 8.1 (Berkeley) 6/10/93
61 * $FreeBSD: src/sys/net/if_var.h,v 1.18.2.7 2001/07/24 19:10:18 brooks Exp $
62 */
63
64 #ifndef _NET_IF_VAR_H_
65 #define _NET_IF_VAR_H_
66
67 #include <sys/appleapiopts.h>
68 #include <stdint.h>
69 #include <sys/types.h>
70 #include <sys/time.h>
71 #include <sys/queue.h> /* get TAILQ macros */
72 #ifdef KERNEL_PRIVATE
73 #include <kern/locks.h>
74 #endif /* KERNEL_PRIVATE */
75 #ifdef PRIVATE
76 #include <net/route.h>
77 #endif
78
79 #ifdef KERNEL
80 #include <net/kpi_interface.h>
81 #endif /* KERNEL */
82
83 #ifdef __APPLE__
84 #define APPLE_IF_FAM_LOOPBACK 1
85 #define APPLE_IF_FAM_ETHERNET 2
86 #define APPLE_IF_FAM_SLIP 3
87 #define APPLE_IF_FAM_TUN 4
88 #define APPLE_IF_FAM_VLAN 5
89 #define APPLE_IF_FAM_PPP 6
90 #define APPLE_IF_FAM_PVC 7
91 #define APPLE_IF_FAM_DISC 8
92 #define APPLE_IF_FAM_MDECAP 9
93 #define APPLE_IF_FAM_GIF 10
94 #define APPLE_IF_FAM_FAITH 11
95 #define APPLE_IF_FAM_STF 12
96 #define APPLE_IF_FAM_FIREWIRE 13
97 #define APPLE_IF_FAM_BOND 14
98 #endif /* __APPLE__ */
99
100 /*
101 * 72 was chosen below because it is the size of a TCP/IP
102 * header (40) + the minimum mss (32).
103 */
104 #define IF_MINMTU 72
105 #define IF_MAXMTU 65535
106
107 /*
108 * Structures defining a network interface, providing a packet
109 * transport mechanism (ala level 0 of the PUP protocols).
110 *
111 * Each interface accepts output datagrams of a specified maximum
112 * length, and provides higher level routines with input datagrams
113 * received from its medium.
114 *
115 * Output occurs when the routine if_output is called, with three parameters:
116 * (*ifp->if_output)(ifp, m, dst, rt)
117 * Here m is the mbuf chain to be sent and dst is the destination address.
118 * The output routine encapsulates the supplied datagram if necessary,
119 * and then transmits it on its medium.
120 *
121 * On input, each interface unwraps the data received by it, and either
122 * places it on the input queue of a internetwork datagram routine
123 * and posts the associated software interrupt, or passes the datagram to a raw
124 * packet input routine.
125 *
126 * Routines exist for locating interfaces by their addresses
127 * or for locating a interface on a certain network, as well as more general
128 * routing and gateway routines maintaining information used to locate
129 * interfaces. These routines live in the files if.c and route.c
130 */
131
132 #define IFNAMSIZ 16
133
134 /* This belongs up in socket.h or socketvar.h, depending on how far the
135 * event bubbles up.
136 */
137
138 struct net_event_data {
139 u_int32_t if_family;
140 u_int32_t if_unit;
141 char if_name[IFNAMSIZ];
142 };
143
144 #if defined(__LP64__)
145 #define __need_struct_timeval32
146 #include <sys/_structs.h>
147 #define IF_DATA_TIMEVAL timeval32
148 #else
149 #define IF_DATA_TIMEVAL timeval
150 #endif
151
152 #pragma pack(4)
153
154 /*
155 * Structure describing information about an interface
156 * which may be of interest to management entities.
157 */
158 struct if_data {
159 /* generic interface information */
160 u_char ifi_type; /* ethernet, tokenring, etc */
161 u_char ifi_typelen; /* Length of frame type id */
162 u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
163 u_char ifi_addrlen; /* media address length */
164 u_char ifi_hdrlen; /* media header length */
165 u_char ifi_recvquota; /* polling quota for receive intrs */
166 u_char ifi_xmitquota; /* polling quota for xmit intrs */
167 u_char ifi_unused1; /* for future use */
168 u_int32_t ifi_mtu; /* maximum transmission unit */
169 u_int32_t ifi_metric; /* routing metric (external only) */
170 u_int32_t ifi_baudrate; /* linespeed */
171 /* volatile statistics */
172 u_int32_t ifi_ipackets; /* packets received on interface */
173 u_int32_t ifi_ierrors; /* input errors on interface */
174 u_int32_t ifi_opackets; /* packets sent on interface */
175 u_int32_t ifi_oerrors; /* output errors on interface */
176 u_int32_t ifi_collisions; /* collisions on csma interfaces */
177 u_int32_t ifi_ibytes; /* total number of octets received */
178 u_int32_t ifi_obytes; /* total number of octets sent */
179 u_int32_t ifi_imcasts; /* packets received via multicast */
180 u_int32_t ifi_omcasts; /* packets sent via multicast */
181 u_int32_t ifi_iqdrops; /* dropped on input, this interface */
182 u_int32_t ifi_noproto; /* destined for unsupported protocol */
183 u_int32_t ifi_recvtiming; /* usec spent receiving when timing */
184 u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */
185 struct IF_DATA_TIMEVAL ifi_lastchange; /* time of last administrative change */
186 u_int32_t ifi_unused2; /* used to be the default_proto */
187 u_int32_t ifi_hwassist; /* HW offload capabilities */
188 u_int32_t ifi_reserved1; /* for future use */
189 u_int32_t ifi_reserved2; /* for future use */
190 };
191
192 /*
193 * Structure describing information about an interface
194 * which may be of interest to management entities.
195 */
196 struct if_data64 {
197 /* generic interface information */
198 u_char ifi_type; /* ethernet, tokenring, etc */
199 u_char ifi_typelen; /* Length of frame type id */
200 u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
201 u_char ifi_addrlen; /* media address length */
202 u_char ifi_hdrlen; /* media header length */
203 u_char ifi_recvquota; /* polling quota for receive intrs */
204 u_char ifi_xmitquota; /* polling quota for xmit intrs */
205 u_char ifi_unused1; /* for future use */
206 u_int32_t ifi_mtu; /* maximum transmission unit */
207 u_int32_t ifi_metric; /* routing metric (external only) */
208 u_int64_t ifi_baudrate; /* linespeed */
209 /* volatile statistics */
210 u_int64_t ifi_ipackets; /* packets received on interface */
211 u_int64_t ifi_ierrors; /* input errors on interface */
212 u_int64_t ifi_opackets; /* packets sent on interface */
213 u_int64_t ifi_oerrors; /* output errors on interface */
214 u_int64_t ifi_collisions; /* collisions on csma interfaces */
215 u_int64_t ifi_ibytes; /* total number of octets received */
216 u_int64_t ifi_obytes; /* total number of octets sent */
217 u_int64_t ifi_imcasts; /* packets received via multicast */
218 u_int64_t ifi_omcasts; /* packets sent via multicast */
219 u_int64_t ifi_iqdrops; /* dropped on input, this interface */
220 u_int64_t ifi_noproto; /* destined for unsupported protocol */
221 u_int32_t ifi_recvtiming; /* usec spent receiving when timing */
222 u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */
223 struct IF_DATA_TIMEVAL ifi_lastchange; /* time of last administrative change */
224 };
225
226 #pragma pack()
227
228 #ifdef PRIVATE
229 struct if_traffic_class {
230 u_int64_t ifi_ibkpackets; /* TC_BK packets received on interface */
231 u_int64_t ifi_ibkbytes; /* TC_BK bytes received on interface */
232 u_int64_t ifi_obkpackets; /* TC_BK packet sent on interface */
233 u_int64_t ifi_obkbytes; /* TC_BK bytes sent on interface */
234 u_int64_t ifi_ivipackets; /* TC_VI packets received on interface */
235 u_int64_t ifi_ivibytes; /* TC_VI bytes received on interface */
236 u_int64_t ifi_ovipackets; /* TC_VI packets sent on interface */
237 u_int64_t ifi_ovibytes; /* TC_VI bytes sent on interface */
238 u_int64_t ifi_ivopackets; /* TC_VO packets received on interface */
239 u_int64_t ifi_ivobytes; /* TC_VO bytes received on interface */
240 u_int64_t ifi_ovopackets; /* TC_VO packets sent on interface */
241 u_int64_t ifi_ovobytes; /* TC_VO bytes sent on interface */
242 };
243
244 /*
245 * Internal storage of if_data. This is bound to change. Various places in the
246 * stack will translate this data structure in to the externally visible
247 * if_data structure above.
248 */
249 struct if_data_internal {
250 /* generic interface information */
251 u_char ifi_type; /* ethernet, tokenring, etc */
252 u_char ifi_typelen; /* Length of frame type id */
253 u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
254 u_char ifi_addrlen; /* media address length */
255 u_char ifi_hdrlen; /* media header length */
256 u_char ifi_recvquota; /* polling quota for receive intrs */
257 u_char ifi_xmitquota; /* polling quota for xmit intrs */
258 u_char ifi_unused1; /* for future use */
259 u_int32_t ifi_mtu; /* maximum transmission unit */
260 u_int32_t ifi_metric; /* routing metric (external only) */
261 u_int32_t ifi_baudrate; /* linespeed */
262 /* volatile statistics */
263 u_int64_t ifi_ipackets; /* packets received on interface */
264 u_int64_t ifi_ierrors; /* input errors on interface */
265 u_int64_t ifi_opackets; /* packets sent on interface */
266 u_int64_t ifi_oerrors; /* output errors on interface */
267 u_int64_t ifi_collisions; /* collisions on csma interfaces */
268 u_int64_t ifi_ibytes; /* total number of octets received */
269 u_int64_t ifi_obytes; /* total number of octets sent */
270 u_int64_t ifi_imcasts; /* packets received via multicast */
271 u_int64_t ifi_omcasts; /* packets sent via multicast */
272 u_int64_t ifi_iqdrops; /* dropped on input, this interface */
273 u_int64_t ifi_noproto; /* destined for unsupported protocol */
274 u_int32_t ifi_recvtiming; /* usec spent receiving when timing */
275 u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */
276 #define IF_LASTCHANGEUPTIME 1 /* lastchange: 1-uptime 0-calendar time */
277 struct timeval ifi_lastchange; /* time of last administrative change */
278 u_int32_t ifi_hwassist; /* HW offload capabilities */
279 u_int32_t ifi_tso_v4_mtu; /* TCP Segment Offload IPv4 maximum segment size */
280 u_int32_t ifi_tso_v6_mtu; /* TCP Segment Offload IPv6 maximum segment size */
281 };
282
283 #define if_mtu if_data.ifi_mtu
284 #define if_type if_data.ifi_type
285 #define if_typelen if_data.ifi_typelen
286 #define if_physical if_data.ifi_physical
287 #define if_addrlen if_data.ifi_addrlen
288 #define if_hdrlen if_data.ifi_hdrlen
289 #define if_metric if_data.ifi_metric
290 #define if_baudrate if_data.ifi_baudrate
291 #define if_hwassist if_data.ifi_hwassist
292 #define if_ipackets if_data.ifi_ipackets
293 #define if_ierrors if_data.ifi_ierrors
294 #define if_opackets if_data.ifi_opackets
295 #define if_oerrors if_data.ifi_oerrors
296 #define if_collisions if_data.ifi_collisions
297 #define if_ibytes if_data.ifi_ibytes
298 #define if_obytes if_data.ifi_obytes
299 #define if_imcasts if_data.ifi_imcasts
300 #define if_omcasts if_data.ifi_omcasts
301 #define if_iqdrops if_data.ifi_iqdrops
302 #define if_noproto if_data.ifi_noproto
303 #define if_lastchange if_data.ifi_lastchange
304 #define if_recvquota if_data.ifi_recvquota
305 #define if_xmitquota if_data.ifi_xmitquota
306 #define if_iflags if_data.ifi_iflags
307 #define if_tso_v4_mtu if_data.ifi_tso_v4_mtu
308 #define if_tso_v6_mtu if_data.ifi_tso_v6_mtu
309
310 struct mbuf;
311 struct ifaddr;
312 TAILQ_HEAD(ifnethead, ifnet); /* we use TAILQs so that the order of */
313 TAILQ_HEAD(ifaddrhead, ifaddr); /* instantiation is preserved in the list */
314 TAILQ_HEAD(ifprefixhead, ifprefix);
315 LIST_HEAD(ifmultihead, ifmultiaddr);
316 struct tqdummy;
317 TAILQ_HEAD(tailq_head, tqdummy);
318
319 /*
320 * Forward structure declarations for function prototypes [sic].
321 */
322 struct proc;
323 struct rtentry;
324 struct socket;
325 struct ether_header;
326 struct sockaddr_dl;
327 struct ifnet_filter;
328
329 TAILQ_HEAD(ifnet_filter_head, ifnet_filter);
330 TAILQ_HEAD(ddesc_head_name, dlil_demux_desc);
331
332 /* All of the following IF_HWASSIST_* flags are defined
333 * in kpi_inteface.h as IFNET_* flags. These are redefined
334 * here as constants to avoid failures to build user level
335 * programs that can not include kpi_interface.h. It is
336 * important to keep this in sync with the definitions in
337 * kpi_interface.h. The corresponding constant for each
338 * definition is mentioned in the comment.
339 *
340 * Bottom 16 bits reserved for hardware checksum
341 */
342 #define IF_HWASSIST_CSUM_IP 0x0001 /* will csum IP, IFNET_CSUM_IP */
343 #define IF_HWASSIST_CSUM_TCP 0x0002 /* will csum TCP, IFNET_CSUM_TCP */
344 #define IF_HWASSIST_CSUM_UDP 0x0004 /* will csum UDP, IFNET_CSUM_UDP */
345 #define IF_HWASSIST_CSUM_IP_FRAGS 0x0008 /* will csum IP fragments, IFNET_CSUM_FRAGMENT */
346 #define IF_HWASSIST_CSUM_FRAGMENT 0x0010 /* will do IP fragmentation, IFNET_IP_FRAGMENT */
347 #define IF_HWASSIST_CSUM_TCP_SUM16 0x1000 /* simple TCP Sum16 computation, IFNET_CSUM_SUM16 */
348 #define IF_HWASSIST_CSUM_MASK 0xffff
349 #define IF_HWASSIST_CSUM_FLAGS(hwassist) ((hwassist) & IF_HWASSIST_CSUM_MASK)
350
351 /* VLAN support */
352 #define IF_HWASSIST_VLAN_TAGGING 0x00010000 /* supports VLAN tagging, IFNET_VLAN_TAGGING */
353 #define IF_HWASSIST_VLAN_MTU 0x00020000 /* supports VLAN MTU-sized packet (for software VLAN), IFNET_VLAN_MTU */
354
355 /* TCP Segment Offloading support */
356
357 #define IF_HWASSIST_TSO_V4 0x00200000 /* will do TCP Segment offload for IPv4, IFNET_TSO_IPV4 */
358 #define IF_HWASSIST_TSO_V6 0x00400000 /* will do TCP Segment offload for IPv6, IFNET_TSO_IPV6 */
359
360 #define IFNET_RW_LOCK 1
361
362 #endif /* PRIVATE */
363 /*
364 * Structure defining a queue for a network interface.
365 */
366 struct ifqueue {
367 void *ifq_head;
368 void *ifq_tail;
369 int ifq_len;
370 int ifq_maxlen;
371 int ifq_drops;
372 };
373
374 #ifdef PRIVATE
375
376 struct ddesc_head_str;
377 struct proto_hash_entry;
378 struct kev_msg;
379 struct dlil_threading_info;
380 #if PF
381 struct pfi_kif;
382 #endif /* PF */
383
384 /*
385 * Structure defining a network interface.
386 *
387 * (Would like to call this struct ``if'', but C isn't PL/1.)
388 */
389 struct ifnet {
390 void *if_softc; /* pointer to driver state */
391 const char *if_name; /* name, e.g. ``en'' or ``lo'' */
392 TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */
393 struct ifaddrhead if_addrhead; /* linked list of addresses per if */
394 u_int32_t if_refcnt;
395 #ifdef __KPI_INTERFACE__
396 ifnet_check_multi if_check_multi;
397 #else
398 void* if_check_multi;
399 #endif /* __KPI_INTERFACE__ */
400 int if_pcount; /* number of promiscuous listeners */
401 struct bpf_if *if_bpf; /* packet filter structure */
402 u_short if_index; /* numeric abbreviation for this if */
403 short if_unit; /* sub-unit for lower level driver */
404 short if_timer; /* time 'til if_watchdog called */
405 short if_flags; /* up/down, broadcast, etc. */
406 int if_ipending; /* interrupts pending */
407 void *if_linkmib; /* link-type-specific MIB data */
408 size_t if_linkmiblen; /* length of above data */
409 struct if_data_internal if_data;
410
411 /* New with DLIL */
412 #ifdef BSD_KERNEL_PRIVATE
413 int if_usecnt;
414 #else
415 int refcnt;
416 #endif
417 #ifdef __KPI_INTERFACE__
418 ifnet_output_func if_output;
419 ifnet_ioctl_func if_ioctl;
420 ifnet_set_bpf_tap if_set_bpf_tap;
421 ifnet_detached_func if_free;
422 ifnet_demux_func if_demux;
423 ifnet_event_func if_event;
424 ifnet_framer_func if_framer;
425 ifnet_family_t if_family; /* value assigned by Apple */
426 #else
427 void* if_output;
428 void* if_ioctl;
429 void* if_set_bpf_tap;
430 void* if_free;
431 void* if_demux;
432 void* if_event;
433 void* if_framer;
434 u_int32_t if_family; /* value assigned by Apple */
435 #endif
436
437 struct ifnet_filter_head if_flt_head;
438
439 /* End DLIL specific */
440
441 u_int32_t if_delayed_detach; /* need to perform delayed detach */
442 void *if_private; /* private to interface */
443 long if_eflags; /* autoaddr, autoaddr done, etc. */
444
445 struct ifmultihead if_multiaddrs; /* multicast addresses configured */
446 int if_amcount; /* number of all-multicast requests */
447 /* procedure handles */
448 #ifdef __KPI_INTERFACE__
449 ifnet_add_proto_func if_add_proto;
450 ifnet_del_proto_func if_del_proto;
451 #else /* !__KPI_INTERFACE__ */
452 void* if_add_proto;
453 void* if_del_proto;
454 #endif /* !__KPI_INTERFACE__ */
455 struct proto_hash_entry *if_proto_hash;
456 void *if_kpi_storage;
457 #if 0
458 void *unused_was_init;
459 #else
460 struct dlil_threading_info *if_input_thread;
461 #endif
462 void *unused_was_resolvemulti;
463
464 struct ifqueue if_snd;
465 u_int32_t unused_2[1];
466 #ifdef __APPLE__
467 uintptr_t family_cookie;
468 struct ifprefixhead if_prefixhead; /* list of prefixes per if */
469
470 #ifdef _KERN_LOCKS_H_
471 #if IFNET_RW_LOCK
472 lck_rw_t *if_lock; /* Lock to protect this interface */
473 #else
474 lck_mtx_t *if_lock; /* Lock to protect this interface */
475 #endif
476 #else
477 void *if_lock;
478 #endif
479
480 #else
481 struct ifprefixhead if_prefixhead; /* list of prefixes per if */
482 #endif /* __APPLE__ */
483 struct {
484 u_int32_t length;
485 union {
486 u_char buffer[8];
487 u_char *ptr;
488 } u;
489 } if_broadcast;
490 #if CONFIG_MACF_NET
491 struct label *if_label; /* interface MAC label */
492 #endif
493
494 u_int32_t if_wake_properties;
495 #if PF
496 struct thread *if_pf_curthread;
497 struct pfi_kif *if_pf_kif;
498 #endif /* PF */
499 #ifdef _KERN_LOCKS_H_
500 lck_mtx_t *if_fwd_route_lock;
501 #else
502 void *if_fwd_route_lock;
503 #endif
504 struct route if_fwd_route; /* cached IPv4 forwarding route */
505 void *if_bridge; /* bridge glue */
506 #if IFNET_ROUTE_REFCNT
507 u_int32_t if_want_aggressive_drain;
508 u_int32_t if_idle_flags; /* idle flags */
509 u_int32_t if_route_refcnt; /* idle: route ref count */
510 #endif /* IFNET_ROUTE_REFCNT */
511 #if PKT_PRIORITY
512 struct if_traffic_class if_tc __attribute__((aligned(8)));
513 #endif /* PKT_PRIORITY */
514 };
515
516 #ifndef __APPLE__
517 /* for compatibility with other BSDs */
518 #define if_addrlist if_addrhead
519 #define if_list if_link
520 #endif /* !__APPLE__ */
521
522
523 #endif /* PRIVATE */
524
525 #ifdef KERNEL_PRIVATE
526 /*
527 * Structure describing a `cloning' interface.
528 */
529 struct if_clone {
530 LIST_ENTRY(if_clone) ifc_list; /* on list of cloners */
531 const char *ifc_name; /* name of device, e.g. `vlan' */
532 size_t ifc_namelen; /* length of name */
533 u_int32_t ifc_minifs; /* minimum number of interfaces */
534 u_int32_t ifc_maxunit; /* maximum unit number */
535 unsigned char *ifc_units; /* bitmap to handle units */
536 u_int32_t ifc_bmlen; /* bitmap length */
537
538 int (*ifc_create)(struct if_clone *, u_int32_t, void *);
539 int (*ifc_destroy)(struct ifnet *);
540 };
541
542 #define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit) \
543 { { NULL, NULL }, name, sizeof(name) - 1, minifs, maxunit, NULL, 0, create, destroy }
544
545 #define M_CLONE M_IFADDR
546
547 /*
548 * Bit values in if_ipending
549 */
550 #define IFI_RECV 1 /* I want to receive */
551 #define IFI_XMIT 2 /* I want to transmit */
552
553 /*
554 * Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq)
555 * are queues of messages stored on ifqueue structures
556 * (defined above). Entries are added to and deleted from these structures
557 * by these macros, which should be called with ipl raised to splimp().
558 */
559 #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
560 #define IF_DROP(ifq) ((ifq)->ifq_drops++)
561 #define IF_ENQUEUE(ifq, m) { \
562 (m)->m_nextpkt = 0; \
563 if ((ifq)->ifq_tail == 0) \
564 (ifq)->ifq_head = m; \
565 else \
566 ((struct mbuf*)(ifq)->ifq_tail)->m_nextpkt = m; \
567 (ifq)->ifq_tail = m; \
568 (ifq)->ifq_len++; \
569 }
570 #define IF_PREPEND(ifq, m) { \
571 (m)->m_nextpkt = (ifq)->ifq_head; \
572 if ((ifq)->ifq_tail == 0) \
573 (ifq)->ifq_tail = (m); \
574 (ifq)->ifq_head = (m); \
575 (ifq)->ifq_len++; \
576 }
577 #define IF_DEQUEUE(ifq, m) { \
578 (m) = (ifq)->ifq_head; \
579 if (m) { \
580 if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
581 (ifq)->ifq_tail = 0; \
582 (m)->m_nextpkt = 0; \
583 (ifq)->ifq_len--; \
584 } \
585 }
586
587 #define IF_ENQ_DROP(ifq, m) if_enq_drop(ifq, m)
588
589 #if defined(__GNUC__) && defined(MT_HEADER)
590 static __inline int
591 if_queue_drop(struct ifqueue *ifq, __unused struct mbuf *m)
592 {
593 IF_DROP(ifq);
594 return 0;
595 }
596
597 static __inline int
598 if_enq_drop(struct ifqueue *ifq, struct mbuf *m)
599 {
600 if (IF_QFULL(ifq) &&
601 !if_queue_drop(ifq, m))
602 return 0;
603 IF_ENQUEUE(ifq, m);
604 return 1;
605 }
606 #else
607
608 #ifdef MT_HEADER
609 int if_enq_drop(struct ifqueue *, struct mbuf *);
610 #endif /* MT_HEADER */
611
612 #endif /* defined(__GNUC__) && defined(MT_HEADER) */
613
614 #endif /* KERNEL_PRIVATE */
615
616
617 #ifdef PRIVATE
618 /*
619 * The ifaddr structure contains information about one address
620 * of an interface. They are maintained by the different address families,
621 * are allocated and attached when an address is set, and are linked
622 * together so all addresses for an interface can be located.
623 */
624 struct ifaddr {
625 struct sockaddr *ifa_addr; /* address of interface */
626 struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */
627 #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
628 struct sockaddr *ifa_netmask; /* used to determine subnet */
629 struct ifnet *ifa_ifp; /* back-pointer to interface */
630 TAILQ_ENTRY(ifaddr) ifa_link; /* queue macro glue */
631 void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */
632 (int, struct rtentry *, struct sockaddr *);
633 uint32_t ifa_flags; /* mostly rt_flags for cloning */
634 int32_t ifa_refcnt; /* ref count, use ifaref, ifafree */
635 int32_t ifa_metric; /* cost of going out this interface */
636 void (*ifa_free)(struct ifaddr *); /* callback fn for freeing */
637 void (*ifa_trace) /* callback fn for tracing refs */
638 (struct ifaddr *, int);
639 uint32_t ifa_debug; /* debug flags */
640 };
641
642 /*
643 * Valid values for ifa_flags
644 */
645 #define IFA_ROUTE RTF_UP /* route installed (0x1) */
646 #define IFA_CLONING RTF_CLONING /* (0x100) */
647
648 /*
649 * Valid values for ifa_debug
650 */
651 #define IFD_ATTACHED 0x1 /* attached to an interface */
652 #define IFD_ALLOC 0x2 /* dynamically allocated */
653 #define IFD_DEBUG 0x4 /* has debugging info */
654
655 #endif /* PRIVATE */
656
657 #ifdef KERNEL_PRIVATE
658 /*
659 * The prefix structure contains information about one prefix
660 * of an interface. They are maintained by the different address families,
661 * are allocated and attached when an prefix or an address is set,
662 * and are linked together so all prefixes for an interface can be located.
663 */
664 struct ifprefix {
665 struct sockaddr *ifpr_prefix; /* prefix of interface */
666 struct ifnet *ifpr_ifp; /* back-pointer to interface */
667 TAILQ_ENTRY(ifprefix) ifpr_list; /* queue macro glue */
668 u_char ifpr_plen; /* prefix length in bits */
669 u_char ifpr_type; /* protocol dependent prefix type */
670 };
671 #endif /* KERNEL_PRIVATE */
672
673 #ifdef PRIVATE
674 typedef void (*ifma_protospec_free_func)(void* ifma_protospec);
675
676 /*
677 * Multicast address structure. This is analogous to the ifaddr
678 * structure except that it keeps track of multicast addresses.
679 * Also, the reference count here is a count of requests for this
680 * address, not a count of pointers to this structure.
681 */
682 struct ifmultiaddr {
683 LIST_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */
684 struct sockaddr *ifma_addr; /* address this membership is for */
685 struct ifmultiaddr *ifma_ll; /* link-layer translation, if any */
686 struct ifnet *ifma_ifp; /* back-pointer to interface */
687 u_int ifma_usecount; /* use count, protected by ifp's lock */
688 void *ifma_protospec; /* protocol-specific state, if any */
689 int32_t ifma_refcount; /* reference count, atomically protected */
690 ifma_protospec_free_func ifma_free; /* function called to free ifma_protospec */
691 };
692 #endif /* PRIVATE */
693
694 #ifdef KERNEL_PRIVATE
695 #define IFAREF(ifa) ifaref(ifa)
696 #define IFAFREE(ifa) ifafree(ifa)
697
698 /*
699 * To preserve kmem compatibility, we define
700 * ifnet_head to ifnet. This should be temp.
701 */
702 #define ifnet_head ifnet
703 extern struct ifnethead ifnet_head;
704 extern struct ifnet **ifindex2ifnet;
705 extern int ifqmaxlen;
706 extern ifnet_t lo_ifp;
707 extern int if_index;
708 extern struct ifaddr **ifnet_addrs;
709
710 int if_addmulti(struct ifnet *, const struct sockaddr *, struct ifmultiaddr **);
711 int if_allmulti(struct ifnet *, int);
712 void if_attach(struct ifnet *);
713 int if_delmultiaddr(struct ifmultiaddr *ifma, int locked);
714 int if_delmulti(struct ifnet *, const struct sockaddr *);
715 void if_down(struct ifnet *);
716 int if_down_all(void);
717 void if_route(struct ifnet *, int flag, int fam);
718 void if_unroute(struct ifnet *, int flag, int fam);
719 void if_up(struct ifnet *);
720 void if_updown(struct ifnet *ifp, int up);
721 /*void ifinit(void));*/ /* declared in systm.h for main( */
722 int ifioctl(struct socket *, u_long, caddr_t, struct proc *);
723 int ifioctllocked(struct socket *, u_long, caddr_t, struct proc *);
724 struct ifnet *ifunit(const char *);
725 struct ifnet *if_withname(struct sockaddr *);
726
727 int if_clone_attach(struct if_clone *);
728 void if_clone_detach(struct if_clone *);
729 struct if_clone *
730 if_clone_lookup(const char *, u_int32_t *);
731
732 void ifnet_lock_assert(struct ifnet *ifp, int what);
733 void ifnet_lock_shared(struct ifnet *ifp);
734 void ifnet_lock_exclusive(struct ifnet *ifp);
735 void ifnet_lock_done(struct ifnet *ifp);
736
737 void ifnet_head_lock_shared(void);
738 void ifnet_head_lock_exclusive(void);
739 void ifnet_head_done(void);
740
741 void if_attach_ifa(struct ifnet * ifp, struct ifaddr *ifa);
742 void if_detach_ifa(struct ifnet * ifp, struct ifaddr *ifa);
743
744 void ifma_reference(struct ifmultiaddr *ifma);
745 void ifma_release(struct ifmultiaddr *ifma);
746
747 struct ifaddr *ifa_ifwithaddr(const struct sockaddr *);
748 struct ifaddr *ifa_ifwithaddr_scoped(const struct sockaddr *, unsigned int);
749 struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *);
750 struct ifaddr *ifa_ifwithnet(const struct sockaddr *);
751 struct ifaddr *ifa_ifwithnet_scoped(const struct sockaddr *, unsigned int);
752 struct ifaddr *ifa_ifwithroute(int, const struct sockaddr *, const struct sockaddr *);
753 struct ifaddr *ifa_ifwithroute_locked(int, const struct sockaddr *, const struct sockaddr *);
754 struct ifaddr *ifa_ifwithroute_scoped_locked(int, const struct sockaddr *,
755 const struct sockaddr *, unsigned int);
756 struct ifaddr *ifaof_ifpforaddr(const struct sockaddr *, struct ifnet *);
757 struct ifaddr *ifa_ifpgetprimary(struct ifnet *, int);
758 void ifafree(struct ifaddr *);
759 void ifaref(struct ifaddr *);
760
761 struct ifmultiaddr *ifmaof_ifpforaddr(const struct sockaddr *, struct ifnet *);
762
763 extern struct in_ifaddr *ifa_foraddr(unsigned int);
764 extern struct in_ifaddr *ifa_foraddr_scoped(unsigned int, unsigned int);
765
766 #ifdef BSD_KERNEL_PRIVATE
767 enum {
768 kIfNetUseCount_MayBeZero = 0,
769 kIfNetUseCount_MustNotBeZero = 1
770 };
771
772 int ifp_use(struct ifnet *ifp, int handle_zero);
773 int ifp_unuse(struct ifnet *ifp);
774 void ifp_use_reached_zero(struct ifnet *ifp);
775
776 void if_data_internal_to_if_data(struct ifnet *ifp, const struct if_data_internal *if_data_int,
777 struct if_data *if_data);
778 void if_data_internal_to_if_data64(struct ifnet *ifp, const struct if_data_internal *if_data_int,
779 struct if_data64 *if_data64);
780 #endif /* BSD_KERNEL_PRIVATE */
781 #endif /* KERNEL_PRIVATE */
782 #endif /* !_NET_IF_VAR_H_ */