add bpf
[unix-history] / usr / src / sys / net / if.h
CommitLineData
cb1c44c2 1/*
ba56c73e 2 * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
5b519e94 3 * All rights reserved.
cb1c44c2 4 *
dbf0c423 5 * %sccs.include.redist.c%
5b519e94 6 *
3d424137 7 * @(#)if.h 7.10 (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:
ee787340
SL
19 * (*ifp->if_output)(ifp, m, dst)
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
KS
34#ifndef _TIME_ /* XXX fast fix for SNMP, going away soon */
35#ifdef KERNEL
36#include "../sys/time.h"
37#else
38#include <sys/time.h>
39#endif
40#endif
8a13b737
BJ
41
42/*
43 * Structure defining a queue for a network interface.
665ce890
BJ
44 *
45 * (Would like to call this struct ``if'', but C isn't PL/1.)
46 */
ba56c73e 47
665ce890 48struct ifnet {
b454c3ea 49 char *if_name; /* name, e.g. ``en'' or ``lo'' */
665ce890 50 short if_unit; /* sub-unit for lower level driver */
665ce890 51 short if_mtu; /* maximum transmission unit */
ee787340 52 short if_flags; /* up/down, broadcast, etc. */
de602274 53 short if_timer; /* time 'til if_watchdog called */
484ee22e 54 int if_metric; /* routing metric (external only) */
63de846e 55 struct ifaddr *if_addrlist; /* linked list of addresses per if */
f1b2fa5b
BJ
56 struct ifqueue {
57 struct mbuf *ifq_head;
58 struct mbuf *ifq_tail;
1e977657
BJ
59 int ifq_len;
60 int ifq_maxlen;
61 int ifq_drops;
f1b2fa5b
BJ
62 } if_snd; /* output queue */
63/* procedure handles */
64 int (*if_init)(); /* init routine */
38a81509
MK
65 int (*if_output)(); /* output routine (enqueue) */
66 int (*if_start)(); /* initiate output routine */
67 int (*if_done)(); /* output complete routine */
a62dd253 68 int (*if_ioctl)(); /* ioctl routine */
b3691eab 69 int (*if_reset)(); /* bus reset routine */
de602274 70 int (*if_watchdog)(); /* timer routine */
f1b2fa5b 71/* generic interface statistics */
b454c3ea
BJ
72 int if_ipackets; /* packets received on interface */
73 int if_ierrors; /* input errors on interface */
74 int if_opackets; /* packets sent on interface */
75 int if_oerrors; /* output errors on interface */
f1b2fa5b 76 int if_collisions; /* collisions on csma interfaces */
f1b2fa5b 77/* end statistics */
4ad99bae 78 struct ifnet *if_next;
b72a6efb
KS
79 u_char if_type; /* ethernet, tokenring, etc */
80 u_char if_addrlen; /* media address length */
81 u_char if_hdrlen; /* media header length */
8b2d214b 82 u_char if_index; /* numeric abbreviation for this if */
ba56c73e
KS
83/* more statistics here to avoid recompiling netstat */
84 struct timeval if_lastchange; /* last updated */
85 int if_ibytes; /* total number of octets received */
86 int if_obytes; /* total number of octets sent */
87 int if_imcasts; /* packets received via multicast */
88 int if_omcasts; /* packets sent via multicast */
89 int if_iqdrops; /* dropped on input, this interface */
90 int if_noproto; /* destined for unsupported protocol */
91 int if_baudrate; /* linespeed */
665ce890
BJ
92};
93
ee787340
SL
94#define IFF_UP 0x1 /* interface is up */
95#define IFF_BROADCAST 0x2 /* broadcast address valid */
96#define IFF_DEBUG 0x4 /* turn on debugging */
484ee22e 97#define IFF_LOOPBACK 0x8 /* is a loopback net */
dc39362e 98#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
a62dd253 99#define IFF_NOTRAILERS 0x20 /* avoid use of trailers */
81889e84 100#define IFF_RUNNING 0x40 /* resources allocated */
2effa891 101#define IFF_NOARP 0x80 /* no address resolution protocol */
bbe75d63
MK
102/* next two not supported now, but reserved: */
103#define IFF_PROMISC 0x100 /* receive all packets */
104#define IFF_ALLMULTI 0x200 /* receive all multicast packets */
38a81509
MK
105#define IFF_OACTIVE 0x400 /* transmission in progress */
106#define IFF_SIMPLEX 0x800 /* can't hear own transmissions */
107
484ee22e 108/* flags set internally only: */
3d424137
MK
109#define IFF_CANTCHANGE \
110 (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|IFF_SIMPLEX)
ee787340 111
f1b2fa5b
BJ
112/*
113 * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
114 * input routines have queues of messages stored on ifqueue structures
115 * (defined above). Entries are added to and deleted from these structures
116 * by these macros, which should be called with ipl raised to splimp().
117 */
1e977657
BJ
118#define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
119#define IF_DROP(ifq) ((ifq)->ifq_drops++)
8a13b737 120#define IF_ENQUEUE(ifq, m) { \
0428a0b2 121 (m)->m_nextpkt = 0; \
8a13b737 122 if ((ifq)->ifq_tail == 0) \
405c9168 123 (ifq)->ifq_head = m; \
8a13b737 124 else \
0428a0b2 125 (ifq)->ifq_tail->m_nextpkt = m; \
405c9168 126 (ifq)->ifq_tail = m; \
1e977657 127 (ifq)->ifq_len++; \
8a13b737 128}
e740a894 129#define IF_PREPEND(ifq, m) { \
0428a0b2 130 (m)->m_nextpkt = (ifq)->ifq_head; \
1dd55890
BJ
131 if ((ifq)->ifq_tail == 0) \
132 (ifq)->ifq_tail = (m); \
e740a894 133 (ifq)->ifq_head = (m); \
1e977657 134 (ifq)->ifq_len++; \
e740a894 135}
8a13b737
BJ
136#define IF_DEQUEUE(ifq, m) { \
137 (m) = (ifq)->ifq_head; \
138 if (m) { \
0428a0b2 139 if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
8a13b737 140 (ifq)->ifq_tail = 0; \
0428a0b2 141 (m)->m_nextpkt = 0; \
1e977657 142 (ifq)->ifq_len--; \
8a13b737
BJ
143 } \
144}
665ce890 145
1e977657 146#define IFQ_MAXLEN 50
de602274 147#define IFNET_SLOWHZ 1 /* granularity is 1 second */
1e977657 148
63de846e
MK
149/*
150 * The ifaddr structure contains information about one address
151 * of an interface. They are maintained by the different address families,
152 * are allocated and attached when an address is set, and are linked
153 * together so all addresses for an interface can be located.
154 */
155struct ifaddr {
b72a6efb
KS
156 struct sockaddr *ifa_addr; /* address of interface */
157 struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */
158#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
159 struct sockaddr *ifa_netmask; /* used to determine subnet */
63de846e
MK
160 struct ifnet *ifa_ifp; /* back-pointer to interface */
161 struct ifaddr *ifa_next; /* next address for interface */
8b2d214b
KS
162 int (*ifa_rtrequest)(); /* check or clean routes (+ or -)'d */
163 struct rtentry *ifa_rt; /* ??? for ROUTETOIF */
164 u_short ifa_flags; /* mostly rt_flags for cloning */
165 u_short ifa_llinfolen; /* extra to malloc for link info */
63de846e 166};
8b2d214b 167#define IFA_ROUTE RTF_UP /* route installed */
0c33c832 168/*
a62dd253
SL
169 * Interface request structure used for socket
170 * ioctl's. All interface ioctl's must have parameter
171 * definitions which begin with ifr_name. The
172 * remainder may be interface specific.
0c33c832
SL
173 */
174struct ifreq {
a62dd253
SL
175#define IFNAMSIZ 16
176 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
0c33c832
SL
177 union {
178 struct sockaddr ifru_addr;
179 struct sockaddr ifru_dstaddr;
bdef13f6 180 struct sockaddr ifru_broadaddr;
0c33c832 181 short ifru_flags;
484ee22e 182 int ifru_metric;
a62dd253 183 caddr_t ifru_data;
0c33c832
SL
184 } ifr_ifru;
185#define ifr_addr ifr_ifru.ifru_addr /* address */
186#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
bdef13f6 187#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
0c33c832 188#define ifr_flags ifr_ifru.ifru_flags /* flags */
484ee22e 189#define ifr_metric ifr_ifru.ifru_metric /* metric */
a62dd253 190#define ifr_data ifr_ifru.ifru_data /* for use by interface */
0c33c832
SL
191};
192
b72a6efb
KS
193struct ifaliasreq {
194 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
195 struct sockaddr ifra_addr;
196 struct sockaddr ifra_broadaddr;
197 struct sockaddr ifra_mask;
198};
199
0c33c832
SL
200/*
201 * Structure used in SIOCGIFCONF request.
202 * Used to retrieve interface configuration
203 * for machine (useful for programs which
204 * must know all networks accessible).
205 */
206struct ifconf {
207 int ifc_len; /* size of associated buffer */
208 union {
209 caddr_t ifcu_buf;
210 struct ifreq *ifcu_req;
211 } ifc_ifcu;
212#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
213#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
214};
215
665ce890 216#ifdef KERNEL
d66f7a18 217#include "../net/if_arp.h"
ee787340 218struct ifqueue rawintrq; /* raw packet input queue */
665ce890 219struct ifnet *ifnet;
2612fc91 220struct ifaddr *ifa_ifwithaddr(), *ifa_ifwithnet();
87e42a46 221struct ifaddr *ifa_ifwithdstaddr();
d66f7a18
MK
222#else KERNEL
223#include <net/if_arp.h>
224#endif KERNEL