Commit | Line | Data |
---|---|---|
cb1c44c2 | 1 | /* |
ba56c73e | 2 | * Copyright (c) 1982, 1986, 1989 Regents of the University of California. |
5b519e94 | 3 | * All rights reserved. |
cb1c44c2 | 4 | * |
5b519e94 | 5 | * Redistribution and use in source and binary forms are permitted |
50c7758a KB |
6 | * provided that the above copyright notice and this paragraph are |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
5b519e94 | 16 | * |
8b2d214b | 17 | * @(#)if.h 7.7 (Berkeley) %G% |
cb1c44c2 | 18 | */ |
665ce890 BJ |
19 | |
20 | /* | |
f1b2fa5b BJ |
21 | * Structures defining a network interface, providing a packet |
22 | * transport mechanism (ala level 0 of the PUP protocols). | |
23 | * | |
24 | * Each interface accepts output datagrams of a specified maximum | |
25 | * length, and provides higher level routines with input datagrams | |
26 | * received from its medium. | |
27 | * | |
28 | * Output occurs when the routine if_output is called, with three parameters: | |
ee787340 SL |
29 | * (*ifp->if_output)(ifp, m, dst) |
30 | * Here m is the mbuf chain to be sent and dst is the destination address. | |
31 | * The output routine encapsulates the supplied datagram if necessary, | |
32 | * and then transmits it on its medium. | |
f1b2fa5b BJ |
33 | * |
34 | * On input, each interface unwraps the data received by it, and either | |
35 | * places it on the input queue of a internetwork datagram routine | |
36 | * and posts the associated software interrupt, or passes the datagram to a raw | |
37 | * packet input routine. | |
38 | * | |
ee787340 | 39 | * Routines exist for locating interfaces by their addresses |
f1b2fa5b BJ |
40 | * or for locating a interface on a certain network, as well as more general |
41 | * routing and gateway routines maintaining information used to locate | |
ee787340 | 42 | * interfaces. These routines live in the files if.c and route.c |
8a13b737 | 43 | */ |
ba56c73e KS |
44 | #ifndef _TIME_ /* XXX fast fix for SNMP, going away soon */ |
45 | #ifdef KERNEL | |
46 | #include "../sys/time.h" | |
47 | #else | |
48 | #include <sys/time.h> | |
49 | #endif | |
50 | #endif | |
8a13b737 BJ |
51 | |
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 | 58 | struct ifnet { |
b454c3ea | 59 | char *if_name; /* name, e.g. ``en'' or ``lo'' */ |
665ce890 | 60 | short if_unit; /* sub-unit for lower level driver */ |
665ce890 | 61 | short if_mtu; /* maximum transmission unit */ |
ee787340 | 62 | short if_flags; /* up/down, broadcast, etc. */ |
de602274 | 63 | short if_timer; /* time 'til if_watchdog called */ |
484ee22e | 64 | int if_metric; /* routing metric (external only) */ |
63de846e | 65 | struct ifaddr *if_addrlist; /* linked list of addresses per if */ |
f1b2fa5b BJ |
66 | struct ifqueue { |
67 | struct mbuf *ifq_head; | |
68 | struct mbuf *ifq_tail; | |
1e977657 BJ |
69 | int ifq_len; |
70 | int ifq_maxlen; | |
71 | int ifq_drops; | |
f1b2fa5b BJ |
72 | } if_snd; /* output queue */ |
73 | /* procedure handles */ | |
74 | int (*if_init)(); /* init routine */ | |
38a81509 MK |
75 | int (*if_output)(); /* output routine (enqueue) */ |
76 | int (*if_start)(); /* initiate output routine */ | |
77 | int (*if_done)(); /* output complete routine */ | |
a62dd253 | 78 | int (*if_ioctl)(); /* ioctl routine */ |
b3691eab | 79 | int (*if_reset)(); /* bus reset routine */ |
de602274 | 80 | int (*if_watchdog)(); /* timer routine */ |
f1b2fa5b | 81 | /* generic interface statistics */ |
b454c3ea BJ |
82 | int if_ipackets; /* packets received on interface */ |
83 | int if_ierrors; /* input errors on interface */ | |
84 | int if_opackets; /* packets sent on interface */ | |
85 | int if_oerrors; /* output errors on interface */ | |
f1b2fa5b | 86 | int if_collisions; /* collisions on csma interfaces */ |
f1b2fa5b | 87 | /* end statistics */ |
4ad99bae | 88 | struct ifnet *if_next; |
b72a6efb KS |
89 | u_char if_type; /* ethernet, tokenring, etc */ |
90 | u_char if_addrlen; /* media address length */ | |
91 | u_char if_hdrlen; /* media header length */ | |
8b2d214b | 92 | u_char if_index; /* numeric abbreviation for this if */ |
ba56c73e KS |
93 | /* more statistics here to avoid recompiling netstat */ |
94 | struct timeval if_lastchange; /* last updated */ | |
95 | int if_ibytes; /* total number of octets received */ | |
96 | int if_obytes; /* total number of octets sent */ | |
97 | int if_imcasts; /* packets received via multicast */ | |
98 | int if_omcasts; /* packets sent via multicast */ | |
99 | int if_iqdrops; /* dropped on input, this interface */ | |
100 | int if_noproto; /* destined for unsupported protocol */ | |
101 | int if_baudrate; /* linespeed */ | |
665ce890 BJ |
102 | }; |
103 | ||
ee787340 SL |
104 | #define IFF_UP 0x1 /* interface is up */ |
105 | #define IFF_BROADCAST 0x2 /* broadcast address valid */ | |
106 | #define IFF_DEBUG 0x4 /* turn on debugging */ | |
484ee22e | 107 | #define IFF_LOOPBACK 0x8 /* is a loopback net */ |
dc39362e | 108 | #define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */ |
a62dd253 | 109 | #define IFF_NOTRAILERS 0x20 /* avoid use of trailers */ |
81889e84 | 110 | #define IFF_RUNNING 0x40 /* resources allocated */ |
2effa891 | 111 | #define IFF_NOARP 0x80 /* no address resolution protocol */ |
bbe75d63 MK |
112 | /* next two not supported now, but reserved: */ |
113 | #define IFF_PROMISC 0x100 /* receive all packets */ | |
114 | #define IFF_ALLMULTI 0x200 /* receive all multicast packets */ | |
38a81509 MK |
115 | #define IFF_OACTIVE 0x400 /* transmission in progress */ |
116 | #define IFF_SIMPLEX 0x800 /* can't hear own transmissions */ | |
117 | ||
484ee22e | 118 | /* flags set internally only: */ |
38a81509 | 119 | #define IFF_CANTCHANGE (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE) |
ee787340 | 120 | |
f1b2fa5b BJ |
121 | /* |
122 | * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1) | |
123 | * input routines have queues of messages stored on ifqueue structures | |
124 | * (defined above). Entries are added to and deleted from these structures | |
125 | * by these macros, which should be called with ipl raised to splimp(). | |
126 | */ | |
1e977657 BJ |
127 | #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) |
128 | #define IF_DROP(ifq) ((ifq)->ifq_drops++) | |
8a13b737 BJ |
129 | #define IF_ENQUEUE(ifq, m) { \ |
130 | (m)->m_act = 0; \ | |
131 | if ((ifq)->ifq_tail == 0) \ | |
405c9168 | 132 | (ifq)->ifq_head = m; \ |
8a13b737 BJ |
133 | else \ |
134 | (ifq)->ifq_tail->m_act = m; \ | |
405c9168 | 135 | (ifq)->ifq_tail = m; \ |
1e977657 | 136 | (ifq)->ifq_len++; \ |
8a13b737 | 137 | } |
e740a894 BJ |
138 | #define IF_PREPEND(ifq, m) { \ |
139 | (m)->m_act = (ifq)->ifq_head; \ | |
1dd55890 BJ |
140 | if ((ifq)->ifq_tail == 0) \ |
141 | (ifq)->ifq_tail = (m); \ | |
e740a894 | 142 | (ifq)->ifq_head = (m); \ |
1e977657 | 143 | (ifq)->ifq_len++; \ |
e740a894 | 144 | } |
8a13b737 BJ |
145 | #define IF_DEQUEUE(ifq, m) { \ |
146 | (m) = (ifq)->ifq_head; \ | |
147 | if (m) { \ | |
148 | if (((ifq)->ifq_head = (m)->m_act) == 0) \ | |
149 | (ifq)->ifq_tail = 0; \ | |
150 | (m)->m_act = 0; \ | |
1e977657 | 151 | (ifq)->ifq_len--; \ |
8a13b737 BJ |
152 | } \ |
153 | } | |
665ce890 | 154 | |
1e977657 | 155 | #define IFQ_MAXLEN 50 |
de602274 | 156 | #define IFNET_SLOWHZ 1 /* granularity is 1 second */ |
1e977657 | 157 | |
63de846e MK |
158 | /* |
159 | * The ifaddr structure contains information about one address | |
160 | * of an interface. They are maintained by the different address families, | |
161 | * are allocated and attached when an address is set, and are linked | |
162 | * together so all addresses for an interface can be located. | |
163 | */ | |
164 | struct ifaddr { | |
b72a6efb KS |
165 | struct sockaddr *ifa_addr; /* address of interface */ |
166 | struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */ | |
167 | #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ | |
168 | struct sockaddr *ifa_netmask; /* used to determine subnet */ | |
63de846e MK |
169 | struct ifnet *ifa_ifp; /* back-pointer to interface */ |
170 | struct ifaddr *ifa_next; /* next address for interface */ | |
8b2d214b KS |
171 | int (*ifa_rtrequest)(); /* check or clean routes (+ or -)'d */ |
172 | struct rtentry *ifa_rt; /* ??? for ROUTETOIF */ | |
173 | u_short ifa_flags; /* mostly rt_flags for cloning */ | |
174 | u_short ifa_llinfolen; /* extra to malloc for link info */ | |
63de846e | 175 | }; |
8b2d214b | 176 | #define IFA_ROUTE RTF_UP /* route installed */ |
0c33c832 | 177 | /* |
a62dd253 SL |
178 | * Interface request structure used for socket |
179 | * ioctl's. All interface ioctl's must have parameter | |
180 | * definitions which begin with ifr_name. The | |
181 | * remainder may be interface specific. | |
0c33c832 SL |
182 | */ |
183 | struct ifreq { | |
a62dd253 SL |
184 | #define IFNAMSIZ 16 |
185 | char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ | |
0c33c832 SL |
186 | union { |
187 | struct sockaddr ifru_addr; | |
188 | struct sockaddr ifru_dstaddr; | |
bdef13f6 | 189 | struct sockaddr ifru_broadaddr; |
0c33c832 | 190 | short ifru_flags; |
484ee22e | 191 | int ifru_metric; |
a62dd253 | 192 | caddr_t ifru_data; |
0c33c832 SL |
193 | } ifr_ifru; |
194 | #define ifr_addr ifr_ifru.ifru_addr /* address */ | |
195 | #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ | |
bdef13f6 | 196 | #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ |
0c33c832 | 197 | #define ifr_flags ifr_ifru.ifru_flags /* flags */ |
484ee22e | 198 | #define ifr_metric ifr_ifru.ifru_metric /* metric */ |
a62dd253 | 199 | #define ifr_data ifr_ifru.ifru_data /* for use by interface */ |
0c33c832 SL |
200 | }; |
201 | ||
b72a6efb KS |
202 | struct ifaliasreq { |
203 | char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ | |
204 | struct sockaddr ifra_addr; | |
205 | struct sockaddr ifra_broadaddr; | |
206 | struct sockaddr ifra_mask; | |
207 | }; | |
208 | ||
0c33c832 SL |
209 | /* |
210 | * Structure used in SIOCGIFCONF request. | |
211 | * Used to retrieve interface configuration | |
212 | * for machine (useful for programs which | |
213 | * must know all networks accessible). | |
214 | */ | |
215 | struct ifconf { | |
216 | int ifc_len; /* size of associated buffer */ | |
217 | union { | |
218 | caddr_t ifcu_buf; | |
219 | struct ifreq *ifcu_req; | |
220 | } ifc_ifcu; | |
221 | #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ | |
222 | #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ | |
223 | }; | |
224 | ||
665ce890 | 225 | #ifdef KERNEL |
d66f7a18 | 226 | #include "../net/if_arp.h" |
ee787340 | 227 | struct ifqueue rawintrq; /* raw packet input queue */ |
665ce890 | 228 | struct ifnet *ifnet; |
2612fc91 | 229 | struct ifaddr *ifa_ifwithaddr(), *ifa_ifwithnet(); |
87e42a46 | 230 | struct ifaddr *ifa_ifwithdstaddr(); |
d66f7a18 MK |
231 | #else KERNEL |
232 | #include <net/if_arp.h> | |
233 | #endif KERNEL |