1996-05-24 01:35:45 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1990,1994 Regents of The University of Michigan.
|
|
|
|
* All Rights Reserved. See COPYRIGHT.
|
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;
|
|
|
|
int s;
|
|
|
|
|
1996-05-24 01:35:45 +00:00
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
ddp = sotoddpcb(so);
|
|
|
|
if (ddp != NULL) {
|
|
|
|
return (EINVAL);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
1997-05-13 21:01:45 +00:00
|
|
|
|
|
|
|
s = splnet();
|
2004-03-22 03:24:10 +00:00
|
|
|
error = at_pcballoc(so);
|
1997-05-13 21:01:45 +00:00
|
|
|
splx(s);
|
|
|
|
if (error) {
|
|
|
|
return (error);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
2004-03-22 03:24:10 +00:00
|
|
|
return (soreserve(so, ddp_sendspace, ddp_recvspace));
|
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;
|
|
|
|
int s;
|
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
ddp = sotoddpcb(so);
|
|
|
|
if (ddp == NULL) {
|
|
|
|
return (EINVAL);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
|
|
|
s = splnet();
|
2004-03-22 03:24:10 +00:00
|
|
|
at_pcbdetach(so, ddp);
|
1997-05-13 21:01:45 +00:00
|
|
|
splx(s);
|
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;
|
|
|
|
int s;
|
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
ddp = sotoddpcb(so);
|
|
|
|
if (ddp == NULL) {
|
|
|
|
return (EINVAL);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
|
|
|
s = splnet();
|
2001-09-12 08:38:13 +00:00
|
|
|
error = at_pcbsetaddr(ddp, nam, td);
|
1997-05-13 21:01:45 +00:00
|
|
|
splx(s);
|
|
|
|
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;
|
|
|
|
int s;
|
|
|
|
|
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-03-22 03:24:10 +00:00
|
|
|
if (ddp->ddp_fsat.sat_port != ATADDR_ANYPORT) {
|
|
|
|
return (EISCONN);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
|
1997-05-13 21:01:45 +00:00
|
|
|
s = splnet();
|
2004-03-22 03:24:10 +00:00
|
|
|
error = at_pcbconnect(ddp, nam, td);
|
1997-05-13 21:01:45 +00:00
|
|
|
splx(s);
|
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;
|
|
|
|
int s;
|
|
|
|
|
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 (ddp->ddp_fsat.sat_addr.s_node == ATADDR_ANYNODE) {
|
|
|
|
return (ENOTCONN);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
1997-05-13 21:01:45 +00:00
|
|
|
|
|
|
|
s = splnet();
|
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;
|
|
|
|
splx(s);
|
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;
|
|
|
|
int s;
|
|
|
|
|
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-03-22 03:24:10 +00:00
|
|
|
if (ddp->ddp_fsat.sat_port != ATADDR_ANYPORT) {
|
|
|
|
return (EISCONN);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
1996-05-24 01:35:45 +00:00
|
|
|
|
1997-05-13 21:01:45 +00:00
|
|
|
s = splnet();
|
2001-09-12 08:38:13 +00:00
|
|
|
error = at_pcbconnect(ddp, addr, td);
|
2004-03-22 03:24:10 +00:00
|
|
|
splx(s);
|
|
|
|
if (error) {
|
|
|
|
return (error);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
1996-05-24 01:35:45 +00:00
|
|
|
} else {
|
2004-03-22 03:24:10 +00:00
|
|
|
if (ddp->ddp_fsat.sat_port == ATADDR_ANYPORT) {
|
|
|
|
return (ENOTCONN);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
|
|
|
|
1997-05-13 21:01:45 +00:00
|
|
|
s = splnet();
|
2004-03-22 03:24:10 +00:00
|
|
|
error = ddp_output(m, so);
|
2004-03-22 03:57:01 +00:00
|
|
|
if (addr != NULL) {
|
2004-03-22 03:24:10 +00:00
|
|
|
at_pcbdisconnect(ddp);
|
1996-05-24 01:35:45 +00:00
|
|
|
}
|
1997-05-13 21:01:45 +00:00
|
|
|
splx(s);
|
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;
|
|
|
|
int s;
|
|
|
|
|
2004-03-22 03:24:10 +00:00
|
|
|
ddp = sotoddpcb(so);
|
|
|
|
if (ddp == NULL) {
|
|
|
|
return (EINVAL);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
|
|
|
s = splnet();
|
2004-03-22 03:24:10 +00:00
|
|
|
at_pcbdetach(so, ddp);
|
1997-05-13 21:01:45 +00:00
|
|
|
splx(s);
|
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);
|
|
|
|
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-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-03-22 03:24:10 +00:00
|
|
|
at_sockaddr(ddp, nam);
|
|
|
|
return (0);
|
1997-05-13 21:01:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct pr_usrreqs ddp_usrreqs = {
|
|
|
|
ddp_abort,
|
|
|
|
pru_accept_notsupp,
|
|
|
|
ddp_attach,
|
|
|
|
ddp_bind,
|
|
|
|
ddp_connect,
|
|
|
|
pru_connect2_notsupp,
|
|
|
|
at_control,
|
|
|
|
ddp_detach,
|
|
|
|
ddp_disconnect,
|
|
|
|
pru_listen_notsupp,
|
|
|
|
at_setpeeraddr,
|
|
|
|
pru_rcvd_notsupp,
|
|
|
|
pru_rcvoob_notsupp,
|
|
|
|
ddp_send,
|
|
|
|
pru_sense_null,
|
|
|
|
ddp_shutdown,
|
|
|
|
at_setsockaddr,
|
|
|
|
sosend,
|
|
|
|
soreceive,
|
Introduce a MAC label reference in 'struct inpcb', which caches
the MAC label referenced from 'struct socket' in the IPv4 and
IPv6-based protocols. This permits MAC labels to be checked during
network delivery operations without dereferencing inp->inp_socket
to get to so->so_label, which will eventually avoid our having to
grab the socket lock during delivery at the network layer.
This change introduces 'struct inpcb' as a labeled object to the
MAC Framework, along with the normal circus of entry points:
initialization, creation from socket, destruction, as well as a
delivery access control check.
For most policies, the inpcb label will simply be a cache of the
socket label, so a new protocol switch method is introduced,
pr_sosetlabel() to notify protocols that the socket layer label
has been updated so that the cache can be updated while holding
appropriate locks. Most protocols implement this using
pru_sosetlabel_null(), but IPv4/IPv6 protocols using inpcbs use
the the worker function in_pcbsosetlabel(), which calls into the
MAC Framework to perform a cache update.
Biba, LOMAC, and MLS implement these entry points, as do the stub
policy, and test policy.
Reviewed by: sam, bms
Obtained from: TrustedBSD Project
Sponsored by: DARPA, Network Associates Laboratories
2003-11-18 00:39:07 +00:00
|
|
|
sopoll,
|
|
|
|
pru_sosetlabel_null
|
1997-05-13 21:01:45 +00:00
|
|
|
};
|