1 | /* |
---|
2 | * Copyright (c) 1982, 1986, 1989, 1993 |
---|
3 | * The Regents of the University of California. All rights reserved. |
---|
4 | * |
---|
5 | * Redistribution and use in source and binary forms, with or without |
---|
6 | * modification, are permitted provided that the following conditions |
---|
7 | * are met: |
---|
8 | * 1. Redistributions of source code must retain the above copyright |
---|
9 | * notice, this list of conditions and the following disclaimer. |
---|
10 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
11 | * notice, this list of conditions and the following disclaimer in the |
---|
12 | * documentation and/or other materials provided with the distribution. |
---|
13 | * 4. Neither the name of the University nor the names of its contributors |
---|
14 | * may be used to endorse or promote products derived from this software |
---|
15 | * without specific prior written permission. |
---|
16 | * |
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
---|
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
---|
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
27 | * SUCH DAMAGE. |
---|
28 | * |
---|
29 | * From: @(#)if.h 8.1 (Berkeley) 6/10/93 |
---|
30 | * $FreeBSD: src/sys/net/if_var.h,v 1.107 2006/06/19 22:20:44 mlaier Exp $ |
---|
31 | */ |
---|
32 | |
---|
33 | /* |
---|
34 | * $Id$ |
---|
35 | */ |
---|
36 | |
---|
37 | #ifndef _NET_IF_VAR_H_ |
---|
38 | #define _NET_IF_VAR_H_ |
---|
39 | |
---|
40 | /* |
---|
41 | * Structures defining a network interface, providing a packet |
---|
42 | * transport mechanism (ala level 0 of the PUP protocols). |
---|
43 | * |
---|
44 | * Each interface accepts output datagrams of a specified maximum |
---|
45 | * length, and provides higher level routines with input datagrams |
---|
46 | * received from its medium. |
---|
47 | * |
---|
48 | * Output occurs when the routine if_output is called, with three parameters: |
---|
49 | * (*ifp->if_output)(ifp, m, dst, rt) |
---|
50 | * Here m is the mbuf chain to be sent and dst is the destination address. |
---|
51 | * The output routine encapsulates the supplied datagram if necessary, |
---|
52 | * and then transmits it on its medium. |
---|
53 | * |
---|
54 | * On input, each interface unwraps the data received by it, and either |
---|
55 | * places it on the input queue of an internetwork datagram routine |
---|
56 | * and posts the associated software interrupt, or passes the datagram to a raw |
---|
57 | * packet input routine. |
---|
58 | * |
---|
59 | * Routines exist for locating interfaces by their addresses |
---|
60 | * or for locating an interface on a certain network, as well as more general |
---|
61 | * routing and gateway routines maintaining information used to locate |
---|
62 | * interfaces. These routines live in the files if.c and route.c |
---|
63 | */ |
---|
64 | |
---|
65 | /* |
---|
66 | * Forward structure declarations for function prototypes [sic]. |
---|
67 | */ |
---|
68 | struct mbuf; |
---|
69 | #ifndef __rtems__ |
---|
70 | struct thread; |
---|
71 | #endif |
---|
72 | struct rtentry; |
---|
73 | struct rt_addrinfo; |
---|
74 | struct socket; |
---|
75 | struct ether_header; |
---|
76 | #ifndef __rtems__ |
---|
77 | struct carp_if; |
---|
78 | #endif |
---|
79 | |
---|
80 | #include <rtems/bsd/sys/queue.h> /* get TAILQ macros */ |
---|
81 | |
---|
82 | /* |
---|
83 | * Structure defining a queue for a network interface. |
---|
84 | */ |
---|
85 | struct ifqueue { |
---|
86 | struct mbuf *ifq_head; |
---|
87 | struct mbuf *ifq_tail; |
---|
88 | int ifq_len; |
---|
89 | int ifq_maxlen; |
---|
90 | int ifq_drops; |
---|
91 | }; |
---|
92 | |
---|
93 | /* |
---|
94 | * Structure defining a network interface. |
---|
95 | * |
---|
96 | * (Would like to call this struct ``if'', but C isn't PL/1.) |
---|
97 | */ |
---|
98 | struct ifnet { |
---|
99 | void *if_softc; /* pointer to driver state */ |
---|
100 | char *if_name; /* name, e.g. ``en'' or ``lo'' */ |
---|
101 | struct ifnet *if_next; /* all struct ifnets are chained */ |
---|
102 | struct ifaddr *if_addrlist; /* linked list of addresses per if */ |
---|
103 | int if_pcount; /* number of promiscuous listeners */ |
---|
104 | struct bpf_if *if_bpf; /* packet filter structure */ |
---|
105 | u_short if_index; /* numeric abbreviation for this if */ |
---|
106 | short if_unit; /* sub-unit for lower level driver */ |
---|
107 | short if_timer; /* time 'til if_watchdog called */ |
---|
108 | int if_flags; /* up/down, broadcast, etc. */ |
---|
109 | void *if_linkmib; /* link-type-specific MIB data */ |
---|
110 | size_t if_linkmiblen; /* length of above data */ |
---|
111 | struct if_data if_data; |
---|
112 | /* procedure handles */ |
---|
113 | int (*if_output) /* output routine (enqueue) */ |
---|
114 | (struct ifnet *, struct mbuf *, struct sockaddr *, |
---|
115 | struct rtentry *); |
---|
116 | void (*if_start) /* initiate output routine */ |
---|
117 | (struct ifnet *); |
---|
118 | int (*if_ioctl) /* ioctl routine */ |
---|
119 | (struct ifnet *, ioctl_command_t, caddr_t); |
---|
120 | void (*if_watchdog) /* timer routine */ |
---|
121 | (struct ifnet *); |
---|
122 | int (*if_poll_recv) /* polled receive routine */ |
---|
123 | (struct ifnet *, int *); |
---|
124 | int (*if_poll_xmit) /* polled transmit routine */ |
---|
125 | (struct ifnet *, int *); |
---|
126 | void (*if_poll_intren) /* polled interrupt reenable routine */ |
---|
127 | (struct ifnet *); |
---|
128 | void (*if_poll_slowinput) /* input routine for slow devices */ |
---|
129 | (struct ifnet *, struct mbuf *); |
---|
130 | void (*if_init) /* Init routine */ |
---|
131 | (void *); |
---|
132 | int (*if_tap) /* Packet filter routine */ |
---|
133 | (struct ifnet *, struct ether_header *, struct mbuf *); |
---|
134 | struct ifqueue if_snd; /* output queue */ |
---|
135 | struct ifqueue *if_poll_slowq; /* input queue for slow devices */ |
---|
136 | }; |
---|
137 | |
---|
138 | typedef void if_init_f_t(void *); |
---|
139 | |
---|
140 | /* |
---|
141 | * XXX These aliases are terribly dangerous because they could apply |
---|
142 | * to anything. |
---|
143 | */ |
---|
144 | #define if_mtu if_data.ifi_mtu |
---|
145 | #define if_type if_data.ifi_type |
---|
146 | #define if_physical if_data.ifi_physical |
---|
147 | #define if_addrlen if_data.ifi_addrlen |
---|
148 | #define if_hdrlen if_data.ifi_hdrlen |
---|
149 | #define if_metric if_data.ifi_metric |
---|
150 | #define if_baudrate if_data.ifi_baudrate |
---|
151 | #define if_ipackets if_data.ifi_ipackets |
---|
152 | #define if_ierrors if_data.ifi_ierrors |
---|
153 | #define if_opackets if_data.ifi_opackets |
---|
154 | #define if_oerrors if_data.ifi_oerrors |
---|
155 | #define if_collisions if_data.ifi_collisions |
---|
156 | #define if_ibytes if_data.ifi_ibytes |
---|
157 | #define if_obytes if_data.ifi_obytes |
---|
158 | #define if_imcasts if_data.ifi_imcasts |
---|
159 | #define if_omcasts if_data.ifi_omcasts |
---|
160 | #define if_iqdrops if_data.ifi_iqdrops |
---|
161 | #define if_noproto if_data.ifi_noproto |
---|
162 | #define if_lastchange if_data.ifi_lastchange |
---|
163 | #define if_recvquota if_data.ifi_recvquota |
---|
164 | #define if_xmitquota if_data.ifi_xmitquota |
---|
165 | #define if_rawoutput(if, m, sa) if_output(if, m, sa, (struct rtentry *)NULL) |
---|
166 | |
---|
167 | /* |
---|
168 | * Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq) |
---|
169 | * are queues of messages stored on ifqueue structures |
---|
170 | * (defined above). Entries are added to and deleted from these structures |
---|
171 | * by these macros, which should be called with ipl raised to splimp(). |
---|
172 | */ |
---|
173 | #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) |
---|
174 | #define IF_DROP(ifq) ((ifq)->ifq_drops++) |
---|
175 | |
---|
176 | #define IF_ENQUEUE(ifq, m) do { \ |
---|
177 | (m)->m_nextpkt = NULL; \ |
---|
178 | if ((ifq)->ifq_tail == NULL) \ |
---|
179 | (ifq)->ifq_head = m; \ |
---|
180 | else \ |
---|
181 | (ifq)->ifq_tail->m_nextpkt = m; \ |
---|
182 | (ifq)->ifq_tail = m; \ |
---|
183 | (ifq)->ifq_len++; \ |
---|
184 | } while (0) |
---|
185 | |
---|
186 | #define IF_PREPEND(ifq, m) do { \ |
---|
187 | (m)->m_nextpkt = (ifq)->ifq_head; \ |
---|
188 | if ((ifq)->ifq_tail == NULL) \ |
---|
189 | (ifq)->ifq_tail = (m); \ |
---|
190 | (ifq)->ifq_head = (m); \ |
---|
191 | (ifq)->ifq_len++; \ |
---|
192 | } while (0) |
---|
193 | |
---|
194 | #define IF_DEQUEUE(ifq, m) do { \ |
---|
195 | (m) = (ifq)->ifq_head; \ |
---|
196 | if (m) { \ |
---|
197 | if (((ifq)->ifq_head = (m)->m_nextpkt) == NULL) \ |
---|
198 | (ifq)->ifq_tail = NULL; \ |
---|
199 | (m)->m_nextpkt = NULL; \ |
---|
200 | (ifq)->ifq_len--; \ |
---|
201 | } \ |
---|
202 | } while (0) |
---|
203 | |
---|
204 | /* |
---|
205 | * The ifaddr structure contains information about one address |
---|
206 | * of an interface. They are maintained by the different address families, |
---|
207 | * are allocated and attached when an address is set, and are linked |
---|
208 | * together so all addresses for an interface can be located. |
---|
209 | */ |
---|
210 | struct ifaddr { |
---|
211 | struct sockaddr *ifa_addr; /* address of interface */ |
---|
212 | struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */ |
---|
213 | #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ |
---|
214 | struct sockaddr *ifa_netmask; /* used to determine subnet */ |
---|
215 | struct ifnet *ifa_ifp; /* back-pointer to interface */ |
---|
216 | struct ifaddr *ifa_next; /* next address for interface */ |
---|
217 | void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */ |
---|
218 | (int, struct rtentry *, struct sockaddr *); |
---|
219 | u_short ifa_flags; /* mostly rt_flags for cloning */ |
---|
220 | u_int ifa_refcnt; /* references to this structure */ |
---|
221 | int ifa_metric; /* cost of going out this interface */ |
---|
222 | int (*ifa_claim_addr) /* check if an addr goes to this if */ |
---|
223 | (struct ifaddr *, struct sockaddr *); |
---|
224 | |
---|
225 | }; |
---|
226 | #define IFA_ROUTE RTF_UP /* route installed */ |
---|
227 | |
---|
228 | #ifdef _KERNEL |
---|
229 | #define IFAFREE(ifa) \ |
---|
230 | if ((ifa)->ifa_refcnt <= 0) \ |
---|
231 | ifafree(ifa); \ |
---|
232 | else \ |
---|
233 | (ifa)->ifa_refcnt--; |
---|
234 | |
---|
235 | extern struct ifnet *ifnet; |
---|
236 | extern int ifqmaxlen; |
---|
237 | extern struct ifnet loif[]; |
---|
238 | extern int if_index; |
---|
239 | extern struct ifaddr **ifnet_addrs; |
---|
240 | |
---|
241 | void if_attach(struct ifnet *); |
---|
242 | void if_down(struct ifnet *); |
---|
243 | void if_up(struct ifnet *); |
---|
244 | /*void ifinit(void);*/ /* declared in systm.h for main() */ |
---|
245 | int ifioctl(struct socket *, u_long, caddr_t, struct proc *); |
---|
246 | int ifpromisc(struct ifnet *, int); |
---|
247 | |
---|
248 | struct ifaddr *ifa_ifwithaddr(struct sockaddr *); |
---|
249 | struct ifaddr *ifa_ifwithdstaddr(struct sockaddr *); |
---|
250 | struct ifaddr *ifa_ifwithnet(struct sockaddr *); |
---|
251 | struct ifaddr *ifa_ifwithroute(int, struct sockaddr *, struct sockaddr *); |
---|
252 | struct ifaddr *ifaof_ifpforaddr(struct sockaddr *, struct ifnet *); |
---|
253 | |
---|
254 | #endif /* _KERNEL */ |
---|
255 | |
---|
256 | #endif /* !_NET_IF_VAR_H_ */ |
---|