2005-01-07 02:35:34 +00:00
|
|
|
/*-
|
2004-07-12 18:39:59 +00:00
|
|
|
* Copyright (c) 2004 Robert N. M. Watson
|
1996-05-24 01:35:45 +00:00
|
|
|
* Copyright (c) 1990,1994 Regents of The University of Michigan.
|
2005-01-07 02:35:34 +00:00
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software and
|
|
|
|
* its documentation for any purpose and without fee is hereby granted,
|
|
|
|
* provided that the above copyright notice appears in all copies and
|
|
|
|
* that both that copyright notice and this permission notice appear
|
|
|
|
* in supporting documentation, and that the name of The University
|
|
|
|
* of Michigan not be used in advertising or publicity pertaining to
|
|
|
|
* distribution of the software without specific, written prior
|
|
|
|
* permission. This software is supplied as is without expressed or
|
|
|
|
* implied warranties of any kind.
|
|
|
|
*
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
*
|
|
|
|
* Research Systems Unix Group
|
|
|
|
* The University of Michigan
|
|
|
|
* c/o Wesley Craig
|
|
|
|
* 535 W. William Street
|
|
|
|
* Ann Arbor, Michigan
|
|
|
|
* +1-313-764-2278
|
|
|
|
* netatalk@umich.edu
|
2000-10-29 16:06:56 +00:00
|
|
|
*
|
|
|
|
* $FreeBSD$
|
1996-05-24 01:35:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1997-09-02 01:19:47 +00:00
|
|
|
#include <sys/malloc.h>
|
1996-05-24 01:35:45 +00:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/route.h>
|
2003-03-04 23:19:55 +00:00
|
|
|
#include <net/netisr.h>
|
1996-05-24 01:35:45 +00:00
|
|
|
|
1996-09-10 08:32:01 +00:00
|
|
|
#include <netatalk/at.h>
|
|
|
|
#include <netatalk/at_var.h>
|
|
|
|
#include <netatalk/ddp_var.h>
|
2004-03-19 07:21:22 +00:00
|
|
|
#include <netatalk/ddp_pcb.h>
|
1996-05-24 01:35:45 +00:00
|
|
|
#include <netatalk/at_extern.h>
|
|
|
|
|
1998-02-09 06:11:36 +00:00
|
|
|
static u_long ddp_sendspace = DDP_MAXSZ; /* Max ddp size + 1 (ddp_type) */
|
2004-03-22 03:24:10 +00:00
|
|
|
static u_long ddp_recvspace = 10 * (587 + sizeof(struct sockaddr_at));
|
1996-05-24 01:35:45 +00:00
|
|
|
|
2003-03-04 23:19:55 +00:00
|
|
|
static struct ifqueue atintrq1, atintrq2, aarpintrq;
|
1996-05-24 01:35:45 +00:00
|
|
|
|
1997-05-13 21:01:45 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
ddp_attach(struct socket *so, int proto, struct thread *td)
|
1997-05-13 21:01:45 +00:00
|
|
|
{
|
|
|
|
struct ddpcb *ddp;
|
|
|
|
int error = 0;
|
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
ddp = sotoddpcb(so);
|
2004-07-12 18:39:59 +00:00
|
|
|
if (ddp != NULL)
|
|
|
|
return (EINVAL);
|
1997-05-13 21:01:45 +00:00
|
|
|
|
2004-07-12 18:39:59 +00:00
|
|
|
/*
|
|
|
|
* Allocate socket buffer space first so that it's present
|
|
|
|
* before first use.
|
|
|
|
*/
|
|
|
|
error = soreserve(so, ddp_sendspace, ddp_recvspace);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
DDP_LIST_XLOCK();
|
2004-03-22 03:24:10 +00:00
|
|
|
error = at_pcballoc(so);
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_LIST_XUNLOCK();
|
|
|
|
return (error);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
1996-05-24 01:35:45 +00:00
|
|
|
|
1997-05-13 21:01:45 +00:00
|
|
|
static int
|
|
|
|
ddp_detach(struct socket *so)
|
|
|
|
{
|
|
|
|
struct ddpcb *ddp;
|
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
ddp = sotoddpcb(so);
|
2004-07-12 18:39:59 +00:00
|
|
|
if (ddp == NULL)
|
2004-03-22 03:24:10 +00:00
|
|
|
return (EINVAL);
|
2004-07-12 18:39:59 +00:00
|
|
|
|
|
|
|
DDP_LIST_XLOCK();
|
|
|
|
DDP_LOCK(ddp);
|
2004-03-22 03:24:10 +00:00
|
|
|
at_pcbdetach(so, ddp);
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_LIST_XUNLOCK();
|
2004-03-22 03:24:10 +00:00
|
|
|
return (0);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
1996-05-24 01:35:45 +00:00
|
|
|
|
1997-05-13 21:01:45 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
ddp_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
|
1997-05-13 21:01:45 +00:00
|
|
|
{
|
|
|
|
struct ddpcb *ddp;
|
|
|
|
int error = 0;
|
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
ddp = sotoddpcb(so);
|
|
|
|
if (ddp == NULL) {
|
|
|
|
return (EINVAL);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_LIST_XLOCK();
|
|
|
|
DDP_LOCK(ddp);
|
2001-09-12 08:38:13 +00:00
|
|
|
error = at_pcbsetaddr(ddp, nam, td);
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_UNLOCK(ddp);
|
|
|
|
DDP_LIST_XUNLOCK();
|
1997-05-13 21:01:45 +00:00
|
|
|
return (error);
|
|
|
|
}
|
1996-05-24 01:35:45 +00:00
|
|
|
|
1997-05-13 21:01:45 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
ddp_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
|
1997-05-13 21:01:45 +00:00
|
|
|
{
|
|
|
|
struct ddpcb *ddp;
|
|
|
|
int error = 0;
|
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
ddp = sotoddpcb(so);
|
|
|
|
if (ddp == NULL) {
|
|
|
|
return (EINVAL);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
1996-05-24 01:35:45 +00:00
|
|
|
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_LIST_XLOCK();
|
|
|
|
DDP_LOCK(ddp);
|
2004-03-22 03:24:10 +00:00
|
|
|
if (ddp->ddp_fsat.sat_port != ATADDR_ANYPORT) {
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_UNLOCK(ddp);
|
|
|
|
DDP_LIST_XUNLOCK();
|
2004-03-22 03:24:10 +00:00
|
|
|
return (EISCONN);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
|
2004-07-12 18:39:59 +00:00
|
|
|
error = at_pcbconnect( ddp, nam, td );
|
|
|
|
DDP_UNLOCK(ddp);
|
|
|
|
DDP_LIST_XUNLOCK();
|
2004-03-22 03:24:10 +00:00
|
|
|
if (error == 0)
|
|
|
|
soisconnected(so);
|
|
|
|
return (error);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
1996-05-24 01:35:45 +00:00
|
|
|
|
1997-05-13 21:01:45 +00:00
|
|
|
static int
|
|
|
|
ddp_disconnect(struct socket *so)
|
|
|
|
{
|
|
|
|
|
|
|
|
struct ddpcb *ddp;
|
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
ddp = sotoddpcb(so);
|
|
|
|
if (ddp == NULL) {
|
|
|
|
return (EINVAL);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_LOCK(ddp);
|
2004-03-22 03:24:10 +00:00
|
|
|
if (ddp->ddp_fsat.sat_addr.s_node == ATADDR_ANYNODE) {
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_UNLOCK(ddp);
|
2004-03-22 03:24:10 +00:00
|
|
|
return (ENOTCONN);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
1997-05-13 21:01:45 +00:00
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
at_pcbdisconnect(ddp);
|
1997-05-13 21:01:45 +00:00
|
|
|
ddp->ddp_fsat.sat_addr.s_node = ATADDR_ANYNODE;
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_UNLOCK(ddp);
|
2004-03-22 03:24:10 +00:00
|
|
|
soisdisconnected(so);
|
|
|
|
return (0);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
1996-05-24 01:35:45 +00:00
|
|
|
|
1997-05-13 21:01:45 +00:00
|
|
|
static int
|
|
|
|
ddp_shutdown(struct socket *so)
|
|
|
|
{
|
|
|
|
struct ddpcb *ddp;
|
1998-12-07 21:58:50 +00:00
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
ddp = sotoddpcb(so);
|
|
|
|
if (ddp == NULL) {
|
|
|
|
return (EINVAL);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
2004-03-22 03:24:10 +00:00
|
|
|
socantsendmore(so);
|
|
|
|
return (0);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
1996-05-24 01:35:45 +00:00
|
|
|
|
1997-05-13 21:01:45 +00:00
|
|
|
static int
|
1997-08-16 19:16:27 +00:00
|
|
|
ddp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
|
2001-09-12 08:38:13 +00:00
|
|
|
struct mbuf *control, struct thread *td)
|
1997-05-13 21:01:45 +00:00
|
|
|
{
|
|
|
|
struct ddpcb *ddp;
|
|
|
|
int error = 0;
|
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
ddp = sotoddpcb(so);
|
|
|
|
if (ddp == NULL) {
|
|
|
|
return (EINVAL);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
if (control && control->m_len) {
|
|
|
|
return (EINVAL);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
1996-05-24 01:35:45 +00:00
|
|
|
|
2004-03-22 03:57:01 +00:00
|
|
|
if (addr != NULL) {
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_LIST_XLOCK();
|
|
|
|
DDP_LOCK(ddp);
|
2004-03-22 03:24:10 +00:00
|
|
|
if (ddp->ddp_fsat.sat_port != ATADDR_ANYPORT) {
|
2004-07-12 18:39:59 +00:00
|
|
|
error = EISCONN;
|
|
|
|
goto out;
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
1996-05-24 01:35:45 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
error = at_pcbconnect(ddp, addr, td);
|
2004-07-12 18:39:59 +00:00
|
|
|
if (error == 0) {
|
|
|
|
error = ddp_output(m, so);
|
|
|
|
at_pcbdisconnect(ddp);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
2004-07-12 18:39:59 +00:00
|
|
|
out:
|
|
|
|
DDP_UNLOCK(ddp);
|
|
|
|
DDP_LIST_XUNLOCK();
|
1996-05-24 01:35:45 +00:00
|
|
|
} else {
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_LOCK(ddp);
|
|
|
|
if (ddp->ddp_fsat.sat_port == ATADDR_ANYPORT)
|
|
|
|
error = ENOTCONN;
|
|
|
|
else
|
|
|
|
error = ddp_output(m, so);
|
|
|
|
DDP_UNLOCK(ddp);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
2004-03-22 03:24:10 +00:00
|
|
|
return (error);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
1996-05-24 01:35:45 +00:00
|
|
|
|
1997-05-13 21:01:45 +00:00
|
|
|
static int
|
|
|
|
ddp_abort(struct socket *so)
|
|
|
|
{
|
|
|
|
struct ddpcb *ddp;
|
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
ddp = sotoddpcb(so);
|
|
|
|
if (ddp == NULL) {
|
|
|
|
return (EINVAL);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_LIST_XLOCK();
|
|
|
|
DDP_LOCK(ddp);
|
2004-03-22 03:24:10 +00:00
|
|
|
at_pcbdetach(so, ddp);
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_LIST_XUNLOCK();
|
2004-03-22 03:24:10 +00:00
|
|
|
return (0);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
|
2004-03-19 07:21:22 +00:00
|
|
|
void
|
|
|
|
ddp_init(void)
|
1996-05-24 01:35:45 +00:00
|
|
|
{
|
2004-03-19 07:21:22 +00:00
|
|
|
atintrq1.ifq_maxlen = IFQ_MAXLEN;
|
|
|
|
atintrq2.ifq_maxlen = IFQ_MAXLEN;
|
|
|
|
aarpintrq.ifq_maxlen = IFQ_MAXLEN;
|
|
|
|
mtx_init(&atintrq1.ifq_mtx, "at1_inq", NULL, MTX_DEF);
|
|
|
|
mtx_init(&atintrq2.ifq_mtx, "at2_inq", NULL, MTX_DEF);
|
|
|
|
mtx_init(&aarpintrq.ifq_mtx, "aarp_inq", NULL, MTX_DEF);
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_LIST_LOCK_INIT();
|
2004-03-19 07:21:22 +00:00
|
|
|
netisr_register(NETISR_ATALK1, at1intr, &atintrq1, 0);
|
|
|
|
netisr_register(NETISR_ATALK2, at2intr, &atintrq2, 0);
|
|
|
|
netisr_register(NETISR_AARP, aarpintr, &aarpintrq, 0);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
|
2004-03-19 07:21:22 +00:00
|
|
|
#if 0
|
1996-05-24 01:35:45 +00:00
|
|
|
static void
|
2004-03-22 03:24:10 +00:00
|
|
|
ddp_clean(void)
|
1996-05-24 01:35:45 +00:00
|
|
|
{
|
|
|
|
struct ddpcb *ddp;
|
|
|
|
|
2004-03-22 04:54:36 +00:00
|
|
|
for (ddp = ddpcb_list; ddp != NULL; ddp = ddp->ddp_next) {
|
2004-03-22 03:24:10 +00:00
|
|
|
at_pcbdetach(ddp->ddp_socket, ddp);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_LIST_LOCK_DESTROY();
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
2004-03-19 07:21:22 +00:00
|
|
|
#endif
|
|
|
|
|
1997-05-13 21:01:45 +00:00
|
|
|
static int
|
1997-08-16 19:16:27 +00:00
|
|
|
at_setpeeraddr(struct socket *so, struct sockaddr **nam)
|
1997-05-13 21:01:45 +00:00
|
|
|
{
|
2004-03-22 03:24:10 +00:00
|
|
|
return (EOPNOTSUPP);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-08-16 19:16:27 +00:00
|
|
|
at_setsockaddr(struct socket *so, struct sockaddr **nam)
|
1997-05-13 21:01:45 +00:00
|
|
|
{
|
|
|
|
struct ddpcb *ddp;
|
1998-12-07 21:58:50 +00:00
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
ddp = sotoddpcb(so);
|
|
|
|
if (ddp == NULL) {
|
|
|
|
return (EINVAL);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_LOCK(ddp);
|
2004-03-22 03:24:10 +00:00
|
|
|
at_sockaddr(ddp, nam);
|
2004-07-12 18:39:59 +00:00
|
|
|
DDP_UNLOCK(ddp);
|
2004-03-22 03:24:10 +00:00
|
|
|
return (0);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct pr_usrreqs ddp_usrreqs = {
|
2004-11-08 14:44:54 +00:00
|
|
|
.pru_abort = ddp_abort,
|
|
|
|
.pru_attach = ddp_attach,
|
|
|
|
.pru_bind = ddp_bind,
|
|
|
|
.pru_connect = ddp_connect,
|
|
|
|
.pru_control = at_control,
|
|
|
|
.pru_detach = ddp_detach,
|
|
|
|
.pru_disconnect = ddp_disconnect,
|
|
|
|
.pru_peeraddr = at_setpeeraddr,
|
|
|
|
.pru_send = ddp_send,
|
|
|
|
.pru_shutdown = ddp_shutdown,
|
|
|
|
.pru_sockaddr = at_setsockaddr,
|
1997-05-13 21:01:45 +00:00
|
|
|
};
|