]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/ddp_usrreq.c
9ad2b99f2a0351a6b0d0d5ef729f3705ba815004
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/appletalk.h>
54 #include <netat/at_var.h>
55 #include <netat/sysglue.h>
56 #include <netat/ddp.h>
58 #include <netat/rtmp.h>
59 #include <netat/zip.h>
60 #include <netat/at_pcb.h>
61 #include <netat/routing_tables.h>
62 #include <netat/nbp.h>
64 extern int at_control(), at_memzone_init();
65 extern void nbp_input(), ep_input(), zip_router_input(),
66 sip_input(), add_ddp_handler(), init_ddp_handler(),
67 ddp_start(), ddp_input(), appletalk_hack_start();
68 extern u_short
ddp_checksum();
69 extern at_ifaddr_t
*forUs();
70 extern struct mbuf
*m_dup(struct mbuf
*, int);
72 extern at_ifaddr_t
*ifID_home
;
75 struct atpcb ddp_head
;
76 u_long ddp_sendspace
= 600, /* *** what should this value be? *** */
77 ddp_recvspace
= 50 * (600 + sizeof(struct sockaddr_at
));
79 int ddp_pru_control(struct socket
*so
, u_long cmd
, caddr_t data
,
80 struct ifnet
*ifp
, struct proc
*p
)
82 return(at_control(so
, cmd
, data
, ifp
));
86 int ddp_pru_attach(struct socket
*so
, int proto
,
91 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
93 error
= soreserve(so
, ddp_sendspace
, ddp_recvspace
);
97 error
= at_pcballoc(so
, &ddp_head
);
100 pcb
= (struct atpcb
*)((so
)->so_pcb
);
101 pcb
->pid
= proc_selfpid();
102 pcb
->ddptype
= (u_char
) proto
; /* set in socreate() */
103 pcb
->proto
= ATPROTO_DDP
;
109 int ddp_pru_disconnect(struct socket
*so
)
113 at_ddp_t
*ddp
= NULL
;
114 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
119 if ((so
->so_state
& SS_ISCONNECTED
) == 0)
122 soisdisconnected(so
);
129 int ddp_pru_abort(struct socket
*so
)
131 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
136 soisdisconnected(so
);
142 int ddp_pru_detach(struct socket
*so
)
144 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
153 int ddp_pru_shutdown(struct socket
*so
)
155 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
165 int ddp_pru_bind(struct socket
*so
, struct sockaddr
*nam
,
168 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
173 return (at_pcbbind(pcb
, nam
));
177 int ddp_pru_send(struct socket
*so
, int flags
, struct mbuf
*m
,
178 struct sockaddr
*addr
, struct mbuf
*control
,
181 at_ddp_t
*ddp
= NULL
;
182 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
188 * Set type to MSG_DATA. Otherwise looped back packet is not
189 * recognized by atp_input() and possibly other protocols.
192 MCHTYPE(m
, MSG_DATA
);
194 if (!(pcb
->ddp_flags
& DDPFLG_HDRINCL
)) {
195 /* prepend a DDP header */
196 M_PREPEND(m
, DDP_X_HDR_SIZE
, M_WAIT
);
197 ddp
= mtod(m
, at_ddp_t
*);
200 if (so
->so_state
& SS_ISCONNECTED
) {
205 NET_ASSIGN(ddp
->dst_net
, pcb
->raddr
.s_net
);
206 ddp
->dst_node
= pcb
->raddr
.s_node
;
207 ddp
->dst_socket
= pcb
->rport
;
214 struct sockaddr_at
*dst
=
215 (struct sockaddr_at
*) addr
;
216 NET_ASSIGN(ddp
->dst_net
, dst
->sat_addr
.s_net
);
217 ddp
->dst_node
= dst
->sat_addr
.s_node
;
218 ddp
->dst_socket
= dst
->sat_port
;
222 DDPLEN_ASSIGN(ddp
, m
->m_pkthdr
.len
);
223 UAS_ASSIGN_HTON(ddp
->checksum
,
224 (pcb
->ddp_flags
& DDPFLG_CHKSUM
)? 1: 0);
225 ddp
->type
= (pcb
->ddptype
)? pcb
->ddptype
: DEFAULT_OT_DDPTYPE
;
227 NET_ASSIGN(ddp
->src_net
, pcb
->laddr
.s_net
);
228 ddp
->src_node
= pcb
->laddr
.s_node
;
229 ddp
->src_socket
= pcb
->lport
;
232 ddp
= mtod(m
, at_ddp_t
*);
234 if (NET_VALUE(ddp
->dst_net
) == ATADDR_ANYNET
&&
235 ddp
->dst_node
== ATADDR_BCASTNODE
&&
236 (pcb
->ddp_flags
& DDPFLG_SLFSND
)) {
239 if ((n
= m_dup(m
, M_DONTWAIT
))) {
242 *ifIDTmp
= (at_ifaddr_t
*)NULL
;
244 /* as in ddp_output() loop processing, fill in the
245 rest of the header */
246 ddp
= mtod(n
, at_ddp_t
*);
247 if (MULTIHOME_MODE
&& (ifIDTmp
= forUs(ddp
)))
249 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
250 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
251 ddp
->src_socket
= pcb
->lport
;
252 if (UAS_VALUE_NTOH(ddp
->checksum
))
253 UAS_ASSIGN_HTON(ddp
->checksum
, ddp_checksum(m
, 4));
257 return(ddp_output(&m
, pcb
->lport
, FALSE
));
260 int ddp_pru_sockaddr(struct socket
*so
,
261 struct sockaddr
**nam
)
264 struct sockaddr_at
*sat
;
266 MALLOC(sat
, struct sockaddr_at
*, sizeof *sat
, M_SONAME
, M_WAITOK
);
269 bzero((caddr_t
)sat
, sizeof(*sat
));
271 if ((pcb
= sotoatpcb(so
)) == NULL
) {
276 sat
->sat_family
= AF_APPLETALK
;
277 sat
->sat_len
= sizeof(*sat
);
278 sat
->sat_port
= pcb
->lport
;
279 sat
->sat_addr
= pcb
->laddr
;
281 *nam
= (struct sockaddr
*)sat
;
286 int ddp_pru_peeraddr(struct socket
*so
,
287 struct sockaddr
**nam
)
290 struct sockaddr_at
*sat
;
292 MALLOC(sat
, struct sockaddr_at
*, sizeof *sat
, M_SONAME
, M_WAITOK
);
295 bzero((caddr_t
)sat
, sizeof(*sat
));
297 if ((pcb
= sotoatpcb(so
)) == NULL
) {
302 sat
->sat_family
= AF_APPLETALK
;
303 sat
->sat_len
= sizeof(*sat
);
304 sat
->sat_port
= pcb
->rport
;
305 sat
->sat_addr
= pcb
->raddr
;
307 *nam
= (struct sockaddr
*)sat
;
312 int ddp_pru_connect(struct socket
*so
, struct sockaddr
*nam
,
315 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
316 struct sockaddr_at
*faddr
= (struct sockaddr_at
*) nam
;
322 return (EADDRNOTAVAIL
);
324 if (faddr
->sat_family
!= AF_APPLETALK
)
325 return (EAFNOSUPPORT
);
327 pcb
->raddr
= faddr
->sat_addr
;
335 * One-time AppleTalk initialization
340 ddp_head
.atpcb_next
= ddp_head
.atpcb_prev
= &ddp_head
;
343 /* Initialize protocols implemented in the kernel */
344 add_ddp_handler(EP_SOCKET
, ep_input
);
345 add_ddp_handler(ZIP_SOCKET
, zip_router_input
);
346 add_ddp_handler(NBP_SOCKET
, nbp_input
);
347 add_ddp_handler(DDP_SOCKET_1st_DYNAMIC
, sip_input
);
351 appletalk_hack_start();