Deleted Added
full compact
if.h (20407) if.h (21259)
1/*
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 17 unchanged lines hidden (view full) ---

26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)if.h 8.1 (Berkeley) 6/10/93
1/*
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 17 unchanged lines hidden (view full) ---

26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)if.h 8.1 (Berkeley) 6/10/93
34 * $Id: if.h,v 1.40 1996/12/11 20:38:14 wollman Exp $
34 * $Id: if.h,v 1.41 1996/12/13 21:28:37 wollman Exp $
35 */
36
37#ifndef _NET_IF_H_
38#define _NET_IF_H_
39
40/*
35 */
36
37#ifndef _NET_IF_H_
38#define _NET_IF_H_
39
40/*
41 * Structures defining a network interface, providing a packet
42 * transport mechanism (ala level 0 of the PUP protocols).
43 *
44 * Each interface accepts output datagrams of a specified maximum
45 * length, and provides higher level routines with input datagrams
46 * received from its medium.
47 *
48 * Output occurs when the routine if_output is called, with three parameters:
49 * (*ifp->if_output)(ifp, m, dst, rt)
50 * Here m is the mbuf chain to be sent and dst is the destination address.
51 * The output routine encapsulates the supplied datagram if necessary,
52 * and then transmits it on its medium.
53 *
54 * On input, each interface unwraps the data received by it, and either
55 * places it on the input queue of a internetwork datagram routine
56 * and posts the associated software interrupt, or passes the datagram to a raw
57 * packet input routine.
58 *
59 * Routines exist for locating interfaces by their addresses
60 * or for locating a interface on a certain network, as well as more general
61 * routing and gateway routines maintaining information used to locate
62 * interfaces. These routines live in the files if.c and route.c
63 */
64
65#ifdef __STDC__
66/*
67 * Forward structure declarations for function prototypes [sic].
68 */
69struct mbuf;
70struct proc;
71struct rtentry;
72struct socket;
73struct ether_header;
74#endif
75
76#include <sys/queue.h> /* get TAILQ macros */
77
78TAILQ_HEAD(ifnethead, ifnet); /* we use TAILQs so that the order of */
79TAILQ_HEAD(ifaddrhead, ifaddr); /* instantiation is preserved in the list */
80
81/*
82 * Structure describing information about an interface
83 * which may be of interest to management entities.
84 */
85struct if_data {
86 /* generic interface information */
87 u_char ifi_type; /* ethernet, tokenring, etc */
88 u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
89 u_char ifi_addrlen; /* media address length */

--- 15 unchanged lines hidden (view full) ---

105 u_long ifi_omcasts; /* packets sent via multicast */
106 u_long ifi_iqdrops; /* dropped on input, this interface */
107 u_long ifi_noproto; /* destined for unsupported protocol */
108 u_long ifi_recvtiming; /* usec spent receiving when timing */
109 u_long ifi_xmittiming; /* usec spent xmitting when timing */
110 struct timeval ifi_lastchange; /* time of last administrative change */
111};
112
41 * Structure describing information about an interface
42 * which may be of interest to management entities.
43 */
44struct if_data {
45 /* generic interface information */
46 u_char ifi_type; /* ethernet, tokenring, etc */
47 u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
48 u_char ifi_addrlen; /* media address length */

--- 15 unchanged lines hidden (view full) ---

64 u_long ifi_omcasts; /* packets sent via multicast */
65 u_long ifi_iqdrops; /* dropped on input, this interface */
66 u_long ifi_noproto; /* destined for unsupported protocol */
67 u_long ifi_recvtiming; /* usec spent receiving when timing */
68 u_long ifi_xmittiming; /* usec spent xmitting when timing */
69 struct timeval ifi_lastchange; /* time of last administrative change */
70};
71
113/*
114 * Structure defining a queue for a network interface.
115 */
116struct ifqueue {
117 struct mbuf *ifq_head;
118 struct mbuf *ifq_tail;
119 int ifq_len;
120 int ifq_maxlen;
121 int ifq_drops;
122};
123
124/*
125 * Structure defining a network interface.
126 *
127 * (Would like to call this struct ``if'', but C isn't PL/1.)
128 */
129struct ifnet {
130 void *if_softc; /* pointer to driver state */
131 char *if_name; /* name, e.g. ``en'' or ``lo'' */
132 TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */
133 struct ifaddrhead if_addrhead; /* linked list of addresses per if */
134 int if_pcount; /* number of promiscuous listeners */
135 struct bpf_if *if_bpf; /* packet filter structure */
136 u_short if_index; /* numeric abbreviation for this if */
137 short if_unit; /* sub-unit for lower level driver */
138 short if_timer; /* time 'til if_watchdog called */
139 short if_flags; /* up/down, broadcast, etc. */
140 int if_ipending; /* interrupts pending */
141 void *if_linkmib; /* link-type-specific MIB data */
142 size_t if_linkmiblen; /* length of above data */
143 struct if_data if_data;
144/* procedure handles */
145 int (*if_output) /* output routine (enqueue) */
146 __P((struct ifnet *, struct mbuf *, struct sockaddr *,
147 struct rtentry *));
148 void (*if_start) /* initiate output routine */
149 __P((struct ifnet *));
150 int (*if_done) /* output complete routine */
151 __P((struct ifnet *)); /* (XXX not used; fake prototype) */
152 int (*if_ioctl) /* ioctl routine */
153 __P((struct ifnet *, int, caddr_t));
154 void (*if_watchdog) /* timer routine */
155 __P((struct ifnet *));
156 int (*if_poll_recv) /* polled receive routine */
157 __P((struct ifnet *, int *));
158 int (*if_poll_xmit) /* polled transmit routine */
159 __P((struct ifnet *, int *));
160 void (*if_poll_intren) /* polled interrupt reenable routine */
161 __P((struct ifnet *));
162 void (*if_poll_slowinput) /* input routine for slow devices */
163 __P((struct ifnet *, struct mbuf *));
164 void (*if_init) /* Init routine */
165 __P((void *));
166 struct ifqueue if_snd; /* output queue */
167 struct ifqueue *if_poll_slowq; /* input queue for slow devices */
168};
169typedef void if_init_f_t __P((void *));
170
171#define if_mtu if_data.ifi_mtu
172#define if_type if_data.ifi_type
173#define if_physical if_data.ifi_physical
174#define if_addrlen if_data.ifi_addrlen
175#define if_hdrlen if_data.ifi_hdrlen
176#define if_metric if_data.ifi_metric
177#define if_baudrate if_data.ifi_baudrate
178#define if_ipackets if_data.ifi_ipackets
179#define if_ierrors if_data.ifi_ierrors
180#define if_opackets if_data.ifi_opackets
181#define if_oerrors if_data.ifi_oerrors
182#define if_collisions if_data.ifi_collisions
183#define if_ibytes if_data.ifi_ibytes
184#define if_obytes if_data.ifi_obytes
185#define if_imcasts if_data.ifi_imcasts
186#define if_omcasts if_data.ifi_omcasts
187#define if_iqdrops if_data.ifi_iqdrops
188#define if_noproto if_data.ifi_noproto
189#define if_lastchange if_data.ifi_lastchange
190#define if_recvquota if_data.ifi_recvquota
191#define if_xmitquota if_data.ifi_xmitquota
192#define if_rawoutput(if, m, sa) if_output(if, m, sa, (struct rtentry *)0)
193
194#define IFF_UP 0x1 /* interface is up */
195#define IFF_BROADCAST 0x2 /* broadcast address valid */
196#define IFF_DEBUG 0x4 /* turn on debugging */
197#define IFF_LOOPBACK 0x8 /* is a loopback net */
198#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
199/*#define IFF_NOTRAILERS 0x20 * obsolete: avoid use of trailers */
200#define IFF_RUNNING 0x40 /* resources allocated */
201#define IFF_NOARP 0x80 /* no address resolution protocol */

