2 * Copyright (c) 2004-2005 Robert N. M. Watson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * Copyright (c) 1990, 1994 Regents of The University of Michigan.
27 * All Rights Reserved.
29 * Permission to use, copy, modify, and distribute this software and
30 * its documentation for any purpose and without fee is hereby granted,
31 * provided that the above copyright notice appears in all copies and
32 * that both that copyright notice and this permission notice appear
33 * in supporting documentation, and that the name of The University
34 * of Michigan not be used in advertising or publicity pertaining to
35 * distribution of the software without specific, written prior
36 * permission. This software is supplied as is without expressed or
37 * implied warranties of any kind.
39 * This product includes software developed by the University of
40 * California, Berkeley and its contributors.
42 * Research Systems Unix Group
43 * The University of Michigan
45 * 535 W. William Street
53 #include <sys/param.h>
54 #include <sys/systm.h>
55 #include <sys/malloc.h>
57 #include <sys/socket.h>
58 #include <sys/socketvar.h>
59 #include <sys/protosw.h>
61 #include <net/route.h>
62 #include <net/netisr.h>
64 #include <netatalk/at.h>
65 #include <netatalk/at_var.h>
66 #include <netatalk/ddp_var.h>
67 #include <netatalk/ddp_pcb.h>
68 #include <netatalk/at_extern.h>
70 static u_long ddp_sendspace = DDP_MAXSZ; /* Max ddp size + 1 (ddp_type) */
71 static u_long ddp_recvspace = 10 * (587 + sizeof(struct sockaddr_at));
73 static struct ifqueue atintrq1, atintrq2, aarpintrq;
76 ddp_attach(struct socket *so, int proto, struct thread *td)
80 KASSERT(sotoddpcb(so) == NULL, ("ddp_attach: ddp != NULL"));
83 * Allocate socket buffer space first so that it's present
86 error = soreserve(so, ddp_sendspace, ddp_recvspace);
91 error = at_pcballoc(so);
97 ddp_detach(struct socket *so)
102 KASSERT(ddp != NULL, ("ddp_detach: ddp == NULL"));
106 at_pcbdetach(so, ddp);
111 ddp_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
117 KASSERT(ddp != NULL, ("ddp_bind: ddp == NULL"));
121 error = at_pcbsetaddr(ddp, nam, td);
128 ddp_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
134 KASSERT(ddp != NULL, ("ddp_connect: ddp == NULL"));
138 if (ddp->ddp_fsat.sat_port != ATADDR_ANYPORT) {
144 error = at_pcbconnect( ddp, nam, td );
153 ddp_disconnect(struct socket *so)
158 KASSERT(ddp != NULL, ("ddp_disconnect: ddp == NULL"));
161 if (ddp->ddp_fsat.sat_addr.s_node == ATADDR_ANYNODE) {
166 at_pcbdisconnect(ddp);
167 ddp->ddp_fsat.sat_addr.s_node = ATADDR_ANYNODE;
169 soisdisconnected(so);
174 ddp_shutdown(struct socket *so)
177 KASSERT(sotoddpcb(so) != NULL, ("ddp_shutdown: ddp == NULL"));
184 ddp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
185 struct mbuf *control, struct thread *td)
191 KASSERT(ddp != NULL, ("ddp_send: ddp == NULL"));
193 if (control && control->m_len)
199 if (ddp->ddp_fsat.sat_port != ATADDR_ANYPORT) {
204 error = at_pcbconnect(ddp, addr, td);
206 error = ddp_output(m, so);
207 at_pcbdisconnect(ddp);
214 if (ddp->ddp_fsat.sat_port == ATADDR_ANYPORT)
217 error = ddp_output(m, so);
224 * XXXRW: This is never called because we only invoke abort on stream
228 ddp_abort(struct socket *so)
233 KASSERT(ddp != NULL, ("ddp_abort: ddp == NULL"));
236 at_pcbdisconnect(ddp);
238 soisdisconnected(so);
242 ddp_close(struct socket *so)
247 KASSERT(ddp != NULL, ("ddp_close: ddp == NULL"));
250 at_pcbdisconnect(ddp);
252 soisdisconnected(so);
259 atintrq1.ifq_maxlen = IFQ_MAXLEN;
260 atintrq2.ifq_maxlen = IFQ_MAXLEN;
261 aarpintrq.ifq_maxlen = IFQ_MAXLEN;
262 mtx_init(&atintrq1.ifq_mtx, "at1_inq", NULL, MTX_DEF);
263 mtx_init(&atintrq2.ifq_mtx, "at2_inq", NULL, MTX_DEF);
264 mtx_init(&aarpintrq.ifq_mtx, "aarp_inq", NULL, MTX_DEF);
265 DDP_LIST_LOCK_INIT();
266 netisr_register(NETISR_ATALK1, at1intr, &atintrq1, NETISR_MPSAFE);
267 netisr_register(NETISR_ATALK2, at2intr, &atintrq2, NETISR_MPSAFE);
268 netisr_register(NETISR_AARP, aarpintr, &aarpintrq, NETISR_MPSAFE);
277 for (ddp = ddpcb_list; ddp != NULL; ddp = ddp->ddp_next)
278 at_pcbdetach(ddp->ddp_socket, ddp);
279 DDP_LIST_LOCK_DESTROY();
284 at_getpeeraddr(struct socket *so, struct sockaddr **nam)
291 at_getsockaddr(struct socket *so, struct sockaddr **nam)
296 KASSERT(ddp != NULL, ("at_getsockaddr: ddp == NULL"));
299 at_sockaddr(ddp, nam);
304 struct pr_usrreqs ddp_usrreqs = {
305 .pru_abort = ddp_abort,
306 .pru_attach = ddp_attach,
307 .pru_bind = ddp_bind,
308 .pru_connect = ddp_connect,
309 .pru_control = at_control,
310 .pru_detach = ddp_detach,
311 .pru_disconnect = ddp_disconnect,
312 .pru_peeraddr = at_getpeeraddr,
313 .pru_send = ddp_send,
314 .pru_shutdown = ddp_shutdown,
315 .pru_sockaddr = at_getsockaddr,
316 .pru_close = ddp_close,