Latest fixes from Nesheim@cornell
[unix-history] / usr / src / sys / net / if.h
CommitLineData
cb1c44c2
KM
1/*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 *
6 * @(#)if.h 6.7 (Berkeley) %G%
7 */
665ce890
BJ
8
9/*
f1b2fa5b
BJ
10 * Structures defining a network interface, providing a packet
11 * transport mechanism (ala level 0 of the PUP protocols).
12 *
13 * Each interface accepts output datagrams of a specified maximum
14 * length, and provides higher level routines with input datagrams
15 * received from its medium.
16 *
17 * Output occurs when the routine if_output is called, with three parameters:
ee787340
SL
18 * (*ifp->if_output)(ifp, m, dst)
19 * Here m is the mbuf chain to be sent and dst is the destination address.
20 * The output routine encapsulates the supplied datagram if necessary,
21 * and then transmits it on its medium.
f1b2fa5b
BJ
22 *
23 * On input, each interface unwraps the data received by it, and either
24 * places it on the input queue of a internetwork datagram routine
25 * and posts the associated software interrupt, or passes the datagram to a raw
26 * packet input routine.
27 *
ee787340 28 * Routines exist for locating interfaces by their addresses
f1b2fa5b
BJ
29 * or for locating a interface on a certain network, as well as more general
30 * routing and gateway routines maintaining information used to locate
ee787340 31 * interfaces. These routines live in the files if.c and route.c
8a13b737 32 */
8a13b737
BJ
33
34/*
35 * Structure defining a queue for a network interface.
665ce890
BJ
36 *
37 * (Would like to call this struct ``if'', but C isn't PL/1.)
38 */
39struct ifnet {
b454c3ea 40 char *if_name; /* name, e.g. ``en'' or ``lo'' */
665ce890 41 short if_unit; /* sub-unit for lower level driver */
665ce890 42 short if_mtu; /* maximum transmission unit */
ee787340 43 short if_flags; /* up/down, broadcast, etc. */
de602274 44 short if_timer; /* time 'til if_watchdog called */
63de846e 45 struct ifaddr *if_addrlist; /* linked list of addresses per if */
f1b2fa5b
BJ
46 struct ifqueue {
47 struct mbuf *ifq_head;
48 struct mbuf *ifq_tail;
1e977657
BJ
49 int ifq_len;
50 int ifq_maxlen;
51 int ifq_drops;
f1b2fa5b
BJ
52 } if_snd; /* output queue */
53/* procedure handles */
54 int (*if_init)(); /* init routine */
8a13b737 55 int (*if_output)(); /* output routine */
a62dd253 56 int (*if_ioctl)(); /* ioctl routine */
b3691eab 57 int (*if_reset)(); /* bus reset routine */
de602274 58 int (*if_watchdog)(); /* timer routine */
f1b2fa5b 59/* generic interface statistics */
b454c3ea
BJ
60 int if_ipackets; /* packets received on interface */
61 int if_ierrors; /* input errors on interface */
62 int if_opackets; /* packets sent on interface */
63 int if_oerrors; /* output errors on interface */
f1b2fa5b 64 int if_collisions; /* collisions on csma interfaces */
f1b2fa5b 65/* end statistics */
4ad99bae 66 struct ifnet *if_next;
665ce890
BJ
67};
68
ee787340
SL
69#define IFF_UP 0x1 /* interface is up */
70#define IFF_BROADCAST 0x2 /* broadcast address valid */
71#define IFF_DEBUG 0x4 /* turn on debugging */
63de846e 72/* was IFF_ROUTE 0x8 /* routing entry installed */
dc39362e 73#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
a62dd253 74#define IFF_NOTRAILERS 0x20 /* avoid use of trailers */
81889e84 75#define IFF_RUNNING 0x40 /* resources allocated */
2effa891 76#define IFF_NOARP 0x80 /* no address resolution protocol */
63de846e
MK
77 /* flags set internally only: */
78#define IFF_CANTCHANGE (IFF_BROADCAST | IFF_POINTOPOINT | IFF_RUNNING)
ee787340 79
f1b2fa5b
BJ
80/*
81 * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
82 * input routines have queues of messages stored on ifqueue structures
83 * (defined above). Entries are added to and deleted from these structures
84 * by these macros, which should be called with ipl raised to splimp().
85 */
1e977657
BJ
86#define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
87#define IF_DROP(ifq) ((ifq)->ifq_drops++)
8a13b737
BJ
88#define IF_ENQUEUE(ifq, m) { \
89 (m)->m_act = 0; \
90 if ((ifq)->ifq_tail == 0) \
405c9168 91 (ifq)->ifq_head = m; \
8a13b737
BJ
92 else \
93 (ifq)->ifq_tail->m_act = m; \
405c9168 94 (ifq)->ifq_tail = m; \
1e977657 95 (ifq)->ifq_len++; \
8a13b737 96}
e740a894
BJ
97#define IF_PREPEND(ifq, m) { \
98 (m)->m_act = (ifq)->ifq_head; \
1dd55890
BJ
99 if ((ifq)->ifq_tail == 0) \
100 (ifq)->ifq_tail = (m); \
e740a894 101 (ifq)->ifq_head = (m); \
1e977657 102 (ifq)->ifq_len++; \
e740a894 103}
8a13b737
BJ
104#define IF_DEQUEUE(ifq, m) { \
105 (m) = (ifq)->ifq_head; \
106 if (m) { \
107 if (((ifq)->ifq_head = (m)->m_act) == 0) \
108 (ifq)->ifq_tail = 0; \
109 (m)->m_act = 0; \
1e977657 110 (ifq)->ifq_len--; \
8a13b737
BJ
111 } \
112}
665ce890 113
1e977657 114#define IFQ_MAXLEN 50
de602274 115#define IFNET_SLOWHZ 1 /* granularity is 1 second */
1e977657 116
63de846e
MK
117/*
118 * The ifaddr structure contains information about one address
119 * of an interface. They are maintained by the different address families,
120 * are allocated and attached when an address is set, and are linked
121 * together so all addresses for an interface can be located.
122 */
123struct ifaddr {
124 struct sockaddr ifa_addr; /* address of interface */
125 union {
126 struct sockaddr ifu_broadaddr;
127 struct sockaddr ifu_dstaddr;
128 } ifa_ifu;
129#define ifa_broadaddr ifa_ifu.ifu_broadaddr /* broadcast address */
130#define ifa_dstaddr ifa_ifu.ifu_dstaddr /* other end of p-to-p link */
131 struct ifnet *ifa_ifp; /* back-pointer to interface */
132 struct ifaddr *ifa_next; /* next address for interface */
133};
134
0c33c832 135/*
a62dd253
SL
136 * Interface request structure used for socket
137 * ioctl's. All interface ioctl's must have parameter
138 * definitions which begin with ifr_name. The
139 * remainder may be interface specific.
0c33c832
SL
140 */
141struct ifreq {
a62dd253
SL
142#define IFNAMSIZ 16
143 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
0c33c832
SL
144 union {
145 struct sockaddr ifru_addr;
146 struct sockaddr ifru_dstaddr;
bdef13f6 147 struct sockaddr ifru_broadaddr;
0c33c832 148 short ifru_flags;
a62dd253 149 caddr_t ifru_data;
0c33c832
SL
150 } ifr_ifru;
151#define ifr_addr ifr_ifru.ifru_addr /* address */
152#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
bdef13f6 153#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
0c33c832 154#define ifr_flags ifr_ifru.ifru_flags /* flags */
a62dd253 155#define ifr_data ifr_ifru.ifru_data /* for use by interface */
0c33c832
SL
156};
157
158/*
159 * Structure used in SIOCGIFCONF request.
160 * Used to retrieve interface configuration
161 * for machine (useful for programs which
162 * must know all networks accessible).
163 */
164struct ifconf {
165 int ifc_len; /* size of associated buffer */
166 union {
167 caddr_t ifcu_buf;
168 struct ifreq *ifcu_req;
169 } ifc_ifcu;
170#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
171#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
172};
173
cf09d0b0
MK
174/*
175 * ARP ioctl request
176 */
177struct arpreq {
178 struct sockaddr arp_pa; /* protocol address */
179 struct sockaddr arp_ha; /* hardware address */
180 int arp_flags; /* flags */
181};
182/* arp_flags and at_flags field values */
183#define ATF_INUSE 1 /* entry in use */
184#define ATF_COM 2 /* completed entry (enaddr valid) */
185#define ATF_PERM 4 /* permanent entry */
186#define ATF_PUBL 8 /* publish entry (respond for other host) */
187
665ce890 188#ifdef KERNEL
8a13b737
BJ
189#ifdef INET
190struct ifqueue ipintrq; /* ip packet input queue */
191#endif
ee787340 192struct ifqueue rawintrq; /* raw packet input queue */
665ce890 193struct ifnet *ifnet;
63de846e 194struct ifaddr *ifa_ifwithaddr(), *ifa_ifwithnet(), *ifa_ifwithaf();
665ce890 195#endif