]>
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
);
190 ddp
= mtod(m
, at_ddp_t
*);
193 if (so
->so_state
& SS_ISCONNECTED
) {
198 NET_ASSIGN(ddp
->dst_net
, pcb
->raddr
.s_net
);
199 ddp
->dst_node
= pcb
->raddr
.s_node
;
200 ddp
->dst_socket
= pcb
->rport
;
207 struct sockaddr_at
*dst
=
208 (struct sockaddr_at
*) addr
;
209 NET_ASSIGN(ddp
->dst_net
, dst
->sat_addr
.s_net
);
210 ddp
->dst_node
= dst
->sat_addr
.s_node
;
211 ddp
->dst_socket
= dst
->sat_port
;
215 DDPLEN_ASSIGN(ddp
, m
->m_pkthdr
.len
);
216 UAS_ASSIGN_HTON(ddp
->checksum
,
217 (pcb
->ddp_flags
& DDPFLG_CHKSUM
)? 1: 0);
218 ddp
->type
= (pcb
->ddptype
)? pcb
->ddptype
: DEFAULT_OT_DDPTYPE
;
220 NET_ASSIGN(ddp
->src_net
, pcb
->laddr
.s_net
);
221 ddp
->src_node
= pcb
->laddr
.s_node
;
222 ddp
->src_socket
= pcb
->lport
;
225 ddp
= mtod(m
, at_ddp_t
*);
227 if (NET_VALUE(ddp
->dst_net
) == ATADDR_ANYNET
&&
228 ddp
->dst_node
== ATADDR_BCASTNODE
&&
229 (pcb
->ddp_flags
& DDPFLG_SLFSND
)) {
232 if ((n
= m_dup(m
, M_DONTWAIT
))) {
235 *ifIDTmp
= (at_ifaddr_t
*)NULL
;
237 /* as in ddp_output() loop processing, fill in the
238 rest of the header */
239 ddp
= mtod(n
, at_ddp_t
*);
240 if (MULTIHOME_MODE
&& (ifIDTmp
= forUs(ddp
)))
242 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
243 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
244 ddp
->src_socket
= pcb
->lport
;
245 if (UAS_VALUE_NTOH(ddp
->checksum
))
246 UAS_ASSIGN_HTON(ddp
->checksum
, ddp_checksum(m
, 4));
250 return(ddp_output(&m
, pcb
->lport
, FALSE
));
253 int ddp_pru_sockaddr(struct socket
*so
,
254 struct sockaddr
**nam
)
257 struct sockaddr_at
*sat
;
259 MALLOC(sat
, struct sockaddr_at
*, sizeof *sat
, M_SONAME
, M_WAITOK
);
262 bzero((caddr_t
)sat
, sizeof(*sat
));
264 if ((pcb
= sotoatpcb(so
)) == NULL
) {
269 sat
->sat_family
= AF_APPLETALK
;
270 sat
->sat_len
= sizeof(*sat
);
271 sat
->sat_port
= pcb
->lport
;
272 sat
->sat_addr
= pcb
->laddr
;
274 *nam
= (struct sockaddr
*)sat
;
279 int ddp_pru_peeraddr(struct socket
*so
,
280 struct sockaddr
**nam
)
283 struct sockaddr_at
*sat
;
285 MALLOC(sat
, struct sockaddr_at
*, sizeof *sat
, M_SONAME
, M_WAITOK
);
288 bzero((caddr_t
)sat
, sizeof(*sat
));
290 if ((pcb
= sotoatpcb(so
)) == NULL
) {
295 sat
->sat_family
= AF_APPLETALK
;
296 sat
->sat_len
= sizeof(*sat
);
297 sat
->sat_port
= pcb
->rport
;
298 sat
->sat_addr
= pcb
->raddr
;
300 *nam
= (struct sockaddr
*)sat
;
305 int ddp_pru_connect(struct socket
*so
, struct sockaddr
*nam
,
306 __unused
struct proc
*p
)
308 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
309 struct sockaddr_at
*faddr
= (struct sockaddr_at
*) nam
;
315 return (EADDRNOTAVAIL
);
317 if (faddr
->sat_family
!= AF_APPLETALK
)
318 return (EAFNOSUPPORT
);
320 pcb
->raddr
= faddr
->sat_addr
;
327 * One-time AppleTalk initialization
332 ddp_head
.atpcb_next
= ddp_head
.atpcb_prev
= &ddp_head
;
335 /* Initialize protocols implemented in the kernel */
336 add_ddp_handler(EP_SOCKET
, ep_input
);
337 add_ddp_handler(ZIP_SOCKET
, zip_router_input
);
338 add_ddp_handler(NBP_SOCKET
, nbp_input
);
339 add_ddp_handler(DDP_SOCKET_1st_DYNAMIC
, sip_input
);
343 appletalk_hack_start();