Deleted Added
full compact
pdq_ifsubr.c (26640) pdq_ifsubr.c (32350)
1/*-
2 * Copyright (c) 1995, 1996 Matt Thomas <matt@3am-software.com>
3 * 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. The name of the author may not be used to endorse or promote products
11 * derived from this software withough specific prior written permission
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
1/*-
2 * Copyright (c) 1995, 1996 Matt Thomas <matt@3am-software.com>
3 * 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. The name of the author may not be used to endorse or promote products
11 * derived from this software withough specific prior written permission
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * $Id: pdq_ifsubr.c,v 1.4 1997/03/24 11:32:26 bde Exp $
24 * $Id: pdq_ifsubr.c,v 1.5 1997/06/14 13:56:07 bde Exp $
25 *
26 */
27
28/*
29 * DEC PDQ FDDI Controller; code for BSD derived operating systems
30 *
31 * This module provide bus independent BSD specific O/S functions.
32 * (ie. it provides an ifnet interface to the rest of the system)
33 */
34
35
25 *
26 */
27
28/*
29 * DEC PDQ FDDI Controller; code for BSD derived operating systems
30 *
31 * This module provide bus independent BSD specific O/S functions.
32 * (ie. it provides an ifnet interface to the rest of the system)
33 */
34
35
36#include "opt_inet.h"
37
36#include <sys/param.h>
37#include <sys/socket.h>
38#include <sys/sockio.h>
39#if defined(__bsdi__) || defined(__NetBSD__)
40#include <sys/device.h>
41#endif
42
43#include <net/if.h>
44#include <net/if_dl.h>
45
46#include "bpfilter.h"
47#if NBPFILTER > 0
48#include <net/bpf.h>
49#endif
50
38#include <sys/param.h>
39#include <sys/socket.h>
40#include <sys/sockio.h>
41#if defined(__bsdi__) || defined(__NetBSD__)
42#include <sys/device.h>
43#endif
44
45#include <net/if.h>
46#include <net/if_dl.h>
47
48#include "bpfilter.h"
49#if NBPFILTER > 0
50#include <net/bpf.h>
51#endif
52
53#if defined(__FreeBSD__)
54#include <net/ethernet.h>
55#include <net/if_arp.h>
51#ifdef INET
52#include <netinet/in.h>
53#include <netinet/if_ether.h>
54#endif
56#ifdef INET
57#include <netinet/in.h>
58#include <netinet/if_ether.h>
59#endif
55#if defined(__FreeBSD__)
56#include <netinet/if_fddi.h>
57#else
58#include <net/if_fddi.h>
59#endif
60
61#if defined(__bsdi__)
62#include <i386/isa/isavar.h>
63#endif
64
65#ifdef NS
66#include <netns/ns.h>
67#include <netns/ns_if.h>
68#endif
69
70#if defined(__FreeBSD__)
71#include <dev/pdq/pdqvar.h>
72#include <dev/pdq/pdqreg.h>
73#else
74#include "pdqvar.h"
75#include "pdqreg.h"
76#endif
77
78#if defined(__bsdi__) && _BSDI_VERSION < 199506 /* XXX */
79static void
80arp_ifinit(
81 struct arpcom *ac,
82 struct ifaddr *ifa)
83{
84 sc->sc_ac.ac_ipaddr = IA_SIN(ifa)->sin_addr;
85 arpwhohas(&sc->sc_ac, &IA_SIN(ifa)->sin_addr);
86#if _BSDI_VERSION >= 199401
87 ifa->ifa_rtrequest = arp_rtrequest;
88 ifa->ifa_flags |= RTF_CLONING;
89#endif
90#endif
91
92
93void
94pdq_ifinit(
95 pdq_softc_t *sc)
96{
97 if (sc->sc_if.if_flags & IFF_UP) {
98 sc->sc_if.if_flags |= IFF_RUNNING;
99 if (sc->sc_if.if_flags & IFF_PROMISC) {
100 sc->sc_pdq->pdq_flags |= PDQ_PROMISC;
101 } else {
102 sc->sc_pdq->pdq_flags &= ~PDQ_PROMISC;
103 }
104 if (sc->sc_if.if_flags & IFF_ALLMULTI) {
105 sc->sc_pdq->pdq_flags |= PDQ_ALLMULTI;
106 } else {
107 sc->sc_pdq->pdq_flags &= ~PDQ_ALLMULTI;
108 }
109 if (sc->sc_if.if_flags & IFF_LINK1) {
110 sc->sc_pdq->pdq_flags |= PDQ_PASS_SMT;
111 } else {
112 sc->sc_pdq->pdq_flags &= ~PDQ_PASS_SMT;
113 }
114 sc->sc_pdq->pdq_flags |= PDQ_RUNNING;
115 pdq_run(sc->sc_pdq);
116 } else {
117 sc->sc_if.if_flags &= ~IFF_RUNNING;
118 sc->sc_pdq->pdq_flags &= ~PDQ_RUNNING;
119 pdq_stop(sc->sc_pdq);
120 }
121}
122
123void
124pdq_ifwatchdog(
125 struct ifnet *ifp)
126{
127 /*
128 * No progress was made on the transmit queue for PDQ_OS_TX_TRANSMIT
129 * seconds. Remove all queued packets.
130 */
131
132 ifp->if_flags &= ~IFF_OACTIVE;
133 ifp->if_timer = 0;
134 for (;;) {
135 struct mbuf *m;
136 IF_DEQUEUE(&ifp->if_snd, m);
137 if (m == NULL)
138 return;
139 m_freem(m);
140 }
141}
142
143ifnet_ret_t
144pdq_ifstart(
145 struct ifnet *ifp)
146{
147 pdq_softc_t *sc = (pdq_softc_t *) ((caddr_t) ifp - offsetof(pdq_softc_t, sc_ac.ac_if));
148 struct ifqueue *ifq = &ifp->if_snd;
149 struct mbuf *m;
150 int tx = 0;
151
152 if ((ifp->if_flags & IFF_RUNNING) == 0)
153 return;
154
155 if (sc->sc_if.if_timer == 0)
156 sc->sc_if.if_timer = PDQ_OS_TX_TIMEOUT;
157
158 if ((sc->sc_pdq->pdq_flags & PDQ_TXOK) == 0) {
159 sc->sc_if.if_flags |= IFF_OACTIVE;
160 return;
161 }
162 for (;; tx = 1) {
163 IF_DEQUEUE(ifq, m);
164 if (m == NULL)
165 break;
166
167 if (pdq_queue_transmit_data(sc->sc_pdq, m) == PDQ_FALSE) {
168 ifp->if_flags |= IFF_OACTIVE;
169 IF_PREPEND(ifq, m);
170 break;
171 }
172 }
173 if (tx)
174 PDQ_DO_TYPE2_PRODUCER(sc->sc_pdq);
175}
176
177void
178pdq_os_receive_pdu(
179 pdq_t *pdq,
180 struct mbuf *m,
181 size_t pktlen)
182{
183 pdq_softc_t *sc = (pdq_softc_t *) pdq->pdq_os_ctx;
184 struct fddi_header *fh = mtod(m, struct fddi_header *);
185
186 sc->sc_if.if_ipackets++;
187#if NBPFILTER > 0
188 if (sc->sc_bpf != NULL)
189 PDQ_BPF_MTAP(sc, m);
190 if ((fh->fddi_fc & (FDDIFC_L|FDDIFC_F)) != FDDIFC_LLC_ASYNC) {
191 m_freem(m);
192 return;
193 }
194#endif
195
196 m->m_data += sizeof(struct fddi_header);
197 m->m_len -= sizeof(struct fddi_header);
198 m->m_pkthdr.len = pktlen - sizeof(struct fddi_header);
199 m->m_pkthdr.rcvif = &sc->sc_if;
200 fddi_input(&sc->sc_if, fh, m);
201}
202
203void
204pdq_os_restart_transmitter(
205 pdq_t *pdq)
206{
207 pdq_softc_t *sc = (pdq_softc_t *) pdq->pdq_os_ctx;
208 sc->sc_if.if_flags &= ~IFF_OACTIVE;
209 if (sc->sc_if.if_snd.ifq_head != NULL) {
210 sc->sc_if.if_timer = PDQ_OS_TX_TIMEOUT;
211 pdq_ifstart(&sc->sc_if);
212 } else {
213 sc->sc_if.if_timer = 0;
214 }
215}
216
217void
218pdq_os_transmit_done(
219 pdq_t *pdq,
220 struct mbuf *m)
221{
222 pdq_softc_t *sc = (pdq_softc_t *) pdq->pdq_os_ctx;
223#if NBPFILTER > 0
224 if (sc->sc_bpf != NULL)
225 PDQ_BPF_MTAP(sc, m);
226#endif
227 m_freem(m);
228 sc->sc_if.if_opackets++;
229}
230
231void
232pdq_os_addr_fill(
233 pdq_t *pdq,
234 pdq_lanaddr_t *addr,
235 size_t num_addrs)
236{
237 pdq_softc_t *sc = (pdq_softc_t *) pdq->pdq_os_ctx;
238 struct ifmultiaddr *ifma;
239
240 for (ifma = sc->sc_if.if_multiaddrs.lh_first; ifma && num_addrs > 0;
241 ifma = ifma->ifma_link.le_next) {
242 char *mcaddr;
243 if (ifma->ifma_addr->sa_family != AF_LINK)
244 continue;
245 mcaddr = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
246 ((u_short *) addr->lanaddr_bytes)[0] = ((u_short *) mcaddr)[0];
247 ((u_short *) addr->lanaddr_bytes)[1] = ((u_short *) mcaddr)[1];
248 ((u_short *) addr->lanaddr_bytes)[2] = ((u_short *) mcaddr)[2];
249 addr++;
250 num_addrs--;
251 }
252}
253
254int
255pdq_ifioctl(
256 struct ifnet *ifp,
257 ioctl_cmd_t cmd,
258 caddr_t data)
259{
260 pdq_softc_t *sc = (pdq_softc_t *) ((caddr_t) ifp - offsetof(pdq_softc_t, sc_ac.ac_if));
261 int s, error = 0;
262
263 s = splimp();
264
265 switch (cmd) {
266 case SIOCSIFADDR: {
267 struct ifaddr *ifa = (struct ifaddr *)data;
268
269 ifp->if_flags |= IFF_UP;
270 switch(ifa->ifa_addr->sa_family) {
271#if defined(INET)
272 case AF_INET: {
273 pdq_ifinit(sc);
274 arp_ifinit(&sc->sc_ac, ifa);
275 break;
276 }
277#endif /* INET */
278
279#if defined(NS)
280 /* This magic copied from if_is.c; I don't use XNS,
281 * so I have no way of telling if this actually
282 * works or not.
283 */
284 case AF_NS: {
285 struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
286 if (ns_nullhost(*ina)) {
287 ina->x_host = *(union ns_host *)(sc->sc_ac.ac_enaddr);
288 } else {
289 ifp->if_flags &= ~IFF_RUNNING;
290 bcopy((caddr_t)ina->x_host.c_host,
291 (caddr_t)sc->sc_ac.ac_enaddr,
292 sizeof sc->sc_ac.ac_enaddr);
293 }
294
295 pdq_ifinit(sc);
296 break;
297 }
298#endif /* NS */
299
300 default: {
301 pdq_ifinit(sc);
302 break;
303 }
304 }
305 break;
306 }
307 case SIOCGIFADDR: {
308 struct ifreq *ifr = (struct ifreq *)data;
309 bcopy((caddr_t) sc->sc_ac.ac_enaddr,
310 (caddr_t) ((struct sockaddr *)&ifr->ifr_data)->sa_data,
311 6);
312 break;
313 }
314
315 case SIOCSIFFLAGS: {
316 pdq_ifinit(sc);
317 break;
318 }
319
320 case SIOCADDMULTI:
321 case SIOCDELMULTI:
322 /*
323 * Update multicast listeners
324 */
325 if (sc->sc_if.if_flags & IFF_RUNNING)
326 pdq_run(sc->sc_pdq);
327 error = 0;
328 break;
329
330#if defined(SIOCSIFMTU)
331#if !defined(ifr_mtu)
332#define ifr_mtu ifr_metric
333#endif
334 case SIOCSIFMTU: {
335 struct ifreq *ifr = (struct ifreq *)data;
336 /*
337 * Set the interface MTU.
338 */
339 if (ifr->ifr_mtu > FDDIMTU) {
340 error = EINVAL;
341 break;
342 }
343 ifp->if_mtu = ifr->ifr_mtu;
344 break;
345 }
346#endif /* SIOCSIFMTU */
347
348 default: {
349 error = EINVAL;
350 break;
351 }
352 }
353
354 splx(s);
355 return error;
356}
357
358#ifndef IFF_NOTRAILERS
359#define IFF_NOTRAILERS 0
360#endif
361
362void
363pdq_ifattach(
364 pdq_softc_t *sc,
365 ifnet_ret_t (*ifwatchdog)(int unit))
366{
367 struct ifnet *ifp = &sc->sc_if;
368
369 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_NOTRAILERS|IFF_MULTICAST;
370
371#if (defined(__FreeBSD__) && BSD >= 199506) || defined(__NetBSD__)
372 ifp->if_watchdog = pdq_ifwatchdog;
373#else
374 ifp->if_watchdog = ifwatchdog;
375#endif
376
377 ifp->if_ioctl = pdq_ifioctl;
378 ifp->if_output = fddi_output;
379 ifp->if_start = pdq_ifstart;
380#warning "Implement fddi_resolvemulti!"
381/* ifp->if_resolvemulti = ether_resolvemulti; XXX */
382
383 if_attach(ifp);
384 fddi_ifattach(ifp);
385#if NBPFILTER > 0
386 PDQ_BPFATTACH(sc, DLT_FDDI, sizeof(struct fddi_header));
387#endif
388}
60#include <netinet/if_fddi.h>
61#else
62#include <net/if_fddi.h>
63#endif
64
65#if defined(__bsdi__)
66#include <i386/isa/isavar.h>
67#endif
68
69#ifdef NS
70#include <netns/ns.h>
71#include <netns/ns_if.h>
72#endif
73
74#if defined(__FreeBSD__)
75#include <dev/pdq/pdqvar.h>
76#include <dev/pdq/pdqreg.h>
77#else
78#include "pdqvar.h"
79#include "pdqreg.h"
80#endif
81
82#if defined(__bsdi__) && _BSDI_VERSION < 199506 /* XXX */
83static void
84arp_ifinit(
85 struct arpcom *ac,
86 struct ifaddr *ifa)
87{
88 sc->sc_ac.ac_ipaddr = IA_SIN(ifa)->sin_addr;
89 arpwhohas(&sc->sc_ac, &IA_SIN(ifa)->sin_addr);
90#if _BSDI_VERSION >= 199401
91 ifa->ifa_rtrequest = arp_rtrequest;
92 ifa->ifa_flags |= RTF_CLONING;
93#endif
94#endif
95
96
97void
98pdq_ifinit(
99 pdq_softc_t *sc)
100{
101 if (sc->sc_if.if_flags & IFF_UP) {
102 sc->sc_if.if_flags |= IFF_RUNNING;
103 if (sc->sc_if.if_flags & IFF_PROMISC) {
104 sc->sc_pdq->pdq_flags |= PDQ_PROMISC;
105 } else {
106 sc->sc_pdq->pdq_flags &= ~PDQ_PROMISC;
107 }
108 if (sc->sc_if.if_flags & IFF_ALLMULTI) {
109 sc->sc_pdq->pdq_flags |= PDQ_ALLMULTI;
110 } else {
111 sc->sc_pdq->pdq_flags &= ~PDQ_ALLMULTI;
112 }
113 if (sc->sc_if.if_flags & IFF_LINK1) {
114 sc->sc_pdq->pdq_flags |= PDQ_PASS_SMT;
115 } else {
116 sc->sc_pdq->pdq_flags &= ~PDQ_PASS_SMT;
117 }
118 sc->sc_pdq->pdq_flags |= PDQ_RUNNING;
119 pdq_run(sc->sc_pdq);
120 } else {
121 sc->sc_if.if_flags &= ~IFF_RUNNING;
122 sc->sc_pdq->pdq_flags &= ~PDQ_RUNNING;
123 pdq_stop(sc->sc_pdq);
124 }
125}
126
127void
128pdq_ifwatchdog(
129 struct ifnet *ifp)
130{
131 /*
132 * No progress was made on the transmit queue for PDQ_OS_TX_TRANSMIT
133 * seconds. Remove all queued packets.
134 */
135
136 ifp->if_flags &= ~IFF_OACTIVE;
137 ifp->if_timer = 0;
138 for (;;) {
139 struct mbuf *m;
140 IF_DEQUEUE(&ifp->if_snd, m);
141 if (m == NULL)
142 return;
143 m_freem(m);
144 }
145}
146
147ifnet_ret_t
148pdq_ifstart(
149 struct ifnet *ifp)
150{
151 pdq_softc_t *sc = (pdq_softc_t *) ((caddr_t) ifp - offsetof(pdq_softc_t, sc_ac.ac_if));
152 struct ifqueue *ifq = &ifp->if_snd;
153 struct mbuf *m;
154 int tx = 0;
155
156 if ((ifp->if_flags & IFF_RUNNING) == 0)
157 return;
158
159 if (sc->sc_if.if_timer == 0)
160 sc->sc_if.if_timer = PDQ_OS_TX_TIMEOUT;
161
162 if ((sc->sc_pdq->pdq_flags & PDQ_TXOK) == 0) {
163 sc->sc_if.if_flags |= IFF_OACTIVE;
164 return;
165 }
166 for (;; tx = 1) {
167 IF_DEQUEUE(ifq, m);
168 if (m == NULL)
169 break;
170
171 if (pdq_queue_transmit_data(sc->sc_pdq, m) == PDQ_FALSE) {
172 ifp->if_flags |= IFF_OACTIVE;
173 IF_PREPEND(ifq, m);
174 break;
175 }
176 }
177 if (tx)
178 PDQ_DO_TYPE2_PRODUCER(sc->sc_pdq);
179}
180
181void
182pdq_os_receive_pdu(
183 pdq_t *pdq,
184 struct mbuf *m,
185 size_t pktlen)
186{
187 pdq_softc_t *sc = (pdq_softc_t *) pdq->pdq_os_ctx;
188 struct fddi_header *fh = mtod(m, struct fddi_header *);
189
190 sc->sc_if.if_ipackets++;
191#if NBPFILTER > 0
192 if (sc->sc_bpf != NULL)
193 PDQ_BPF_MTAP(sc, m);
194 if ((fh->fddi_fc & (FDDIFC_L|FDDIFC_F)) != FDDIFC_LLC_ASYNC) {
195 m_freem(m);
196 return;
197 }
198#endif
199
200 m->m_data += sizeof(struct fddi_header);
201 m->m_len -= sizeof(struct fddi_header);
202 m->m_pkthdr.len = pktlen - sizeof(struct fddi_header);
203 m->m_pkthdr.rcvif = &sc->sc_if;
204 fddi_input(&sc->sc_if, fh, m);
205}
206
207void
208pdq_os_restart_transmitter(
209 pdq_t *pdq)
210{
211 pdq_softc_t *sc = (pdq_softc_t *) pdq->pdq_os_ctx;
212 sc->sc_if.if_flags &= ~IFF_OACTIVE;
213 if (sc->sc_if.if_snd.ifq_head != NULL) {
214 sc->sc_if.if_timer = PDQ_OS_TX_TIMEOUT;
215 pdq_ifstart(&sc->sc_if);
216 } else {
217 sc->sc_if.if_timer = 0;
218 }
219}
220
221void
222pdq_os_transmit_done(
223 pdq_t *pdq,
224 struct mbuf *m)
225{
226 pdq_softc_t *sc = (pdq_softc_t *) pdq->pdq_os_ctx;
227#if NBPFILTER > 0
228 if (sc->sc_bpf != NULL)
229 PDQ_BPF_MTAP(sc, m);
230#endif
231 m_freem(m);
232 sc->sc_if.if_opackets++;
233}
234
235void
236pdq_os_addr_fill(
237 pdq_t *pdq,
238 pdq_lanaddr_t *addr,
239 size_t num_addrs)
240{
241 pdq_softc_t *sc = (pdq_softc_t *) pdq->pdq_os_ctx;
242 struct ifmultiaddr *ifma;
243
244 for (ifma = sc->sc_if.if_multiaddrs.lh_first; ifma && num_addrs > 0;
245 ifma = ifma->ifma_link.le_next) {
246 char *mcaddr;
247 if (ifma->ifma_addr->sa_family != AF_LINK)
248 continue;
249 mcaddr = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
250 ((u_short *) addr->lanaddr_bytes)[0] = ((u_short *) mcaddr)[0];
251 ((u_short *) addr->lanaddr_bytes)[1] = ((u_short *) mcaddr)[1];
252 ((u_short *) addr->lanaddr_bytes)[2] = ((u_short *) mcaddr)[2];
253 addr++;
254 num_addrs--;
255 }
256}
257
258int
259pdq_ifioctl(
260 struct ifnet *ifp,
261 ioctl_cmd_t cmd,
262 caddr_t data)
263{
264 pdq_softc_t *sc = (pdq_softc_t *) ((caddr_t) ifp - offsetof(pdq_softc_t, sc_ac.ac_if));
265 int s, error = 0;
266
267 s = splimp();
268
269 switch (cmd) {
270 case SIOCSIFADDR: {
271 struct ifaddr *ifa = (struct ifaddr *)data;
272
273 ifp->if_flags |= IFF_UP;
274 switch(ifa->ifa_addr->sa_family) {
275#if defined(INET)
276 case AF_INET: {
277 pdq_ifinit(sc);
278 arp_ifinit(&sc->sc_ac, ifa);
279 break;
280 }
281#endif /* INET */
282
283#if defined(NS)
284 /* This magic copied from if_is.c; I don't use XNS,
285 * so I have no way of telling if this actually
286 * works or not.
287 */
288 case AF_NS: {
289 struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
290 if (ns_nullhost(*ina)) {
291 ina->x_host = *(union ns_host *)(sc->sc_ac.ac_enaddr);
292 } else {
293 ifp->if_flags &= ~IFF_RUNNING;
294 bcopy((caddr_t)ina->x_host.c_host,
295 (caddr_t)sc->sc_ac.ac_enaddr,
296 sizeof sc->sc_ac.ac_enaddr);
297 }
298
299 pdq_ifinit(sc);
300 break;
301 }
302#endif /* NS */
303
304 default: {
305 pdq_ifinit(sc);
306 break;
307 }
308 }
309 break;
310 }
311 case SIOCGIFADDR: {
312 struct ifreq *ifr = (struct ifreq *)data;
313 bcopy((caddr_t) sc->sc_ac.ac_enaddr,
314 (caddr_t) ((struct sockaddr *)&ifr->ifr_data)->sa_data,
315 6);
316 break;
317 }
318
319 case SIOCSIFFLAGS: {
320 pdq_ifinit(sc);
321 break;
322 }
323
324 case SIOCADDMULTI:
325 case SIOCDELMULTI:
326 /*
327 * Update multicast listeners
328 */
329 if (sc->sc_if.if_flags & IFF_RUNNING)
330 pdq_run(sc->sc_pdq);
331 error = 0;
332 break;
333
334#if defined(SIOCSIFMTU)
335#if !defined(ifr_mtu)
336#define ifr_mtu ifr_metric
337#endif
338 case SIOCSIFMTU: {
339 struct ifreq *ifr = (struct ifreq *)data;
340 /*
341 * Set the interface MTU.
342 */
343 if (ifr->ifr_mtu > FDDIMTU) {
344 error = EINVAL;
345 break;
346 }
347 ifp->if_mtu = ifr->ifr_mtu;
348 break;
349 }
350#endif /* SIOCSIFMTU */
351
352 default: {
353 error = EINVAL;
354 break;
355 }
356 }
357
358 splx(s);
359 return error;
360}
361
362#ifndef IFF_NOTRAILERS
363#define IFF_NOTRAILERS 0
364#endif
365
366void
367pdq_ifattach(
368 pdq_softc_t *sc,
369 ifnet_ret_t (*ifwatchdog)(int unit))
370{
371 struct ifnet *ifp = &sc->sc_if;
372
373 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_NOTRAILERS|IFF_MULTICAST;
374
375#if (defined(__FreeBSD__) && BSD >= 199506) || defined(__NetBSD__)
376 ifp->if_watchdog = pdq_ifwatchdog;
377#else
378 ifp->if_watchdog = ifwatchdog;
379#endif
380
381 ifp->if_ioctl = pdq_ifioctl;
382 ifp->if_output = fddi_output;
383 ifp->if_start = pdq_ifstart;
384#warning "Implement fddi_resolvemulti!"
385/* ifp->if_resolvemulti = ether_resolvemulti; XXX */
386
387 if_attach(ifp);
388 fddi_ifattach(ifp);
389#if NBPFILTER > 0
390 PDQ_BPFATTACH(sc, DLT_FDDI, sizeof(struct fddi_header));
391#endif
392}