]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/ddp_usrreq.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1998 Apple Computer, Inc.
35 #include <sys/errno.h>
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <machine/spl.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
42 #include <sys/filedesc.h>
43 #include <sys/fcntl.h>
45 #include <sys/ioctl.h>
46 #include <sys/malloc.h>
47 #include <sys/socket.h>
48 #include <sys/socketvar.h>
49 #include <sys/protosw.h>
53 #include <netat/sysglue.h>
54 #include <netat/appletalk.h>
55 #include <netat/at_pcb.h>
56 #include <netat/at_var.h>
57 #include <netat/ddp.h>
59 #include <netat/rtmp.h>
60 #include <netat/zip.h>
61 #include <netat/routing_tables.h>
62 #include <netat/nbp.h>
65 extern at_ifaddr_t
*ifID_home
;
68 struct atpcb ddp_head
;
69 u_long ddp_sendspace
= 600, /* *** what should this value be? *** */
70 ddp_recvspace
= 50 * (600 + sizeof(struct sockaddr_at
));
72 int ddp_pru_control(struct socket
*so
, u_long cmd
, caddr_t data
,
73 struct ifnet
*ifp
, __unused
struct proc
*p
)
75 return(at_control(so
, cmd
, data
, ifp
));
79 int ddp_pru_attach(struct socket
*so
, int proto
,
80 __unused
struct proc
*p
)
83 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
85 error
= soreserve(so
, ddp_sendspace
, ddp_recvspace
);
89 error
= at_pcballoc(so
, &ddp_head
);
92 pcb
= (struct atpcb
*)((so
)->so_pcb
);
93 pcb
->pid
= proc_selfpid();
94 pcb
->ddptype
= (u_char
) proto
; /* set in socreate() */
95 pcb
->proto
= ATPROTO_DDP
;
101 int ddp_pru_disconnect(struct socket
*so
)
105 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
110 if ((so
->so_state
& SS_ISCONNECTED
) == 0)
113 soisdisconnected(so
);
120 int ddp_pru_abort(struct socket
*so
)
122 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
127 soisdisconnected(so
);
133 int ddp_pru_detach(struct socket
*so
)
135 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
144 int ddp_pru_shutdown(struct socket
*so
)
146 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
156 int ddp_pru_bind(struct socket
*so
, struct sockaddr
*nam
,
157 __unused
struct proc
*p
)
159 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
164 return (at_pcbbind(pcb
, nam
));
168 int ddp_pru_send(struct socket
*so
, __unused
int flags
, struct mbuf
*m
,
169 struct sockaddr
*addr
, __unused
struct mbuf
*control
,
170 __unused
struct proc
*p
)
172 at_ddp_t
*ddp
= NULL
;
173 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
179 * Set type to MSG_DATA. Otherwise looped back packet is not
180 * recognized by atp_input() and possibly other protocols.
183 MCHTYPE(m
, MSG_DATA
);
185 if (!(pcb
->ddp_flags
& DDPFLG_HDRINCL
)) {
186 /* prepend a DDP header */
187 M_PREPEND(m
, DDP_X_HDR_SIZE
, M_WAIT
);
188 ddp
= mtod(m
, at_ddp_t
*);
191 if (so
->so_state
& SS_ISCONNECTED
) {
196 NET_ASSIGN(ddp
->dst_net
, pcb
->raddr
.s_net
);
197 ddp
->dst_node
= pcb
->raddr
.s_node
;
198 ddp
->dst_socket
= pcb
->rport
;
205 struct sockaddr_at
*dst
=
206 (struct sockaddr_at
*) addr
;
207 NET_ASSIGN(ddp
->dst_net
, dst
->sat_addr
.s_net
);
208 ddp
->dst_node
= dst
->sat_addr
.s_node
;
209 ddp
->dst_socket
= dst
->sat_port
;
213 DDPLEN_ASSIGN(ddp
, m
->m_pkthdr
.len
);
214 UAS_ASSIGN_HTON(ddp
->checksum
,
215 (pcb
->ddp_flags
& DDPFLG_CHKSUM
)? 1: 0);
216 ddp
->type
= (pcb
->ddptype
)? pcb
->ddptype
: DEFAULT_OT_DDPTYPE
;
218 NET_ASSIGN(ddp
->src_net
, pcb
->laddr
.s_net
);
219 ddp
->src_node
= pcb
->laddr
.s_node
;
220 ddp
->src_socket
= pcb
->lport
;
223 ddp
= mtod(m
, at_ddp_t
*);
225 if (NET_VALUE(ddp
->dst_net
) == ATADDR_ANYNET
&&
226 ddp
->dst_node
== ATADDR_BCASTNODE
&&
227 (pcb
->ddp_flags
& DDPFLG_SLFSND
)) {
230 if ((n
= m_dup(m
, M_DONTWAIT
))) {
233 *ifIDTmp
= (at_ifaddr_t
*)NULL
;
235 /* as in ddp_output() loop processing, fill in the
236 rest of the header */
237 ddp
= mtod(n
, at_ddp_t
*);
238 if (MULTIHOME_MODE
&& (ifIDTmp
= forUs(ddp
)))
240 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
241 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
242 ddp
->src_socket
= pcb
->lport
;
243 if (UAS_VALUE_NTOH(ddp
->checksum
))
244 UAS_ASSIGN_HTON(ddp
->checksum
, ddp_checksum(m
, 4));
248 return(ddp_output(&m
, pcb
->lport
, FALSE
));
251 int ddp_pru_sockaddr(struct socket
*so
,
252 struct sockaddr
**nam
)
255 struct sockaddr_at
*sat
;
257 MALLOC(sat
, struct sockaddr_at
*, sizeof *sat
, M_SONAME
, M_WAITOK
);
260 bzero((caddr_t
)sat
, sizeof(*sat
));
262 if ((pcb
= sotoatpcb(so
)) == NULL
) {
267 sat
->sat_family
= AF_APPLETALK
;
268 sat
->sat_len
= sizeof(*sat
);
269 sat
->sat_port
= pcb
->lport
;
270 sat
->sat_addr
= pcb
->laddr
;
272 *nam
= (struct sockaddr
*)sat
;
277 int ddp_pru_peeraddr(struct socket
*so
,
278 struct sockaddr
**nam
)
281 struct sockaddr_at
*sat
;
283 MALLOC(sat
, struct sockaddr_at
*, sizeof *sat
, M_SONAME
, M_WAITOK
);
286 bzero((caddr_t
)sat
, sizeof(*sat
));
288 if ((pcb
= sotoatpcb(so
)) == NULL
) {
293 sat
->sat_family
= AF_APPLETALK
;
294 sat
->sat_len
= sizeof(*sat
);
295 sat
->sat_port
= pcb
->rport
;
296 sat
->sat_addr
= pcb
->raddr
;
298 *nam
= (struct sockaddr
*)sat
;
303 int ddp_pru_connect(struct socket
*so
, struct sockaddr
*nam
,
304 __unused
struct proc
*p
)
306 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
307 struct sockaddr_at
*faddr
= (struct sockaddr_at
*) nam
;
313 return (EADDRNOTAVAIL
);
315 if (faddr
->sat_family
!= AF_APPLETALK
)
316 return (EAFNOSUPPORT
);
318 pcb
->raddr
= faddr
->sat_addr
;
325 * One-time AppleTalk initialization
330 ddp_head
.atpcb_next
= ddp_head
.atpcb_prev
= &ddp_head
;
333 /* Initialize protocols implemented in the kernel */
334 add_ddp_handler(EP_SOCKET
, ep_input
);
335 add_ddp_handler(ZIP_SOCKET
, zip_router_input
);
336 add_ddp_handler(NBP_SOCKET
, nbp_input
);
337 add_ddp_handler(DDP_SOCKET_1st_DYNAMIC
, sip_input
);
341 appletalk_hack_start();