This commit was generated by cvs2svn to track changes on a CVS vendor
[unix-history] / sys / net / if.h
CommitLineData
15637ed4
RG
1/*
2 * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
3 * 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
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
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 *
70c5ff60 33 * from: @(#)if.h 7.11 (Berkeley) 3/19/91
fde1aeb2 34 * $Id: if.h,v 1.10 1993/11/25 01:33:59 wollman Exp $
15637ed4
RG
35 */
36
8ace4366
GW
37#ifndef _NET_IF_H_
38#define _NET_IF_H_ 1
39
15637ed4
RG
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)
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#ifndef _TIME_ /* XXX fast fix for SNMP, going away soon */
65#ifdef KERNEL
66#include "../sys/time.h"
67#else
68#include <sys/time.h>
69#endif
70#endif
71
72/*
73 * Structure defining a queue for a network interface.
74 *
75 * (Would like to call this struct ``if'', but C isn't PL/1.)
76 */
77
4c45483e
GW
78struct rtentry;
79
15637ed4
RG
80struct ifnet {
81 char *if_name; /* name, e.g. ``en'' or ``lo'' */
82 short if_unit; /* sub-unit for lower level driver */
3544846f 83 u_short if_mtu; /* maximum transmission unit */
deb4b2da 84 short if_flags; /* up/down, broadcast, etc. */
15637ed4
RG
85 short if_timer; /* time 'til if_watchdog called */
86 int if_metric; /* routing metric (external only) */
87 struct ifaddr *if_addrlist; /* linked list of addresses per if */
88 struct ifqueue {
89 struct mbuf *ifq_head;
90 struct mbuf *ifq_tail;
91 int ifq_len;
92 int ifq_maxlen;
93 int ifq_drops;
94 } if_snd; /* output queue */
95/* procedure handles */
4c45483e
GW
96 void (*if_init)(int); /* init routine */
97 int (*if_output)(struct ifnet *, struct mbuf *, struct sockaddr *,
98 struct rtentry *); /* output routine (enqueue) */
99 void (*if_start)(struct ifnet *); /* initiate output routine */
100 int (*if_done)(struct ifnet *); /* output complete routine */
101 int (*if_ioctl)(struct ifnet *, int, caddr_t); /* ioctl routine */
102 void (*if_reset)(int, int); /* bus reset routine */
103 void (*if_watchdog)(int); /* timer routine */
15637ed4
RG
104/* generic interface statistics */
105 int if_ipackets; /* packets received on interface */
106 int if_ierrors; /* input errors on interface */
107 int if_opackets; /* packets sent on interface */
108 int if_oerrors; /* output errors on interface */
109 int if_collisions; /* collisions on csma interfaces */
110/* end statistics */
111 struct ifnet *if_next;
112 u_char if_type; /* ethernet, tokenring, etc */
113 u_char if_addrlen; /* media address length */
114 u_char if_hdrlen; /* media header length */
115 u_char if_index; /* numeric abbreviation for this if */
116/* more statistics here to avoid recompiling netstat */
117 struct timeval if_lastchange; /* last updated */
118 int if_ibytes; /* total number of octets received */
119 int if_obytes; /* total number of octets sent */
120 int if_imcasts; /* packets received via multicast */
121 int if_omcasts; /* packets sent via multicast */
122 int if_iqdrops; /* dropped on input, this interface */
123 int if_noproto; /* destined for unsupported protocol */
124 int if_baudrate; /* linespeed */
125 int if_pcount; /* number of promiscuous listeners */
126};
127
128#define IFF_UP 0x1 /* interface is up */
129#define IFF_BROADCAST 0x2 /* broadcast address valid */
130#define IFF_DEBUG 0x4 /* turn on debugging */
131#define IFF_LOOPBACK 0x8 /* is a loopback net */
132#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
133#define IFF_NOTRAILERS 0x20 /* avoid use of trailers */
134#define IFF_RUNNING 0x40 /* resources allocated */
135#define IFF_NOARP 0x80 /* no address resolution protocol */
deb4b2da 136/* next two not supported now, but reserved: */
15637ed4
RG
137#define IFF_PROMISC 0x100 /* receive all packets */
138#define IFF_ALLMULTI 0x200 /* receive all multicast packets */
139#define IFF_OACTIVE 0x400 /* transmission in progress */
140#define IFF_SIMPLEX 0x800 /* can't hear own transmissions */
8ace4366
GW
141#define IFF_LLC0 0x1000 /* IEEE 802.2 LLC class 0 */
142#define IFF_LLC1 0x2000 /* IEEE 802.2 LLC class 1 */
143#define IFF_LLC2 0x4000 /* IEEE 802.2 LLC class 2 */
8ace4366
GW
144#define IFF_ALTPHYS 0x8000 /* alternative physical connection */
145#define IFF_MULTICAST 0x10000 /* i'face supports multicast */
146#define IFF_VIRTUAL 0x20000 /* i'face is really a VIF */
15637ed4 147
8ace4366
GW
148/* flags set internally only: */
149#define IFF_CANTCHANGE \
150 (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|IFF_SIMPLEX\
7f49a21d 151 |IFF_MULTICAST|IFF_VIRTUAL)
15637ed4
RG
152
153/*
154 * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
155 * input routines have queues of messages stored on ifqueue structures
156 * (defined above). Entries are added to and deleted from these structures
157 * by these macros, which should be called with ipl raised to splimp().
158 */
159#define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
160#define IF_DROP(ifq) ((ifq)->ifq_drops++)
161#define IF_ENQUEUE(ifq, m) { \
162 (m)->m_nextpkt = 0; \
163 if ((ifq)->ifq_tail == 0) \
164 (ifq)->ifq_head = m; \
165 else \
166 (ifq)->ifq_tail->m_nextpkt = m; \
167 (ifq)->ifq_tail = m; \
168 (ifq)->ifq_len++; \
169}
170#define IF_PREPEND(ifq, m) { \
171 (m)->m_nextpkt = (ifq)->ifq_head; \
172 if ((ifq)->ifq_tail == 0) \
173 (ifq)->ifq_tail = (m); \
174 (ifq)->ifq_head = (m); \
175 (ifq)->ifq_len++; \
176}
177#define IF_DEQUEUE(ifq, m) { \
178 (m) = (ifq)->ifq_head; \
179 if (m) { \
180 if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
181 (ifq)->ifq_tail = 0; \
182 (m)->m_nextpkt = 0; \
183 (ifq)->ifq_len--; \
184 } \
185}
186
187#define IFQ_MAXLEN 50
188#define IFNET_SLOWHZ 1 /* granularity is 1 second */
189
190/*
191 * The ifaddr structure contains information about one address
192 * of an interface. They are maintained by the different address families,
193 * are allocated and attached when an address is set, and are linked
194 * together so all addresses for an interface can be located.
195 */
4c45483e
GW
196struct rtentry;
197
15637ed4
RG
198struct ifaddr {
199 struct sockaddr *ifa_addr; /* address of interface */
200 struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */
201#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
202 struct sockaddr *ifa_netmask; /* used to determine subnet */
203 struct ifnet *ifa_ifp; /* back-pointer to interface */
204 struct ifaddr *ifa_next; /* next address for interface */
4c45483e
GW
205 void (*ifa_rtrequest)(int, struct rtentry *, struct sockaddr *);
206 /* check or clean routes (+ or -)'d */
15637ed4
RG
207 struct rtentry *ifa_rt; /* ??? for ROUTETOIF */
208 u_short ifa_flags; /* mostly rt_flags for cloning */
209 u_short ifa_llinfolen; /* extra to malloc for link info */
210};
211#define IFA_ROUTE RTF_UP /* route installed */
212/*
213 * Interface request structure used for socket
214 * ioctl's. All interface ioctl's must have parameter
215 * definitions which begin with ifr_name. The
216 * remainder may be interface specific.
217 */
218struct ifreq {
219#define IFNAMSIZ 16
220 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
221 union {
222 struct sockaddr ifru_addr;
223 struct sockaddr ifru_dstaddr;
224 struct sockaddr ifru_broadaddr;
225 short ifru_flags;
226 int ifru_metric;
227 caddr_t ifru_data;
228 } ifr_ifru;
229#define ifr_addr ifr_ifru.ifru_addr /* address */
230#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
231#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
232#define ifr_flags ifr_ifru.ifru_flags /* flags */
233#define ifr_metric ifr_ifru.ifru_metric /* metric */
234#define ifr_data ifr_ifru.ifru_data /* for use by interface */
235};
236
237struct ifaliasreq {
238 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
239 struct sockaddr ifra_addr;
240 struct sockaddr ifra_broadaddr;
241 struct sockaddr ifra_mask;
242};
243
244/*
245 * Structure used in SIOCGIFCONF request.
246 * Used to retrieve interface configuration
247 * for machine (useful for programs which
248 * must know all networks accessible).
249 */
250struct ifconf {
251 int ifc_len; /* size of associated buffer */
252 union {
253 caddr_t ifcu_buf;
254 struct ifreq *ifcu_req;
255 } ifc_ifcu;
256#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
257#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
258};
259
260#ifdef KERNEL
261#include "../net/if_arp.h"
8ace4366
GW
262extern struct ifqueue rawintrq; /* raw packet input queue */
263extern struct ifnet *ifnet;
15637ed4
RG
264struct ifaddr *ifa_ifwithaddr(), *ifa_ifwithnet();
265struct ifaddr *ifa_ifwithdstaddr();
fde1aeb2
GW
266extern int ifpromisc(struct ifnet *, int);
267
268/* Loopback interface, used internally by non-loopback code */
f78a4b51 269extern struct ifnet loif;
fde1aeb2
GW
270extern int looutput(struct ifnet *, struct mbuf *, struct sockaddr *,
271 struct rtentry *);
f78a4b51
GW
272
273#else /* KERNEL */
15637ed4 274#include <net/if_arp.h>
f78a4b51 275#endif /* KERNEL */
8ace4366 276#endif /* _NET_IF_H_ */