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