Source to bsd/netat/ddp_usrreq.c
/*
* Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* The contents of this file constitute Original Code as defined in and
* are subject to the Apple Public Source License Version 1.1 (the
* "License"). You may not use this file except in compliance with the
* License. Please obtain a copy of the License at
* http://www.apple.com/publicsource and read it before using this file.
*
* This Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* Copyright (c) 1998 Apple Computer, Inc.
*/
/* ddp_usrreq.c
*/
#include <sys/errno.h>
#include <sys/types.h>
#include <sys/param.h>
#include <machine/spl.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/filedesc.h>
#include <sys/fcntl.h>
#include <sys/mbuf.h>
#include <sys/ioctl.h>
#include <sys/malloc.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/protosw.h>
#include <net/if.h>
#include <netat/appletalk.h>
#include <netat/at_var.h>
#include <netat/sysglue.h>
#include <netat/lap.h>
#include <netat/ddp.h>
#include <netat/ep.h>
#include <netat/rtmp.h>
#include <netat/zip.h>
#include <netat/at_pcb.h>
#include <netat/routing_tables.h>
#include <netat/nbp.h>
extern int at_control(), at_memzone_init();
extern void nbp_input(), ep_input(), zip_router_input(),
sip_input(), add_ddp_handler(), init_ddp_handler(),
ddp_start(), appletalk_hack_start();
extern int xpatcnt;
struct atpcb ddp_head;
u_long ddp_sendspace = 600, /* *** what should this value be? *** */
ddp_recvspace = 50 * (600 + sizeof(struct sockaddr_at));
int ddp_pru_control(struct socket *so, u_long cmd, caddr_t data,
struct ifnet *ifp, struct proc *p)
{
return(at_control(so, cmd, data, ifp));
}
int ddp_pru_attach(struct socket *so, int proto,
struct proc *p)
{
int s, error = 0;
at_ddp_t *ddp = NULL;
struct atpcb *pcb = (struct atpcb *)((so)->so_pcb);
s = splnet();
error = at_pcballoc(so, &ddp_head);
splx(s);
if (error)
return error;
error = soreserve(so, ddp_sendspace, ddp_recvspace);
pcb = (struct atpcb *)((so)->so_pcb);
pcb->pid = current_proc()->p_pid;
pcb->ddptype = (u_char) proto; /* set in socreate() */
/* *** to support at_ioctl() hack *** */
pcb->proto = (pcb->ddptype == DDP_ATP)? ATPROTO_ATP:
(pcb->ddptype == DDP_ADSP)? ATPROTO_ADSP:
ATPROTO_DDP;
ATEVENTINIT(pcb->iocevent);
/* *** end of hack *** */
return error;
}
int ddp_pru_disconnect(struct socket *so)
{
int s, error = 0;
at_ddp_t *ddp = NULL;
struct atpcb *pcb = (struct atpcb *)((so)->so_pcb);
if (pcb == NULL)
return (EINVAL);
if ((so->so_state & SS_ISCONNECTED) == 0)
return ENOTCONN;
soisdisconnected(so);
s = splnet();
at_pcbdetach(pcb);
splx(s);
return error;
}
int ddp_pru_abort(struct socket *so)
{
int s;
struct atpcb *pcb = (struct atpcb *)((so)->so_pcb);
if (pcb == NULL)
return (EINVAL);
soisdisconnected(so);
s = splnet();
at_pcbdetach(pcb);
splx(s);
return 0;
}
int ddp_pru_detach(struct socket *so)
{
int s;
struct atpcb *pcb = (struct atpcb *)((so)->so_pcb);
if (pcb == NULL)
return (EINVAL);
s = splnet();
at_pcbdetach(pcb);
splx(s);
return 0;
}
int ddp_pru_shutdown(struct socket *so)
{
struct atpcb *pcb = (struct atpcb *)((so)->so_pcb);
if (pcb == NULL)
return (EINVAL);
socantsendmore(so);
return 0;
}
int ddp_pru_bind(struct socket *so, struct sockaddr *nam,
struct proc *p)
{
struct atpcb *pcb = (struct atpcb *)((so)->so_pcb);
if (pcb == NULL)
return (EINVAL);
return (at_pcbbind(pcb, nam));
}
int ddp_pru_send(struct socket *so, int flags, struct mbuf *m,
struct sockaddr *addr, struct mbuf *control,
struct proc *p)
{
int s, error = 0;
at_ddp_t *ddp = NULL;
struct atpcb *pcb = (struct atpcb *)((so)->so_pcb);
if (pcb == NULL)
return (EINVAL);
if (!(pcb->ddp_flags & DDPFLG_HDRINCL)) {
/* prepend a DDP header */
M_PREPEND(m, DDP_X_HDR_SIZE, M_WAIT);
ddp = mtod(m, at_ddp_t *);
}
if (so->so_state & SS_ISCONNECTED) {
if (addr)
return EISCONN;
if (ddp) {
NET_ASSIGN(ddp->dst_net, pcb->raddr.s_net);
ddp->dst_node = pcb->raddr.s_node;
ddp->dst_socket = pcb->rport;
}
} else {
if (addr == NULL)
return ENOTCONN;
if (ddp) {
struct sockaddr_at *dst =
(struct sockaddr_at *) addr;
NET_ASSIGN(ddp->dst_net, dst->sat_addr.s_net);
ddp->dst_node = dst->sat_addr.s_node;
ddp->dst_socket = dst->sat_port;
}
}
ddp->length = m->m_pkthdr.len;
UAS_ASSIGN(ddp->checksum, 0);
ddp->type = (pcb->ddptype)? pcb->ddptype: DEFAULT_OT_DDPTYPE;
#ifdef NOT_YET
NET_ASSIGN(ddp->src_net, pcb->laddr.s_net);
ddp->src_node = pcb->laddr.s_node;
ddp->src_socket = pcb->lport;
#endif
error = ddp_output(&m, pcb->lport, FALSE);
m = NULL;
return error;
}
int ddp_pru_sockaddr(struct socket *so,
struct sockaddr **nam)
{
struct atpcb *pcb = (struct atpcb *)((so)->so_pcb);
if (pcb == NULL)
return (EINVAL);
at_setsockaddr(pcb, *nam);
return 0;
}
int ddp_pru_peeraddr(struct socket *so,
struct sockaddr **nam)
{
struct atpcb *pcb = (struct atpcb *)((so)->so_pcb);
if (pcb == NULL)
return (EINVAL);
at_setpeeraddr(pcb, *nam);
return 0;
}
int ddp_pru_connect(struct socket *so, struct sockaddr *nam,
struct proc *p)
{
struct atpcb *pcb = (struct atpcb *)((so)->so_pcb);
struct sockaddr_at *faddr = (struct sockaddr_at *) nam;
if (pcb != NULL)
return (EINVAL);
if (xpatcnt == 0)
return (EADDRNOTAVAIL);
if (faddr->sat_family != AF_APPLETALK)
return (EAFNOSUPPORT);
pcb->raddr = faddr->sat_addr;
soisconnected(so);
return 0;
}
/*
* One-time AppleTalk initialization
*/
void ddp_init()
{
at_memzone_init();
ddp_head.atpcb_next = ddp_head.atpcb_prev = &ddp_head;
init_ddp_handler();
/* Initialize protocols implemented in the kernel */
add_ddp_handler(EP_SOCKET, ep_input);
add_ddp_handler(ZIP_SOCKET, zip_router_input);
add_ddp_handler(NBP_SOCKET, nbp_input);
add_ddp_handler(DDP_SOCKET_1st_DYNAMIC, sip_input);
ddp_start();
appletalk_hack_start();
} /* ddp_init */