2 * Copyright (c) 2004-2005 Robert N. M. Watson
3 * Copyright (c) 1990,1994 Regents of The University of Michigan.
6 * Permission to use, copy, modify, and distribute this software and
7 * its documentation for any purpose and without fee is hereby granted,
8 * provided that the above copyright notice appears in all copies and
9 * that both that copyright notice and this permission notice appear
10 * in supporting documentation, and that the name of The University
11 * of Michigan not be used in advertising or publicity pertaining to
12 * distribution of the software without specific, written prior
13 * permission. This software is supplied as is without expressed or
14 * implied warranties of any kind.
16 * This product includes software developed by the University of
17 * California, Berkeley and its contributors.
19 * Research Systems Unix Group
20 * The University of Michigan
22 * 535 W. William Street
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/malloc.h>
34 #include <sys/socket.h>
35 #include <sys/socketvar.h>
36 #include <sys/protosw.h>
38 #include <net/route.h>
39 #include <net/netisr.h>
41 #include <netatalk/at.h>
42 #include <netatalk/at_var.h>
43 #include <netatalk/ddp_var.h>
44 #include <netatalk/ddp_pcb.h>
45 #include <netatalk/at_extern.h>
47 static u_long ddp_sendspace = DDP_MAXSZ; /* Max ddp size + 1 (ddp_type) */
48 static u_long ddp_recvspace = 10 * (587 + sizeof(struct sockaddr_at));
50 static struct ifqueue atintrq1, atintrq2, aarpintrq;
53 ddp_attach(struct socket *so, int proto, struct thread *td)
59 KASSERT(ddp == NULL, ("ddp_attach: ddp != NULL"));
62 * Allocate socket buffer space first so that it's present
65 error = soreserve(so, ddp_sendspace, ddp_recvspace);
70 error = at_pcballoc(so);
76 ddp_detach(struct socket *so)
81 KASSERT(ddp != NULL, ("ddp_detach: ddp == NULL"));
85 at_pcbdetach(so, ddp);
91 ddp_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
97 KASSERT(ddp != NULL, ("ddp_bind: ddp == NULL"));
100 error = at_pcbsetaddr(ddp, nam, td);
107 ddp_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
113 KASSERT(ddp != NULL, ("ddp_connect: ddp == NULL"));
116 if (ddp->ddp_fsat.sat_port != ATADDR_ANYPORT) {
122 error = at_pcbconnect( ddp, nam, td );
131 ddp_disconnect(struct socket *so)
137 KASSERT(ddp != NULL, ("ddp_disconnect: ddp == NULL"));
139 if (ddp->ddp_fsat.sat_addr.s_node == ATADDR_ANYNODE) {
144 at_pcbdisconnect(ddp);
145 ddp->ddp_fsat.sat_addr.s_node = ATADDR_ANYNODE;
147 soisdisconnected(so);
152 ddp_shutdown(struct socket *so)
157 KASSERT(ddp != NULL, ("ddp_shutdown: ddp == NULL"));
163 ddp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
164 struct mbuf *control, struct thread *td)
170 KASSERT(ddp != NULL, ("ddp_send: ddp == NULL"));
172 if (control && control->m_len) {
179 if (ddp->ddp_fsat.sat_port != ATADDR_ANYPORT) {
184 error = at_pcbconnect(ddp, addr, td);
186 error = ddp_output(m, so);
187 at_pcbdisconnect(ddp);
194 if (ddp->ddp_fsat.sat_port == ATADDR_ANYPORT)
197 error = ddp_output(m, so);
204 ddp_abort(struct socket *so)
209 KASSERT(ddp != NULL, ("ddp_abort: ddp == NULL"));
212 at_pcbdetach(so, ddp);
214 /* XXXRW: Should be calling sotryfree() here? */
221 atintrq1.ifq_maxlen = IFQ_MAXLEN;
222 atintrq2.ifq_maxlen = IFQ_MAXLEN;
223 aarpintrq.ifq_maxlen = IFQ_MAXLEN;
224 mtx_init(&atintrq1.ifq_mtx, "at1_inq", NULL, MTX_DEF);
225 mtx_init(&atintrq2.ifq_mtx, "at2_inq", NULL, MTX_DEF);
226 mtx_init(&aarpintrq.ifq_mtx, "aarp_inq", NULL, MTX_DEF);
227 DDP_LIST_LOCK_INIT();
228 netisr_register(NETISR_ATALK1, at1intr, &atintrq1, NETISR_MPSAFE);
229 netisr_register(NETISR_ATALK2, at2intr, &atintrq2, NETISR_MPSAFE);
230 netisr_register(NETISR_AARP, aarpintr, &aarpintrq, NETISR_MPSAFE);
239 for (ddp = ddpcb_list; ddp != NULL; ddp = ddp->ddp_next) {
240 at_pcbdetach(ddp->ddp_socket, ddp);
242 DDP_LIST_LOCK_DESTROY();
247 at_setpeeraddr(struct socket *so, struct sockaddr **nam)
253 at_setsockaddr(struct socket *so, struct sockaddr **nam)
258 KASSERT(ddp != NULL, ("at_setsockaddr: ddp == NULL"));
261 at_sockaddr(ddp, nam);
266 struct pr_usrreqs ddp_usrreqs = {
267 .pru_abort = ddp_abort,
268 .pru_attach = ddp_attach,
269 .pru_bind = ddp_bind,
270 .pru_connect = ddp_connect,
271 .pru_control = at_control,
272 .pru_detach = ddp_detach,
273 .pru_disconnect = ddp_disconnect,
274 .pru_peeraddr = at_setpeeraddr,
275 .pru_send = ddp_send,
276 .pru_shutdown = ddp_shutdown,
277 .pru_sockaddr = at_setsockaddr,