Watt-32 tcp/ip  2.2 dev-rel.10
if.h
Go to the documentation of this file.
1 
5 /* $NetBSD: if.h,v 1.29 1997/10/02 19:41:57 is Exp $ */
6 
7 /*
8  * Copyright (c) 1982, 1986, 1989, 1993
9  * The Regents of the University of California. All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in the
18  * documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  * must display the following acknowledgement:
21  * This product includes software developed by the University of
22  * California, Berkeley and its contributors.
23  * 4. Neither the name of the University nor the names of its contributors
24  * may be used to endorse or promote products derived from this software
25  * without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  *
39  * @(#)if.h 8.1 (Berkeley) 6/10/93
40  */
41 
42 #ifndef __NET_IF_H
43 #define __NET_IF_H
44 
45 #ifndef __SYS_QUEUE_H
46 #include <sys/queue.h>
47 #endif
48 
49 #ifndef __SYS_MBUF_H
50 #include <sys/mbuf.h>
51 #endif
52 
53 /*
54  * Structures defining a network interface, providing a packet
55  * transport mechanism (ala level 0 of the PUP protocols).
56  *
57  * Each interface accepts output datagrams of a specified maximum
58  * length, and provides higher level routines with input datagrams
59  * received from its medium.
60  *
61  * Output occurs when the routine if_output is called, with four parameters:
62  * (*ifp->if_output)(ifp, m, dst, rt)
63  * Here m is the mbuf chain to be sent and dst is the destination address.
64  * The output routine encapsulates the supplied datagram if necessary,
65  * and then transmits it on its medium.
66  *
67  * On input, each interface unwraps the data received by it, and either
68  * places it on the input queue of a internetwork datagram routine
69  * and posts the associated software interrupt, or passes the datagram to a raw
70  * packet input routine.
71  *
72  * Routines exist for locating interfaces by their addresses
73  * or for locating a interface on a certain network, as well as more general
74  * routing and gateway routines maintaining information used to locate
75  * interfaces. These routines live in the files if.c and route.c
76  */
77 #ifndef __SYS_WTIME_H
78 #include <sys/wtime.h>
79 #endif
80 
81 struct rtentry;
82 struct ether_header;
83 struct proc { int dummy; };
84 struct socket { int dummy; };
85 
86 /*
87  * Structure defining statistics and other data kept regarding a network
88  * interface.
89  */
90 struct if_data {
91  /* generic interface information */
92  u_char ifi_type; /* ethernet, tokenring, etc. */
93  u_char ifi_addrlen; /* media address length */
94  u_char ifi_hdrlen; /* media header length */
95  u_long ifi_mtu; /* maximum transmission unit */
96  u_long ifi_metric; /* routing metric (external only) */
97  u_long ifi_baudrate; /* linespeed */
98  /* volatile statistics */
99  u_long ifi_ipackets; /* packets received on interface */
100  u_long ifi_ierrors; /* input errors on interface */
101  u_long ifi_opackets; /* packets sent on interface */
102  u_long ifi_oerrors; /* output errors on interface */
103  u_long ifi_collisions; /* collisions on csma interfaces */
104  u_long ifi_ibytes; /* total number of octets received */
105  u_long ifi_obytes; /* total number of octets sent */
106  u_long ifi_imcasts; /* packets received via multicast */
107  u_long ifi_omcasts; /* packets sent via multicast */
108  u_long ifi_iqdrops; /* dropped on input, this interface */
109  u_long ifi_noproto; /* destined for unsupported protocol */
110  struct timeval ifi_lastchange; /* last updated */
111 };
112 
113 /*
114  * Structure defining a queue for a network interface.
115  *
116  * (Would like to call this struct ``if'', but C isn't PL/1.)
117  */
118 TAILQ_HEAD(ifnet_head, ifnet); /* the actual queue head */
119 
120 /*
121  * Length of interface external name, including terminating '\0'.
122  * Note: this is the same size as a generic device's external name.
123  */
124 #define IFNAMSIZ 16
125 
126 #ifndef IF_NAMESIZE
127 #define IF_NAMESIZE IFNAMSIZ
128 #endif
129 
130 struct ifnet { /* and the entries */
131  void *if_softc; /* lower-level data for this if */
132  TAILQ_ENTRY(ifnet) if_list; /* all struct ifnets are chained */
133  TAILQ_HEAD(xx, ifaddr) if_addrlist; /* linked list of addresses per if */
134  char if_xname[IFNAMSIZ]; /* external name (name + unit) */
135  int if_pcount; /* number of promiscuous listeners */
136  caddr_t if_bpf; /* packet filter structure */
137  u_short if_index; /* numeric abbreviation for this if */
138  short if_timer; /* time 'til if_watchdog called */
139  short if_flags; /* up/down, broadcast, etc. */
140  short if__pad1; /* be nice to m68k ports */
141  struct if_data if_data; /* statistics and other data about if */
142 /* procedure handles */
143  int (*if_output) /* output routine (enqueue) */
144  (struct ifnet *, struct mbuf *, struct sockaddr *,
145  struct rtentry *);
146  void (*if_start) /* initiate output routine */
147  (struct ifnet *);
148  int (*if_ioctl) /* ioctl routine */
149  (struct ifnet *, u_long, caddr_t);
150  int (*if_reset) /* XXX bus reset routine */
151  (struct ifnet *);
152  void (*if_watchdog) /* timer routine */
153  (struct ifnet *);
154  struct ifqueue {
155  struct mbuf *ifq_head;
156  struct mbuf *ifq_tail;
157  int ifq_len;
158  int ifq_maxlen;
159  int ifq_drops;
160  } if_snd; /* output queue */
161  struct sockaddr_dl *if_sadl; /* pointer to our sockaddr_dl */
162  u_int8_t *if_broadcastaddr; /* linklevel broadcast bytestring */
163 };
164 
165 #define if_mtu if_data.ifi_mtu
166 #define if_type if_data.ifi_type
167 #define if_addrlen if_data.ifi_addrlen
168 #define if_hdrlen if_data.ifi_hdrlen
169 #define if_metric if_data.ifi_metric
170 #define if_baudrate if_data.ifi_baudrate
171 #define if_ipackets if_data.ifi_ipackets
172 #define if_ierrors if_data.ifi_ierrors
173 #define if_opackets if_data.ifi_opackets
174 #define if_oerrors if_data.ifi_oerrors
175 #define if_collisions if_data.ifi_collisions
176 #define if_ibytes if_data.ifi_ibytes
177 #define if_obytes if_data.ifi_obytes
178 #define if_imcasts if_data.ifi_imcasts
179 #define if_omcasts if_data.ifi_omcasts
180 #define if_iqdrops if_data.ifi_iqdrops
181 #define if_noproto if_data.ifi_noproto
182 #define if_lastchange if_data.ifi_lastchange
183 
184 #define IFF_UP 0x1 /* interface is up */
185 #define IFF_BROADCAST 0x2 /* broadcast address valid */
186 #define IFF_DEBUG 0x4 /* turn on debugging */
187 #define IFF_LOOPBACK 0x8 /* is a loopback net */
188 #define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
189 #define IFF_NOTRAILERS 0x20 /* avoid use of trailers */
190 #define IFF_RUNNING 0x40 /* resources allocated */
191 #define IFF_NOARP 0x80 /* no address resolution protocol */
192 #define IFF_PROMISC 0x100 /* receive all packets */
193 #define IFF_ALLMULTI 0x200 /* receive all multicast packets */
194 #define IFF_OACTIVE 0x400 /* transmission in progress */
195 #define IFF_SIMPLEX 0x800 /* can't hear own transmissions */
196 #define IFF_LINK0 0x1000 /* per link layer defined bit */
197 #define IFF_LINK1 0x2000 /* per link layer defined bit */
198 #define IFF_LINK2 0x4000 /* per link layer defined bit */
199 #define IFF_MULTICAST 0x8000 /* supports multicast */
200 
201 /* flags set internally only: */
202 #define IFF_CANTCHANGE \
203  (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
204  IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
205 
206 /*
207  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
208  * input routines have queues of messages stored on ifqueue structures
209  * (defined above). Entries are added to and deleted from these structures
210  * by these macros, which should be called with ipl raised to splimp().
211  */
212 #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
213 #define IF_DROP(ifq) ((ifq)->ifq_drops++)
214 #define IF_ENQUEUE(ifq, m) { \
215  (m)->m_nextpkt = 0; \
216  if ((ifq)->ifq_tail == 0) \
217  (ifq)->ifq_head = m; \
218  else \
219  (ifq)->ifq_tail->m_nextpkt = m; \
220  (ifq)->ifq_tail = m; \
221  (ifq)->ifq_len++; \
222 }
223 #define IF_PREPEND(ifq, m) { \
224  (m)->m_nextpkt = (ifq)->ifq_head; \
225  if ((ifq)->ifq_tail == 0) \
226  (ifq)->ifq_tail = (m); \
227  (ifq)->ifq_head = (m); \
228  (ifq)->ifq_len++; \
229 }
230 #define IF_DEQUEUE(ifq, m) { \
231  (m) = (ifq)->ifq_head; \
232  if (m) { \
233  if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
234  (ifq)->ifq_tail = 0; \
235  (m)->m_nextpkt = 0; \
236  (ifq)->ifq_len--; \
237  } \
238 }
239 
240 #define IFQ_MAXLEN 50
241 #define IFNET_SLOWHZ 1 /* granularity is 1 second */
242 
243 /*
244  * The ifaddr structure contains information about one address
245  * of an interface. They are maintained by the different address families,
246  * are allocated and attached when an address is set, and are linked
247  * together so all addresses for an interface can be located.
248  */
249 struct ifaddr {
250  struct sockaddr *ifa_addr; /* address of interface */
251  struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */
252 #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
253  struct sockaddr *ifa_netmask; /* used to determine subnet */
254  struct ifnet *ifa_ifp; /* back-pointer to interface */
255  TAILQ_ENTRY(ifaddr) ifa_list; /* list of addresses for interface */
256  void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */
257  (int, struct rtentry *, struct sockaddr *);
258  u_short ifa_flags; /* mostly rt_flags for cloning */
259  short ifa_refcnt; /* count of references */
260  int ifa_metric; /* cost of going out this interface */
261 };
262 #define IFA_ROUTE RTF_UP /* route installed */
263 
264 /*
265  * Message format for use in obtaining information about interfaces
266  * from sysctl and the routing socket.
267  */
268 struct if_msghdr {
269  u_short ifm_msglen; /* to skip over non-understood messages */
270  u_char ifm_version; /* future binary compatability */
271  u_char ifm_type; /* message type */
272  int ifm_addrs; /* like rtm_addrs */
273  int ifm_flags; /* value of if_flags */
274  u_short ifm_index; /* index for associated ifp */
275  struct if_data ifm_data;/* statistics and other data about if */
276 };
277 
278 /*
279  * Message format for use in obtaining information about interface addresses
280  * from sysctl and the routing socket.
281  */
282 struct ifa_msghdr {
283  u_short ifam_msglen; /* to skip over non-understood messages */
284  u_char ifam_version; /* future binary compatability */
285  u_char ifam_type; /* message type */
286  int ifam_addrs; /* like rtm_addrs */
287  int ifam_flags; /* value of ifa_flags */
288  u_short ifam_index; /* index for associated ifp */
289  int ifam_metric; /* value of ifa_metric */
290 };
291 
292 /*
293  * Interface request structure used for socket
294  * ioctl's. All interface ioctl's must have parameter
295  * definitions which begin with ifr_name. The
296  * remainder may be interface specific.
297  */
298 struct ifreq {
299  char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
300  union {
301  struct sockaddr ifru_addr;
302  struct sockaddr ifru_dstaddr;
303  struct sockaddr ifru_hwaddr;
304  struct sockaddr ifru_broadaddr;
305  short ifru_flags;
306  int ifru_metric;
307  int ifru_mtu;
308  caddr_t ifru_data;
309  } ifr_ifru;
310 #define ifr_addr ifr_ifru.ifru_addr /* address */
311 #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
312 #define ifr_hwaddr ifr_ifru.ifru_hwaddr /* hardware address */
313 #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
314 #define ifr_flags ifr_ifru.ifru_flags /* flags */
315 #define ifr_metric ifr_ifru.ifru_metric /* metric */
316 #define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
317 #define ifr_media ifr_ifru.ifru_metric /* media options (overload) */
318 #define ifr_data ifr_ifru.ifru_data /* for use by interface */
319 };
320 
321 struct ifaliasreq {
322  char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
323  struct sockaddr ifra_addr;
324  struct sockaddr ifra_dstaddr;
325 #define ifra_broadaddr ifra_dstaddr
326  struct sockaddr ifra_mask;
327 };
328 
329 struct ifmediareq {
330  char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
331  int ifm_current; /* current media options */
332  int ifm_mask; /* don't care mask */
333  int ifm_status; /* media status */
334  int ifm_active; /* active options */
335  int ifm_count; /* # entries in ifm_ulist array */
336  int *ifm_ulist; /* media words */
337 };
338 
339 /*
340  * Structure used in SIOCGIFCONF request.
341  * Used to retrieve interface configuration
342  * for machine (useful for programs which
343  * must know all networks accessible).
344  */
345 struct ifconf {
346  int ifc_len; /* size of associated buffer */
347  union {
348  caddr_t ifcu_buf;
349  struct ifreq *ifcu_req;
350  } ifc_ifcu;
351 #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
352 #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
353 };
354 
355 #ifndef __NET_IF_ARP_H
356 #include <net/if_arp.h>
357 #endif
358 
359 #endif
Definition: if.h:282
Definition: if.h:329
Definition: if.h:90
Definition: if.h:84
Definition: if.h:83
Definition: if.h:268
Definition: if.h:321
Definition: wtime.h:38
Definition: if.h:130
Definition: if.h:249
Definition: mbuf.h:6
Definition: if.h:345
Definition: if.h:298
Definition: route.h:98