compromise fixes for duped keys
[unix-history] / usr / src / sys / net / if.h
CommitLineData
cb1c44c2 1/*
c8dfc989
KB
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
cb1c44c2 4 *
dbf0c423 5 * %sccs.include.redist.c%
5b519e94 6 *
c8dfc989 7 * @(#)if.h 8.1 (Berkeley) %G%
cb1c44c2 8 */
665ce890
BJ
9
10/*
f1b2fa5b
BJ
11 * Structures defining a network interface, providing a packet
12 * transport mechanism (ala level 0 of the PUP protocols).
13 *
14 * Each interface accepts output datagrams of a specified maximum
15 * length, and provides higher level routines with input datagrams
16 * received from its medium.
17 *
18 * Output occurs when the routine if_output is called, with three parameters:
320326b9 19 * (*ifp->if_output)(ifp, m, dst, rt)
ee787340
SL
20 * Here m is the mbuf chain to be sent and dst is the destination address.
21 * The output routine encapsulates the supplied datagram if necessary,
22 * and then transmits it on its medium.
f1b2fa5b
BJ
23 *
24 * On input, each interface unwraps the data received by it, and either
25 * places it on the input queue of a internetwork datagram routine
26 * and posts the associated software interrupt, or passes the datagram to a raw
27 * packet input routine.
28 *
ee787340 29 * Routines exist for locating interfaces by their addresses
f1b2fa5b
BJ
30 * or for locating a interface on a certain network, as well as more general
31 * routing and gateway routines maintaining information used to locate
ee787340 32 * interfaces. These routines live in the files if.c and route.c
8a13b737 33 */
ba56c73e 34#ifndef _TIME_ /* XXX fast fix for SNMP, going away soon */
ba56c73e
KS
35#include <sys/time.h>
36#endif
8a13b737 37
7e3bff40
KS
38#ifdef __STDC__
39/*
40 * Forward structure declarations for function prototypes [sic].
41 */
1a30fb87 42struct mbuf;
6c2dff04
KB
43struct proc;
44struct rtentry;
45struct socket;
46struct ether_header;
7e3bff40 47#endif
ec1367f4
KS
48/*
49 * Structure describing information about an interface
50 * which may be of interest to management entities.
51 */
8a13b737
BJ
52/*
53 * Structure defining a queue for a network interface.
665ce890
BJ
54 *
55 * (Would like to call this struct ``if'', but C isn't PL/1.)
56 */
ba56c73e 57
665ce890 58struct ifnet {
b454c3ea 59 char *if_name; /* name, e.g. ``en'' or ``lo'' */
ec1367f4
KS
60 struct ifnet *if_next; /* all struct ifnets are chained */
61 struct ifaddr *if_addrlist; /* linked list of addresses per if */
62 int if_pcount; /* number of promiscuous listeners */
78cafbd4 63 caddr_t if_bpf; /* packet filter structure */
ec1367f4 64 u_short if_index; /* numeric abbreviation for this if */
665ce890 65 short if_unit; /* sub-unit for lower level driver */
de602274 66 short if_timer; /* time 'til if_watchdog called */
ec1367f4
KS
67 short if_flags; /* up/down, broadcast, etc. */
68 struct if_data {
69/* generic interface information */
ec1367f4
KS
70 u_char ifi_type; /* ethernet, tokenring, etc */
71 u_char ifi_addrlen; /* media address length */
72 u_char ifi_hdrlen; /* media header length */
78cafbd4
KS
73 u_long ifi_mtu; /* maximum transmission unit */
74 u_long ifi_metric; /* routing metric (external only) */
75 u_long ifi_baudrate; /* linespeed */
ec1367f4 76/* volatile statistics */
78cafbd4
KS
77 u_long ifi_ipackets; /* packets received on interface */
78 u_long ifi_ierrors; /* input errors on interface */
79 u_long ifi_opackets; /* packets sent on interface */
80 u_long ifi_oerrors; /* output errors on interface */
81 u_long ifi_collisions; /* collisions on csma interfaces */
82 u_long ifi_ibytes; /* total number of octets received */
83 u_long ifi_obytes; /* total number of octets sent */
84 u_long ifi_imcasts; /* packets received via multicast */
85 u_long ifi_omcasts; /* packets sent via multicast */
86 u_long ifi_iqdrops; /* dropped on input, this interface */
87 u_long ifi_noproto; /* destined for unsupported protocol */
ec1367f4
KS
88 struct timeval ifi_lastchange;/* last updated */
89 } if_data;
f1b2fa5b 90/* procedure handles */
320326b9
KS
91 int (*if_init) /* init routine */
92 __P((int));
93 int (*if_output) /* output routine (enqueue) */
94 __P((struct ifnet *, struct mbuf *, struct sockaddr *,
95 struct rtentry *));
96 int (*if_start) /* initiate output routine */
97 __P((struct ifnet *));
98 int (*if_done) /* output complete routine */
99 __P((struct ifnet *)); /* (XXX not used; fake prototype) */
100 int (*if_ioctl) /* ioctl routine */
101 __P((struct ifnet *, int, caddr_t));
78cafbd4
KS
102 int (*if_reset)
103 __P((int)); /* new autoconfig will permit removal */
320326b9
KS
104 int (*if_watchdog) /* timer routine */
105 __P((int));
ec1367f4
KS
106 struct ifqueue {
107 struct mbuf *ifq_head;
108 struct mbuf *ifq_tail;
109 int ifq_len;
110 int ifq_maxlen;
111 int ifq_drops;
112 } if_snd; /* output queue */
665ce890 113};
ec1367f4
KS
114#define if_mtu if_data.ifi_mtu
115#define if_type if_data.ifi_type
116#define if_addrlen if_data.ifi_addrlen
117#define if_hdrlen if_data.ifi_hdrlen
118#define if_metric if_data.ifi_metric
119#define if_baudrate if_data.ifi_baudrate
120#define if_ipackets if_data.ifi_ipackets
121#define if_ierrors if_data.ifi_ierrors
122#define if_opackets if_data.ifi_opackets
123#define if_oerrors if_data.ifi_oerrors
124#define if_collisions if_data.ifi_collisions
125#define if_ibytes if_data.ifi_ibytes
126#define if_obytes if_data.ifi_obytes
127#define if_imcasts if_data.ifi_imcasts
128#define if_omcasts if_data.ifi_omcasts
129#define if_iqdrops if_data.ifi_iqdrops
130#define if_noproto if_data.ifi_noproto
131#define if_lastchange if_data.ifi_lastchange
665ce890 132
ee787340
SL
133#define IFF_UP 0x1 /* interface is up */
134#define IFF_BROADCAST 0x2 /* broadcast address valid */
135#define IFF_DEBUG 0x4 /* turn on debugging */
484ee22e 136#define IFF_LOOPBACK 0x8 /* is a loopback net */
dc39362e 137#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
a62dd253 138#define IFF_NOTRAILERS 0x20 /* avoid use of trailers */
81889e84 139#define IFF_RUNNING 0x40 /* resources allocated */
2effa891 140#define IFF_NOARP 0x80 /* no address resolution protocol */
bbe75d63
MK
141#define IFF_PROMISC 0x100 /* receive all packets */
142#define IFF_ALLMULTI 0x200 /* receive all multicast packets */
38a81509
MK
143#define IFF_OACTIVE 0x400 /* transmission in progress */
144#define IFF_SIMPLEX 0x800 /* can't hear own transmissions */
38f662d0
KS
145#define IFF_LINK0 0x1000 /* per link layer defined bit */
146#define IFF_LINK1 0x2000 /* per link layer defined bit */
147#define IFF_LINK2 0x4000 /* per link layer defined bit */
78cafbd4 148#define IFF_MULTICAST 0x8000 /* supports multicast */
38a81509 149
484ee22e 150/* flags set internally only: */
3d424137 151#define IFF_CANTCHANGE \
78cafbd4 152 (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
b53bf200 153 IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
ee787340 154
f1b2fa5b
BJ
155/*
156 * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
157 * input routines have queues of messages stored on ifqueue structures
158 * (defined above). Entries are added to and deleted from these structures
159 * by these macros, which should be called with ipl raised to splimp().
160 */
1e977657
BJ
161#define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
162#define IF_DROP(ifq) ((ifq)->ifq_drops++)
8a13b737 163#define IF_ENQUEUE(ifq, m) { \
0428a0b2 164 (m)->m_nextpkt = 0; \
8a13b737 165 if ((ifq)->ifq_tail == 0) \
405c9168 166 (ifq)->ifq_head = m; \
8a13b737 167 else \
0428a0b2 168 (ifq)->ifq_tail->m_nextpkt = m; \
405c9168 169 (ifq)->ifq_tail = m; \
1e977657 170 (ifq)->ifq_len++; \
8a13b737 171}
e740a894 172#define IF_PREPEND(ifq, m) { \
0428a0b2 173 (m)->m_nextpkt = (ifq)->ifq_head; \
1dd55890
BJ
174 if ((ifq)->ifq_tail == 0) \
175 (ifq)->ifq_tail = (m); \
e740a894 176 (ifq)->ifq_head = (m); \
1e977657 177 (ifq)->ifq_len++; \
e740a894 178}
8a13b737
BJ
179#define IF_DEQUEUE(ifq, m) { \
180 (m) = (ifq)->ifq_head; \
181 if (m) { \
0428a0b2 182 if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
8a13b737 183 (ifq)->ifq_tail = 0; \
0428a0b2 184 (m)->m_nextpkt = 0; \
1e977657 185 (ifq)->ifq_len--; \
8a13b737
BJ
186 } \
187}
665ce890 188
1e977657 189#define IFQ_MAXLEN 50
de602274 190#define IFNET_SLOWHZ 1 /* granularity is 1 second */
1e977657 191
63de846e
MK
192/*
193 * The ifaddr structure contains information about one address
194 * of an interface. They are maintained by the different address families,
195 * are allocated and attached when an address is set, and are linked
196 * together so all addresses for an interface can be located.
197 */
198struct ifaddr {
b72a6efb
KS
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 */
63de846e
MK
203 struct ifnet *ifa_ifp; /* back-pointer to interface */
204 struct ifaddr *ifa_next; /* next address for interface */
78cafbd4 205 void (*ifa_rtrequest)(); /* check or clean routes (+ or -)'d */
8b2d214b 206 u_short ifa_flags; /* mostly rt_flags for cloning */
320326b9 207 short ifa_refcnt; /* extra to malloc for link info */
ec1367f4 208 int ifa_metric; /* cost of going out this interface */
78cafbd4
KS
209#ifdef notdef
210 struct rtentry *ifa_rt; /* XXXX for ROUTETOIF ????? */
211#endif
63de846e 212};
78cafbd4 213#define IFA_ROUTE RTF_UP /* route installed */
ec1367f4
KS
214
215/*
216 * Message format for use in obtaining information about interfaces
217 * from getkerninfo and the routing socket
218 */
219struct if_msghdr {
220 u_short ifm_msglen; /* to skip over non-understood messages */
221 u_char ifm_version; /* future binary compatability */
222 u_char ifm_type; /* message type */
223 int ifm_addrs; /* like rtm_addrs */
224 int ifm_flags; /* value of if_flags */
225 u_short ifm_index; /* index for associated ifp */
226 struct if_data ifm_data;/* statistics and other data about if */
227};
228
229/*
230 * Message format for use in obtaining information about interface addresses
231 * from getkerninfo and the routing socket
232 */
233struct ifa_msghdr {
234 u_short ifam_msglen; /* to skip over non-understood messages */
235 u_char ifam_version; /* future binary compatability */
236 u_char ifam_type; /* message type */
237 int ifam_addrs; /* like rtm_addrs */
238 int ifam_flags; /* value of ifa_flags */
239 u_short ifam_index; /* index for associated ifp */
240 int ifam_metric; /* value of ifa_metric */
241};
242
0c33c832 243/*
a62dd253
SL
244 * Interface request structure used for socket
245 * ioctl's. All interface ioctl's must have parameter
246 * definitions which begin with ifr_name. The
247 * remainder may be interface specific.
0c33c832
SL
248 */
249struct ifreq {
a62dd253
SL
250#define IFNAMSIZ 16
251 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
0c33c832
SL
252 union {
253 struct sockaddr ifru_addr;
254 struct sockaddr ifru_dstaddr;
bdef13f6 255 struct sockaddr ifru_broadaddr;
0c33c832 256 short ifru_flags;
484ee22e 257 int ifru_metric;
a62dd253 258 caddr_t ifru_data;
0c33c832
SL
259 } ifr_ifru;
260#define ifr_addr ifr_ifru.ifru_addr /* address */
261#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
bdef13f6 262#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
0c33c832 263#define ifr_flags ifr_ifru.ifru_flags /* flags */
484ee22e 264#define ifr_metric ifr_ifru.ifru_metric /* metric */
a62dd253 265#define ifr_data ifr_ifru.ifru_data /* for use by interface */
0c33c832
SL
266};
267
b72a6efb
KS
268struct ifaliasreq {
269 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
270 struct sockaddr ifra_addr;
271 struct sockaddr ifra_broadaddr;
272 struct sockaddr ifra_mask;
273};
274
0c33c832
SL
275/*
276 * Structure used in SIOCGIFCONF request.
277 * Used to retrieve interface configuration
278 * for machine (useful for programs which
279 * must know all networks accessible).
280 */
281struct ifconf {
282 int ifc_len; /* size of associated buffer */
283 union {
284 caddr_t ifcu_buf;
285 struct ifreq *ifcu_req;
286 } ifc_ifcu;
287#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
288#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
289};
290
5548a02f
KB
291#include <net/if_arp.h>
292
665ce890 293#ifdef KERNEL
38f662d0 294#define IFAFREE(ifa) \
320326b9 295 if ((ifa)->ifa_refcnt <= 0) \
38f662d0
KS
296 ifafree(ifa); \
297 else \
298 (ifa)->ifa_refcnt--;
299
38f662d0 300struct ifnet *ifnet;
6c2dff04
KB
301
302void ether_ifattach __P((struct ifnet *));
303void ether_input __P((struct ifnet *, struct ether_header *, struct mbuf *));
304int ether_output __P((struct ifnet *,
305 struct mbuf *, struct sockaddr *, struct rtentry *));
306char *ether_sprintf __P((u_char *));
307
320326b9 308void if_attach __P((struct ifnet *));
6c2dff04
KB
309void if_down __P((struct ifnet *));
310void if_qflush __P((struct ifqueue *));
311void if_slowtimo __P((void *));
312void if_up __P((struct ifnet *));
313#ifdef vax
314void ifubareset __P((int));
315#endif
316int ifconf __P((int, caddr_t));
317void ifinit __P((void));
318int ifioctl __P((struct socket *, int, caddr_t, struct proc *));
319int ifpromisc __P((struct ifnet *, int));
320struct ifnet *ifunit __P((char *));
321
322struct ifaddr *ifa_ifwithaddr __P((struct sockaddr *));
323struct ifaddr *ifa_ifwithaf __P((int));
324struct ifaddr *ifa_ifwithdstaddr __P((struct sockaddr *));
325struct ifaddr *ifa_ifwithnet __P((struct sockaddr *));
326struct ifaddr *ifa_ifwithroute __P((int, struct sockaddr *,
327 struct sockaddr *));
328struct ifaddr *ifaof_ifpforaddr __P((struct sockaddr *, struct ifnet *));
329void ifafree __P((struct ifaddr *));
330void link_rtrequest __P((int, struct rtentry *, struct sockaddr *));
331
332int loioctl __P((struct ifnet *, int, caddr_t));
333void loopattach __P((int));
334int looutput __P((struct ifnet *,
335 struct mbuf *, struct sockaddr *, struct rtentry *));
336void lortrequest __P((int, struct rtentry *, struct sockaddr *));
5548a02f 337#endif