--- 7 unchanged lines hidden (view full) ---

209#define IFF_ALTPHYS IFF_LINK2 /* use alternate physical connection */
210#define IFF_MULTICAST 0x8000 /* supports multicast */
211
212/* flags set internally only: */
213#define IFF_CANTCHANGE \
214 (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
215 IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
216
72#define IFF_UP 0x1 /* interface is up */
73#define IFF_BROADCAST 0x2 /* broadcast address valid */
74#define IFF_DEBUG 0x4 /* turn on debugging */
75#define IFF_LOOPBACK 0x8 /* is a loopback net */
76#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
77/*#define IFF_NOTRAILERS 0x20 * obsolete: avoid use of trailers */
78#define IFF_RUNNING 0x40 /* resources allocated */
79#define IFF_NOARP 0x80 /* no address resolution protocol */

--- 7 unchanged lines hidden (view full) ---

87#define IFF_ALTPHYS IFF_LINK2 /* use alternate physical connection */
88#define IFF_MULTICAST 0x8000 /* supports multicast */
89
90/* flags set internally only: */
91#define IFF_CANTCHANGE \
92 (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
93 IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
94
217
218/*
219 * These really don't belong here, but there's no other obviously appropriate
220 * location.
221 */
222#define IFP_AUI 0
223#define IFP_10BASE2 1
224#define IFP_10BASET 2
225/* etc. */
226
227/*
228 * Bit values in if_ipending
229 */
230#define IFI_RECV 1 /* I want to receive */
231#define IFI_XMIT 2 /* I want to transmit */
232
233/*
234 * Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq)
235 * are queues of messages stored on ifqueue structures
236 * (defined above). Entries are added to and deleted from these structures
237 * by these macros, which should be called with ipl raised to splimp().
238 */
239#define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
240#define IF_DROP(ifq) ((ifq)->ifq_drops++)
241#define IF_ENQUEUE(ifq, m) { \
242 (m)->m_nextpkt = 0; \
243 if ((ifq)->ifq_tail == 0) \
244 (ifq)->ifq_head = m; \
245 else \
246 (ifq)->ifq_tail->m_nextpkt = m; \
247 (ifq)->ifq_tail = m; \
248 (ifq)->ifq_len++; \
249}
250#define IF_PREPEND(ifq, m) { \
251 (m)->m_nextpkt = (ifq)->ifq_head; \
252 if ((ifq)->ifq_tail == 0) \
253 (ifq)->ifq_tail = (m); \
254 (ifq)->ifq_head = (m); \
255 (ifq)->ifq_len++; \
256}
257#define IF_DEQUEUE(ifq, m) { \
258 (m) = (ifq)->ifq_head; \
259 if (m) { \
260 if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
261 (ifq)->ifq_tail = 0; \
262 (m)->m_nextpkt = 0; \
263 (ifq)->ifq_len--; \
264 } \
265}
266
267#ifdef KERNEL
268#define IF_ENQ_DROP(ifq, m) if_enq_drop(ifq, m)
269
270#if defined(__GNUC__) && defined(MT_HEADER)
271static inline int
272if_queue_drop(struct ifqueue *ifq, struct mbuf *m)
273{
274 IF_DROP(ifq);
275 return 0;
276}
277
278static inline int
279if_enq_drop(struct ifqueue *ifq, struct mbuf *m)
280{
281 if (IF_QFULL(ifq) &&
282 !if_queue_drop(ifq, m))
283 return 0;
284 IF_ENQUEUE(ifq, m);
285 return 1;
286}
287#else
288
289#ifdef MT_HEADER
290int if_enq_drop __P((struct ifqueue *, struct mbuf *));
291#endif
292
293#endif
294#endif /* KERNEL */
295
296#define IFQ_MAXLEN 50
297#define IFNET_SLOWHZ 1 /* granularity is 1 second */
298
299/*
95#define IFQ_MAXLEN 50
96#define IFNET_SLOWHZ 1 /* granularity is 1 second */
97
98/*
300 * The ifaddr structure contains information about one address
301 * of an interface. They are maintained by the different address families,
302 * are allocated and attached when an address is set, and are linked
303 * together so all addresses for an interface can be located.
304 */
305struct ifaddr {
306 struct sockaddr *ifa_addr; /* address of interface */
307 struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */
308#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
309 struct sockaddr *ifa_netmask; /* used to determine subnet */
310 struct ifnet *ifa_ifp; /* back-pointer to interface */
311 TAILQ_ENTRY(ifaddr) ifa_link; /* queue macro glue */
312 void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */
313 __P((int, struct rtentry *, struct sockaddr *));
314 u_short ifa_flags; /* mostly rt_flags for cloning */
315 short ifa_refcnt; /* references to this structure */
316 int ifa_metric; /* cost of going out this interface */
317#ifdef notdef
318 struct rtentry *ifa_rt; /* XXXX for ROUTETOIF ????? */
319#endif
320};
321#define IFA_ROUTE RTF_UP /* route installed */
322
323/*
324 * Message format for use in obtaining information about interfaces
325 * from getkerninfo and the routing socket
326 */
327struct if_msghdr {
328 u_short ifm_msglen; /* to skip over non-understood messages */
329 u_char ifm_version; /* future binary compatability */
330 u_char ifm_type; /* message type */
331 int ifm_addrs; /* like rtm_addrs */

--- 63 unchanged lines hidden (view full) ---

395 union {
396 caddr_t ifcu_buf;
397 struct ifreq *ifcu_req;
398 } ifc_ifcu;
399#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
400#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
401};
402
99 * Message format for use in obtaining information about interfaces
100 * from getkerninfo and the routing socket
101 */
102struct if_msghdr {
103 u_short ifm_msglen; /* to skip over non-understood messages */
104 u_char ifm_version; /* future binary compatability */
105 u_char ifm_type; /* message type */
106 int ifm_addrs; /* like rtm_addrs */

--- 63 unchanged lines hidden (view full) ---

170 union {
171 caddr_t ifcu_buf;
172 struct ifreq *ifcu_req;
173 } ifc_ifcu;
174#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
175#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
176};
177
178/* XXX - this should go away soon */
403#ifdef KERNEL
179#ifdef KERNEL
404#define IFAFREE(ifa) \
405 if ((ifa)->ifa_refcnt <= 0) \
406 ifafree(ifa); \
407 else \
408 (ifa)->ifa_refcnt--;
409
410extern struct ifnethead ifnet;
411extern int ifqmaxlen;
412extern struct ifnet loif[];
413extern int if_index;
414extern struct ifaddr **ifnet_addrs;
415
416void ether_ifattach __P((struct ifnet *));
417void ether_input __P((struct ifnet *, struct ether_header *, struct mbuf *));
418int ether_output __P((struct ifnet *,
419 struct mbuf *, struct sockaddr *, struct rtentry *));
420int ether_ioctl __P((struct ifnet *, int, caddr_t));
421
422void if_attach __P((struct ifnet *));
423void if_down __P((struct ifnet *));
424void if_up __P((struct ifnet *));
425#ifdef vax
426void ifubareset __P((int));
180#include <net/if_var.h>
427#endif
181#endif
428/*void ifinit __P((void));*/ /* declared in systm.h for main() */
429int ifioctl __P((struct socket *, int, caddr_t, struct proc *));
430int ifpromisc __P((struct ifnet *, int));
431struct ifnet *ifunit __P((char *));
432
182
433int if_poll_recv_slow __P((struct ifnet *ifp, int *quotap));
434void if_poll_xmit_slow __P((struct ifnet *ifp, int *quotap));
435void if_poll_throttle __P((void));
436void if_poll_unthrottle __P((void *));
437void if_poll_init __P((void));
438void if_poll __P((void));
439
440struct ifaddr *ifa_ifwithaddr __P((struct sockaddr *));
441struct ifaddr *ifa_ifwithdstaddr __P((struct sockaddr *));
442struct ifaddr *ifa_ifwithnet __P((struct sockaddr *));
443struct ifaddr *ifa_ifwithroute __P((int, struct sockaddr *,
444 struct sockaddr *));
445struct ifaddr *ifaof_ifpforaddr __P((struct sockaddr *, struct ifnet *));
446void ifafree __P((struct ifaddr *));
447
448int looutput __P((struct ifnet *,
449 struct mbuf *, struct sockaddr *, struct rtentry *));
450#endif /* KERNEL */
451
452#endif /* !_NET_IF_H_ */
183#endif /* !_NET_IF_H_ */