]> git.saurik.com Git - apple/xnu.git/blame - bsd/net/if_var.h
xnu-792.6.76.tar.gz
[apple/xnu.git] / bsd / net / if_var.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
37839358
A
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
1c79356b 11 *
37839358
A
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
37839358
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * Copyright (c) 1982, 1986, 1989, 1993
24 * The Regents of the University of California. All rights reserved.
25 *
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
28 * are met:
29 * 1. Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in the
33 * documentation and/or other materials provided with the distribution.
34 * 3. All advertising materials mentioning features or use of this software
35 * must display the following acknowledgement:
36 * This product includes software developed by the University of
37 * California, Berkeley and its contributors.
38 * 4. Neither the name of the University nor the names of its contributors
39 * may be used to endorse or promote products derived from this software
40 * without specific prior written permission.
41 *
42 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 * SUCH DAMAGE.
53 *
54 * From: @(#)if.h 8.1 (Berkeley) 6/10/93
9bccf70c 55 * $FreeBSD: src/sys/net/if_var.h,v 1.18.2.7 2001/07/24 19:10:18 brooks Exp $
1c79356b
A
56 */
57
58#ifndef _NET_IF_VAR_H_
59#define _NET_IF_VAR_H_
91447636 60
9bccf70c 61#include <sys/appleapiopts.h>
91447636
A
62#include <sys/types.h>
63#include <sys/time.h>
64#include <sys/queue.h> /* get TAILQ macros */
65#ifdef KERNEL_PRIVATE
66#include <kern/locks.h>
67#endif /* KERNEL_PRIVATE */
68
69#ifdef KERNEL
70#include <net/kpi_interface.h>
71#endif KERNEL
1c79356b 72
9bccf70c 73#ifdef __APPLE__
1c79356b
A
74#define APPLE_IF_FAM_LOOPBACK 1
75#define APPLE_IF_FAM_ETHERNET 2
76#define APPLE_IF_FAM_SLIP 3
77#define APPLE_IF_FAM_TUN 4
78#define APPLE_IF_FAM_VLAN 5
79#define APPLE_IF_FAM_PPP 6
80#define APPLE_IF_FAM_PVC 7
81#define APPLE_IF_FAM_DISC 8
82#define APPLE_IF_FAM_MDECAP 9
83#define APPLE_IF_FAM_GIF 10
84#define APPLE_IF_FAM_FAITH 11
55e303ae
A
85#define APPLE_IF_FAM_STF 12
86#define APPLE_IF_FAM_FIREWIRE 13
91447636
A
87#define APPLE_IF_FAM_BOND 14
88#endif __APPLE__
89
90/*
91 * 72 was chosen below because it is the size of a TCP/IP
92 * header (40) + the minimum mss (32).
93 */
94#define IF_MINMTU 72
95#define IF_MAXMTU 65535
1c79356b
A
96
97/*
98 * Structures defining a network interface, providing a packet
99 * transport mechanism (ala level 0 of the PUP protocols).
100 *
101 * Each interface accepts output datagrams of a specified maximum
102 * length, and provides higher level routines with input datagrams
103 * received from its medium.
104 *
105 * Output occurs when the routine if_output is called, with three parameters:
106 * (*ifp->if_output)(ifp, m, dst, rt)
107 * Here m is the mbuf chain to be sent and dst is the destination address.
108 * The output routine encapsulates the supplied datagram if necessary,
109 * and then transmits it on its medium.
110 *
111 * On input, each interface unwraps the data received by it, and either
112 * places it on the input queue of a internetwork datagram routine
113 * and posts the associated software interrupt, or passes the datagram to a raw
114 * packet input routine.
115 *
116 * Routines exist for locating interfaces by their addresses
117 * or for locating a interface on a certain network, as well as more general
118 * routing and gateway routines maintaining information used to locate
119 * interfaces. These routines live in the files if.c and route.c
120 */
121
1c79356b
A
122#define IFNAMSIZ 16
123
1c79356b
A
124/* This belongs up in socket.h or socketvar.h, depending on how far the
125 * event bubbles up.
126 */
127
128struct net_event_data {
91447636
A
129 unsigned long if_family;
130 unsigned long if_unit;
1c79356b
A
131 char if_name[IFNAMSIZ];
132};
1c79356b 133
91447636
A
134/*
135 * Structure describing information about an interface
136 * which may be of interest to management entities.
137 */
138struct if_data {
139 /* generic interface information */
140 unsigned char ifi_type; /* ethernet, tokenring, etc */
9bccf70c 141#ifdef __APPLE__
91447636
A
142 unsigned char ifi_typelen; /* Length of frame type id */
143#endif
144 unsigned char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
145 unsigned char ifi_addrlen; /* media address length */
146 unsigned char ifi_hdrlen; /* media header length */
147 unsigned char ifi_recvquota; /* polling quota for receive intrs */
148 unsigned char ifi_xmitquota; /* polling quota for xmit intrs */
149 unsigned char ifi_unused1; /* for future use */
150 unsigned long ifi_mtu; /* maximum transmission unit */
151 unsigned long ifi_metric; /* routing metric (external only) */
152 unsigned long ifi_baudrate; /* linespeed */
153 /* volatile statistics */
154 unsigned long ifi_ipackets; /* packets received on interface */
155 unsigned long ifi_ierrors; /* input errors on interface */
156 unsigned long ifi_opackets; /* packets sent on interface */
157 unsigned long ifi_oerrors; /* output errors on interface */
158 unsigned long ifi_collisions; /* collisions on csma interfaces */
159 unsigned long ifi_ibytes; /* total number of octets received */
160 unsigned long ifi_obytes; /* total number of octets sent */
161 unsigned long ifi_imcasts; /* packets received via multicast */
162 unsigned long ifi_omcasts; /* packets sent via multicast */
163 unsigned long ifi_iqdrops; /* dropped on input, this interface */
164 unsigned long ifi_noproto; /* destined for unsupported protocol */
165 unsigned long ifi_recvtiming; /* usec spent receiving when timing */
166 unsigned long ifi_xmittiming; /* usec spent xmitting when timing */
167 struct timeval ifi_lastchange; /* time of last administrative change */
168 unsigned long ifi_unused2; /* used to be the default_proto */
169 unsigned long ifi_hwassist; /* HW offload capabilities */
170 unsigned long ifi_reserved1; /* for future use */
171 unsigned long ifi_reserved2; /* for future use */
172};
4a249263 173
1c79356b
A
174/*
175 * Structure describing information about an interface
176 * which may be of interest to management entities.
177 */
91447636 178struct if_data64 {
1c79356b
A
179 /* generic interface information */
180 u_char ifi_type; /* ethernet, tokenring, etc */
9bccf70c
A
181#ifdef __APPLE__
182 u_char ifi_typelen; /* Length of frame type id */
183#endif
91447636
A
184 u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
185 u_char ifi_addrlen; /* media address length */
186 u_char ifi_hdrlen; /* media header length */
187 u_char ifi_recvquota; /* polling quota for receive intrs */
188 u_char ifi_xmitquota; /* polling quota for xmit intrs */
189 u_char ifi_unused1; /* for future use */
190 u_long ifi_mtu; /* maximum transmission unit */
191 u_long ifi_metric; /* routing metric (external only) */
192 u_int64_t ifi_baudrate; /* linespeed */
193 /* volatile statistics */
194 u_int64_t ifi_ipackets; /* packets received on interface */
195 u_int64_t ifi_ierrors; /* input errors on interface */
196 u_int64_t ifi_opackets; /* packets sent on interface */
197 u_int64_t ifi_oerrors; /* output errors on interface */
198 u_int64_t ifi_collisions; /* collisions on csma interfaces */
199 u_int64_t ifi_ibytes; /* total number of octets received */
200 u_int64_t ifi_obytes; /* total number of octets sent */
201 u_int64_t ifi_imcasts; /* packets received via multicast */
202 u_int64_t ifi_omcasts; /* packets sent via multicast */
203 u_int64_t ifi_iqdrops; /* dropped on input, this interface */
204 u_int64_t ifi_noproto; /* destined for unsupported protocol */
205 u_long ifi_recvtiming; /* usec spent receiving when timing */
206 u_long ifi_xmittiming; /* usec spent xmitting when timing */
207 struct timeval ifi_lastchange; /* time of last administrative change */
208};
209
210#ifdef PRIVATE
211/*
212 * Internal storage of if_data. This is bound to change. Various places in the
213 * stack will translate this data structure in to the externally visible
214 * if_data structure above.
215 */
216struct if_data_internal {
217 /* generic interface information */
218 u_char ifi_type; /* ethernet, tokenring, etc */
219 u_char ifi_typelen; /* Length of frame type id */
220 u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
221 u_char ifi_addrlen; /* media address length */
1c79356b 222 u_char ifi_hdrlen; /* media header length */
91447636
A
223 u_char ifi_recvquota; /* polling quota for receive intrs */
224 u_char ifi_xmitquota; /* polling quota for xmit intrs */
225 u_char ifi_unused1; /* for future use */
1c79356b
A
226 u_long ifi_mtu; /* maximum transmission unit */
227 u_long ifi_metric; /* routing metric (external only) */
91447636 228 u_long ifi_baudrate; /* linespeed */
1c79356b 229 /* volatile statistics */
91447636
A
230 u_int64_t ifi_ipackets; /* packets received on interface */
231 u_int64_t ifi_ierrors; /* input errors on interface */
232 u_int64_t ifi_opackets; /* packets sent on interface */
233 u_int64_t ifi_oerrors; /* output errors on interface */
234 u_int64_t ifi_collisions; /* collisions on csma interfaces */
235 u_int64_t ifi_ibytes; /* total number of octets received */
236 u_int64_t ifi_obytes; /* total number of octets sent */
237 u_int64_t ifi_imcasts; /* packets received via multicast */
238 u_int64_t ifi_omcasts; /* packets sent via multicast */
239 u_int64_t ifi_iqdrops; /* dropped on input, this interface */
240 u_int64_t ifi_noproto; /* destined for unsupported protocol */
1c79356b
A
241 u_long ifi_recvtiming; /* usec spent receiving when timing */
242 u_long ifi_xmittiming; /* usec spent xmitting when timing */
91447636 243#define IF_LASTCHANGEUPTIME 1 /* lastchange: 1-uptime 0-calendar time */
1c79356b 244 struct timeval ifi_lastchange; /* time of last administrative change */
9bccf70c 245 u_long ifi_hwassist; /* HW offload capabilities */
1c79356b 246};
91447636
A
247
248#define if_mtu if_data.ifi_mtu
249#define if_type if_data.ifi_type
250#define if_typelen if_data.ifi_typelen
251#define if_physical if_data.ifi_physical
252#define if_addrlen if_data.ifi_addrlen
253#define if_hdrlen if_data.ifi_hdrlen
254#define if_metric if_data.ifi_metric
255#define if_baudrate if_data.ifi_baudrate
256#define if_hwassist if_data.ifi_hwassist
257#define if_ipackets if_data.ifi_ipackets
258#define if_ierrors if_data.ifi_ierrors
259#define if_opackets if_data.ifi_opackets
260#define if_oerrors if_data.ifi_oerrors
261#define if_collisions if_data.ifi_collisions
262#define if_ibytes if_data.ifi_ibytes
263#define if_obytes if_data.ifi_obytes
264#define if_imcasts if_data.ifi_imcasts
265#define if_omcasts if_data.ifi_omcasts
266#define if_iqdrops if_data.ifi_iqdrops
267#define if_noproto if_data.ifi_noproto
268#define if_lastchange if_data.ifi_lastchange
269#define if_recvquota if_data.ifi_recvquota
270#define if_xmitquota if_data.ifi_xmitquota
271#define if_iflags if_data.ifi_iflags
272
273struct mbuf;
274struct ifaddr;
275TAILQ_HEAD(ifnethead, ifnet); /* we use TAILQs so that the order of */
276TAILQ_HEAD(ifaddrhead, ifaddr); /* instantiation is preserved in the list */
277TAILQ_HEAD(ifprefixhead, ifprefix);
278LIST_HEAD(ifmultihead, ifmultiaddr);
279struct tqdummy;
280TAILQ_HEAD(tailq_head, tqdummy);
281
282/*
283 * Forward structure declarations for function prototypes [sic].
284 */
285struct proc;
286struct rtentry;
287struct socket;
288struct ether_header;
289struct sockaddr_dl;
290struct ifnet_filter;
291
292TAILQ_HEAD(ifnet_filter_head, ifnet_filter);
293TAILQ_HEAD(ddesc_head_name, dlil_demux_desc);
294
295/* bottom 16 bits reserved for hardware checksum */
296#define IF_HWASSIST_CSUM_IP 0x0001 /* will csum IP */
297#define IF_HWASSIST_CSUM_TCP 0x0002 /* will csum TCP */
298#define IF_HWASSIST_CSUM_UDP 0x0004 /* will csum UDP */
299#define IF_HWASSIST_CSUM_IP_FRAGS 0x0008 /* will csum IP fragments */
300#define IF_HWASSIST_CSUM_FRAGMENT 0x0010 /* will do IP fragmentation */
301#define IF_HWASSIST_CSUM_TCP_SUM16 0x1000 /* simple TCP Sum16 computation */
302#define IF_HWASSIST_CSUM_MASK 0xffff
303#define IF_HWASSIST_CSUM_FLAGS(hwassist) ((hwassist) & IF_HWASSIST_CSUM_MASK)
304
305/* VLAN support */
306#define IF_HWASSIST_VLAN_TAGGING 0x10000 /* supports VLAN tagging */
307#define IF_HWASSIST_VLAN_MTU 0x20000 /* supports VLAN MTU-sized packet (for software VLAN) */
308
309#define IFNET_RW_LOCK 1
1c79356b
A
310
311/*
312 * Structure defining a queue for a network interface.
313 */
314struct ifqueue {
91447636
A
315 void *ifq_head;
316 void *ifq_tail;
1c79356b
A
317 int ifq_len;
318 int ifq_maxlen;
319 int ifq_drops;
320};
321
91447636
A
322struct ddesc_head_str;
323struct proto_hash_entry;
324struct kev_msg;
325
1c79356b
A
326/*
327 * Structure defining a network interface.
328 *
329 * (Would like to call this struct ``if'', but C isn't PL/1.)
330 */
331struct ifnet {
332 void *if_softc; /* pointer to driver state */
91447636 333 const char *if_name; /* name, e.g. ``en'' or ``lo'' */
1c79356b
A
334 TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */
335 struct ifaddrhead if_addrhead; /* linked list of addresses per if */
91447636
A
336 u_long if_refcnt;
337#ifdef __KPI_INTERFACE__
338 ifnet_check_multi if_check_multi;
339#else
340 void* if_check_multi;
341#endif __KPI_INTERFACE__
342 int if_pcount; /* number of promiscuous listeners */
1c79356b
A
343 struct bpf_if *if_bpf; /* packet filter structure */
344 u_short if_index; /* numeric abbreviation for this if */
345 short if_unit; /* sub-unit for lower level driver */
346 short if_timer; /* time 'til if_watchdog called */
347 short if_flags; /* up/down, broadcast, etc. */
348 int if_ipending; /* interrupts pending */
349 void *if_linkmib; /* link-type-specific MIB data */
350 size_t if_linkmiblen; /* length of above data */
91447636 351 struct if_data_internal if_data;
1c79356b
A
352
353/* New with DLIL */
91447636
A
354#ifdef BSD_KERNEL_PRIVATE
355 int if_usecnt;
356#else
1c79356b 357 int refcnt;
91447636 358#endif
1c79356b 359 int offercnt;
91447636
A
360#ifdef __KPI_INTERFACE__
361 ifnet_output_func if_output;
362 ifnet_ioctl_func if_ioctl;
363 ifnet_set_bpf_tap if_set_bpf_tap;
364 ifnet_detached_func if_free;
365 ifnet_demux_func if_demux;
366 ifnet_event_func if_event;
367 ifnet_framer_func if_framer;
368 ifnet_family_t if_family; /* ulong assigned by Apple */
369#else
370 void* if_output;
371 void* if_ioctl;
372 void* if_set_bpf_tap;
373 void* if_free;
374 void* if_demux;
375 void* if_event;
376 void* if_framer;
377 u_long if_family; /* ulong assigned by Apple */
378#endif
1c79356b 379
91447636 380 struct ifnet_filter_head if_flt_head;
1c79356b
A
381
382/* End DLIL specific */
383
91447636 384 u_long if_delayed_detach; /* need to perform delayed detach */
9bccf70c 385 void *if_private; /* private to interface */
1c79356b 386 long if_eflags; /* autoaddr, autoaddr done, etc. */
1c79356b
A
387
388 struct ifmultihead if_multiaddrs; /* multicast addresses configured */
389 int if_amcount; /* number of all-multicast requests */
390/* procedure handles */
91447636
A
391#ifdef __KPI_INTERFACE__
392 union {
393 int (*original)(struct ifnet *ifp, u_long protocol_family,
394 struct ddesc_head_str *demux_desc_head);
395 ifnet_add_proto_func kpi;
396 } if_add_proto_u;
397 ifnet_del_proto_func if_del_proto;
398#else __KPI_INTERFACE__
399 void* if_add_proto;
400 void* if_del_proto;
401#endif __KPI_INTERFACE__
402 struct proto_hash_entry *if_proto_hash;
403 void *if_kpi_storage;
404
405 void *unused_was_init;
406 void *unused_was_resolvemulti;
407
408 struct ifqueue if_snd;
409 u_long unused_2[1];
9bccf70c 410#ifdef __APPLE__
91447636 411 u_long family_cookie;
9bccf70c 412 struct ifprefixhead if_prefixhead; /* list of prefixes per if */
91447636
A
413
414#ifdef _KERN_LOCKS_H_
415#if IFNET_RW_LOCK
416 lck_rw_t *if_lock; /* Lock to protect this interface */
417#else
418 lck_mtx_t *if_lock; /* Lock to protect this interface */
419#endif
420#else
421 void *if_lock;
422#endif
423
9bccf70c
A
424#else
425 struct ifprefixhead if_prefixhead; /* list of prefixes per if */
426#endif /* __APPLE__ */
91447636
A
427 struct {
428 u_long length;
429 union {
430 u_char buffer[8];
431 u_char *ptr;
432 } u;
433 } if_broadcast;
1c79356b 434};
1c79356b 435
91447636 436#define if_add_proto if_add_proto_u.original
1c79356b 437
9bccf70c
A
438#ifndef __APPLE__
439/* for compatibility with other BSDs */
440#define if_addrlist if_addrhead
441#define if_list if_link
91447636
A
442#endif !__APPLE__
443
444
445#endif /* PRIVATE */
446
4a249263
A
447#ifdef KERNEL_PRIVATE
448/*
449 * Structure describing a `cloning' interface.
450 */
451struct if_clone {
452 LIST_ENTRY(if_clone) ifc_list; /* on list of cloners */
91447636 453 const char *ifc_name; /* name of device, e.g. `vlan' */
4a249263
A
454 size_t ifc_namelen; /* length of name */
455 int ifc_minifs; /* minimum number of interfaces */
456 int ifc_maxunit; /* maximum unit number */
457 unsigned char *ifc_units; /* bitmap to handle units */
458 int ifc_bmlen; /* bitmap length */
459
460 int (*ifc_create)(struct if_clone *, int);
461 void (*ifc_destroy)(struct ifnet *);
462};
463
464#define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit) \
91447636 465 { { 0, 0 }, name, sizeof(name) - 1, minifs, maxunit, NULL, 0, create, destroy }
9bccf70c 466
1c79356b
A
467/*
468 * Bit values in if_ipending
469 */
470#define IFI_RECV 1 /* I want to receive */
471#define IFI_XMIT 2 /* I want to transmit */
472
473/*
474 * Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq)
475 * are queues of messages stored on ifqueue structures
476 * (defined above). Entries are added to and deleted from these structures
477 * by these macros, which should be called with ipl raised to splimp().
478 */
479#define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
480#define IF_DROP(ifq) ((ifq)->ifq_drops++)
481#define IF_ENQUEUE(ifq, m) { \
482 (m)->m_nextpkt = 0; \
483 if ((ifq)->ifq_tail == 0) \
484 (ifq)->ifq_head = m; \
485 else \
91447636 486 ((struct mbuf*)(ifq)->ifq_tail)->m_nextpkt = m; \
1c79356b
A
487 (ifq)->ifq_tail = m; \
488 (ifq)->ifq_len++; \
489}
490#define IF_PREPEND(ifq, m) { \
491 (m)->m_nextpkt = (ifq)->ifq_head; \
492 if ((ifq)->ifq_tail == 0) \
493 (ifq)->ifq_tail = (m); \
494 (ifq)->ifq_head = (m); \
495 (ifq)->ifq_len++; \
496}
497#define IF_DEQUEUE(ifq, m) { \
498 (m) = (ifq)->ifq_head; \
499 if (m) { \
500 if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
501 (ifq)->ifq_tail = 0; \
502 (m)->m_nextpkt = 0; \
503 (ifq)->ifq_len--; \
504 } \
505}
506
1c79356b
A
507#define IF_ENQ_DROP(ifq, m) if_enq_drop(ifq, m)
508
509#if defined(__GNUC__) && defined(MT_HEADER)
510static __inline int
91447636 511if_queue_drop(struct ifqueue *ifq, __unused struct mbuf *m)
1c79356b
A
512{
513 IF_DROP(ifq);
514 return 0;
515}
516
517static __inline int
518if_enq_drop(struct ifqueue *ifq, struct mbuf *m)
519{
520 if (IF_QFULL(ifq) &&
521 !if_queue_drop(ifq, m))
522 return 0;
523 IF_ENQUEUE(ifq, m);
524 return 1;
525}
526#else
527
528#ifdef MT_HEADER
91447636
A
529int if_enq_drop(struct ifqueue *, struct mbuf *);
530#endif MT_HEADER
1c79356b 531
91447636 532#endif defined(__GNUC__) && defined(MT_HEADER)
9bccf70c 533
91447636 534#endif /* KERNEL_PRIVATE */
9bccf70c 535
1c79356b 536
91447636 537#ifdef PRIVATE
1c79356b
A
538/*
539 * The ifaddr structure contains information about one address
540 * of an interface. They are maintained by the different address families,
541 * are allocated and attached when an address is set, and are linked
542 * together so all addresses for an interface can be located.
543 */
544struct ifaddr {
545 struct sockaddr *ifa_addr; /* address of interface */
546 struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */
547#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
548 struct sockaddr *ifa_netmask; /* used to determine subnet */
549 struct ifnet *ifa_ifp; /* back-pointer to interface */
550 TAILQ_ENTRY(ifaddr) ifa_link; /* queue macro glue */
551 void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */
91447636 552 (int, struct rtentry *, struct sockaddr *);
1c79356b 553 u_short ifa_flags; /* mostly rt_flags for cloning */
91447636 554 int ifa_refcnt;/* 32bit ref count, use ifaref, ifafree */
1c79356b
A
555 int ifa_metric; /* cost of going out this interface */
556#ifdef notdef
557 struct rtentry *ifa_rt; /* XXXX for ROUTETOIF ????? */
558#endif
1c79356b 559 int (*ifa_claim_addr) /* check if an addr goes to this if */
91447636
A
560 (struct ifaddr *, const struct sockaddr *);
561 u_long ifa_debug; /* debug flags */
1c79356b 562};
91447636
A
563#define IFA_ROUTE RTF_UP /* route installed (0x1) */
564#define IFA_CLONING RTF_CLONING /* (0x100) */
565#define IFA_ATTACHED 0x1 /* ifa_debug: IFA is attached to an interface */
566
567#endif /* PRIVATE */
1c79356b 568
91447636 569#ifdef KERNEL_PRIVATE
1c79356b
A
570/*
571 * The prefix structure contains information about one prefix
572 * of an interface. They are maintained by the different address families,
573 * are allocated and attached when an prefix or an address is set,
574 * and are linked together so all prefixes for an interface can be located.
575 */
576struct ifprefix {
577 struct sockaddr *ifpr_prefix; /* prefix of interface */
578 struct ifnet *ifpr_ifp; /* back-pointer to interface */
9bccf70c 579 TAILQ_ENTRY(ifprefix) ifpr_list; /* queue macro glue */
1c79356b
A
580 u_char ifpr_plen; /* prefix length in bits */
581 u_char ifpr_type; /* protocol dependent prefix type */
582};
91447636
A
583#endif /* KERNEL_PRIVATE */
584
585#ifdef PRIVATE
586typedef void (*ifma_protospec_free_func)(void* ifma_protospec);
1c79356b
A
587
588/*
589 * Multicast address structure. This is analogous to the ifaddr
590 * structure except that it keeps track of multicast addresses.
591 * Also, the reference count here is a count of requests for this
592 * address, not a count of pointers to this structure.
593 */
594struct ifmultiaddr {
595 LIST_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */
596 struct sockaddr *ifma_addr; /* address this membership is for */
91447636
A
597 struct ifmultiaddr *ifma_ll; /* link-layer translation, if any */
598 struct ifnet *ifma_ifp; /* back-pointer to interface */
599 u_int ifma_usecount; /* use count, protected by ifp's lock */
600 void *ifma_protospec; /* protocol-specific state, if any */
601 int32_t ifma_refcount; /* reference count, atomically protected */
602 ifma_protospec_free_func ifma_free; /* function called to free ifma_protospec */
1c79356b 603};
91447636 604#endif /* PRIVATE */
1c79356b 605
91447636 606#ifdef KERNEL_PRIVATE
9bccf70c
A
607#define IFAREF(ifa) ifaref(ifa)
608#define IFAFREE(ifa) ifafree(ifa)
1c79356b 609
91447636
A
610/*
611 * To preserve kmem compatibility, we define
612 * ifnet_head to ifnet. This should be temp.
613 */
614#define ifnet_head ifnet
615extern struct ifnethead ifnet_head;
1c79356b
A
616extern struct ifnet **ifindex2ifnet;
617extern int ifqmaxlen;
618extern struct ifnet loif[];
619extern int if_index;
620extern struct ifaddr **ifnet_addrs;
91447636
A
621extern struct ifnet *lo_ifp;
622
623int if_addmulti(struct ifnet *, const struct sockaddr *, struct ifmultiaddr **);
624int if_allmulti(struct ifnet *, int);
625void if_attach(struct ifnet *);
626int if_delmultiaddr(struct ifmultiaddr *ifma, int locked);
627int if_delmulti(struct ifnet *, const struct sockaddr *);
628void if_down(struct ifnet *);
629void if_route(struct ifnet *, int flag, int fam);
630void if_unroute(struct ifnet *, int flag, int fam);
631void if_up(struct ifnet *);
632void if_updown(struct ifnet *ifp, int up);
633/*void ifinit(void));*/ /* declared in systm.h for main( */
634int ifioctl(struct socket *, u_long, caddr_t, struct proc *);
635int ifioctllocked(struct socket *, u_long, caddr_t, struct proc *);
636struct ifnet *ifunit(const char *);
637struct ifnet *if_withname(struct sockaddr *);
9bccf70c 638
4a249263
A
639void if_clone_attach(struct if_clone *);
640void if_clone_detach(struct if_clone *);
1c79356b 641
91447636
A
642void ifnet_lock_assert(struct ifnet *ifp, int what);
643void ifnet_lock_shared(struct ifnet *ifp);
644void ifnet_lock_exclusive(struct ifnet *ifp);
645void ifnet_lock_done(struct ifnet *ifp);
646
647void ifnet_head_lock_shared(void);
648void ifnet_head_lock_exclusive(void);
649void ifnet_head_done(void);
650
651void if_attach_ifa(struct ifnet * ifp, struct ifaddr *ifa);
652void if_detach_ifa(struct ifnet * ifp, struct ifaddr *ifa);
653
654void ifma_reference(struct ifmultiaddr *ifma);
655void ifma_release(struct ifmultiaddr *ifma);
656
657struct ifaddr *ifa_ifwithaddr(const struct sockaddr *);
658struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *);
659struct ifaddr *ifa_ifwithnet(const struct sockaddr *);
660struct ifaddr *ifa_ifwithroute(int, const struct sockaddr *, const struct sockaddr *);
661struct ifaddr *ifaof_ifpforaddr(const struct sockaddr *, struct ifnet *);
662void ifafree(struct ifaddr *);
663void ifaref(struct ifaddr *);
664
665struct ifmultiaddr *ifmaof_ifpforaddr(const struct sockaddr *, struct ifnet *);
666
667#ifdef BSD_KERNEL_PRIVATE
668void if_data_internal_to_if_data(const struct if_data_internal *if_data_int,
669 struct if_data *if_data);
670void if_data_internal_to_if_data64(const struct if_data_internal *if_data_int,
671 struct if_data64 *if_data64);
672#endif /* BSD_KERNEL_PRIVATE */
673#endif /* KERNEL_PRIVATE */
1c79356b 674#endif /* !_NET_IF_VAR_H_ */