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.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
36#include "opt_inet.h"
37
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>
56#ifdef INET
57#include <netinet/in.h>
58#include <netinet/if_ether.h>
59#endif
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}
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.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
36#include "opt_inet.h"
37
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>
56#ifdef INET
57#include <netinet/in.h>
58#include <netinet/if_ether.h>
59#endif
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}