]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/ddp_usrreq.c
215a72510fb5d165cd293f629d513d684e2a508c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1998 Apple Computer, Inc.
32 #include <sys/errno.h>
33 #include <sys/types.h>
34 #include <sys/param.h>
35 #include <machine/spl.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
39 #include <sys/filedesc.h>
40 #include <sys/fcntl.h>
42 #include <sys/ioctl.h>
43 #include <sys/malloc.h>
44 #include <sys/socket.h>
45 #include <sys/socketvar.h>
46 #include <sys/protosw.h>
50 #include <netat/appletalk.h>
51 #include <netat/at_var.h>
52 #include <netat/sysglue.h>
53 #include <netat/ddp.h>
55 #include <netat/rtmp.h>
56 #include <netat/zip.h>
57 #include <netat/at_pcb.h>
58 #include <netat/routing_tables.h>
59 #include <netat/nbp.h>
61 extern int at_control(), at_memzone_init();
62 extern void nbp_input(), ep_input(), zip_router_input(),
63 sip_input(), add_ddp_handler(), init_ddp_handler(),
64 ddp_start(), ddp_input(), appletalk_hack_start();
65 extern u_short
ddp_checksum();
66 extern at_ifaddr_t
*forUs();
67 extern struct mbuf
*m_dup(struct mbuf
*, int);
69 extern at_ifaddr_t
*ifID_home
;
72 struct atpcb ddp_head
;
73 u_long ddp_sendspace
= 600, /* *** what should this value be? *** */
74 ddp_recvspace
= 50 * (600 + sizeof(struct sockaddr_at
));
76 int ddp_pru_control(struct socket
*so
, u_long cmd
, caddr_t data
,
77 struct ifnet
*ifp
, struct proc
*p
)
79 return(at_control(so
, cmd
, data
, ifp
));
83 int ddp_pru_attach(struct socket
*so
, int proto
,
88 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
91 error
= at_pcballoc(so
, &ddp_head
);
95 error
= soreserve(so
, ddp_sendspace
, ddp_recvspace
);
96 pcb
= (struct atpcb
*)((so
)->so_pcb
);
97 pcb
->pid
= current_proc()->p_pid
;
98 pcb
->ddptype
= (u_char
) proto
; /* set in socreate() */
99 pcb
->proto
= ATPROTO_DDP
;
105 int ddp_pru_disconnect(struct socket
*so
)
109 at_ddp_t
*ddp
= NULL
;
110 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
115 if ((so
->so_state
& SS_ISCONNECTED
) == 0)
118 soisdisconnected(so
);
127 int ddp_pru_abort(struct socket
*so
)
130 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
135 soisdisconnected(so
);
143 int ddp_pru_detach(struct socket
*so
)
146 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
157 int ddp_pru_shutdown(struct socket
*so
)
159 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
169 int ddp_pru_bind(struct socket
*so
, struct sockaddr
*nam
,
172 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
177 return (at_pcbbind(pcb
, nam
));
181 int ddp_pru_send(struct socket
*so
, int flags
, struct mbuf
*m
,
182 struct sockaddr
*addr
, struct mbuf
*control
,
185 at_ddp_t
*ddp
= NULL
;
186 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
192 * Set type to MSG_DATA. Otherwise looped back packet is not
193 * recognized by atp_input() and possibly other protocols.
196 MCHTYPE(m
, MSG_DATA
);
198 if (!(pcb
->ddp_flags
& DDPFLG_HDRINCL
)) {
199 /* prepend a DDP header */
200 M_PREPEND(m
, DDP_X_HDR_SIZE
, M_WAIT
);
201 ddp
= mtod(m
, at_ddp_t
*);
204 if (so
->so_state
& SS_ISCONNECTED
) {
209 NET_ASSIGN(ddp
->dst_net
, pcb
->raddr
.s_net
);
210 ddp
->dst_node
= pcb
->raddr
.s_node
;
211 ddp
->dst_socket
= pcb
->rport
;
218 struct sockaddr_at
*dst
=
219 (struct sockaddr_at
*) addr
;
220 NET_ASSIGN(ddp
->dst_net
, dst
->sat_addr
.s_net
);
221 ddp
->dst_node
= dst
->sat_addr
.s_node
;
222 ddp
->dst_socket
= dst
->sat_port
;
226 ddp
->length
= m
->m_pkthdr
.len
;
227 UAS_ASSIGN(ddp
->checksum
,
228 (pcb
->ddp_flags
& DDPFLG_CHKSUM
)? 1: 0);
229 ddp
->type
= (pcb
->ddptype
)? pcb
->ddptype
: DEFAULT_OT_DDPTYPE
;
231 NET_ASSIGN(ddp
->src_net
, pcb
->laddr
.s_net
);
232 ddp
->src_node
= pcb
->laddr
.s_node
;
233 ddp
->src_socket
= pcb
->lport
;
236 ddp
= mtod(m
, at_ddp_t
*);
238 if (NET_VALUE(ddp
->dst_net
) == ATADDR_ANYNET
&&
239 ddp
->dst_node
== ATADDR_BCASTNODE
&&
240 (pcb
->ddp_flags
& DDPFLG_SLFSND
)) {
243 if ((n
= m_dup(m
, M_DONTWAIT
))) {
246 *ifIDTmp
= (at_ifaddr_t
*)NULL
;
248 /* as in ddp_output() loop processing, fill in the
249 rest of the header */
250 ddp
= mtod(n
, at_ddp_t
*);
251 if (MULTIHOME_MODE
&& (ifIDTmp
= forUs(ddp
)))
253 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
254 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
255 ddp
->src_socket
= pcb
->lport
;
256 if (UAS_VALUE(ddp
->checksum
))
257 UAS_ASSIGN(ddp
->checksum
, ddp_checksum(m
, 4));
261 return(ddp_output(&m
, pcb
->lport
, FALSE
));
264 int ddp_pru_sockaddr(struct socket
*so
,
265 struct sockaddr
**nam
)
269 struct sockaddr_at
*sat
;
271 MALLOC(sat
, struct sockaddr_at
*, sizeof *sat
, M_SONAME
, M_WAITOK
);
274 bzero((caddr_t
)sat
, sizeof(*sat
));
277 if ((pcb
= sotoatpcb(so
)) == NULL
) {
283 sat
->sat_family
= AF_APPLETALK
;
284 sat
->sat_len
= sizeof(*sat
);
285 sat
->sat_port
= pcb
->lport
;
286 sat
->sat_addr
= pcb
->laddr
;
289 *nam
= (struct sockaddr
*)sat
;
294 int ddp_pru_peeraddr(struct socket
*so
,
295 struct sockaddr
**nam
)
299 struct sockaddr_at
*sat
;
301 MALLOC(sat
, struct sockaddr_at
*, sizeof *sat
, M_SONAME
, M_WAITOK
);
304 bzero((caddr_t
)sat
, sizeof(*sat
));
307 if ((pcb
= sotoatpcb(so
)) == NULL
) {
313 sat
->sat_family
= AF_APPLETALK
;
314 sat
->sat_len
= sizeof(*sat
);
315 sat
->sat_port
= pcb
->rport
;
316 sat
->sat_addr
= pcb
->raddr
;
319 *nam
= (struct sockaddr
*)sat
;
324 int ddp_pru_connect(struct socket
*so
, struct sockaddr
*nam
,
327 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
328 struct sockaddr_at
*faddr
= (struct sockaddr_at
*) nam
;
334 return (EADDRNOTAVAIL
);
336 if (faddr
->sat_family
!= AF_APPLETALK
)
337 return (EAFNOSUPPORT
);
339 pcb
->raddr
= faddr
->sat_addr
;
347 * One-time AppleTalk initialization
352 ddp_head
.atpcb_next
= ddp_head
.atpcb_prev
= &ddp_head
;
355 /* Initialize protocols implemented in the kernel */
356 add_ddp_handler(EP_SOCKET
, ep_input
);
357 add_ddp_handler(ZIP_SOCKET
, zip_router_input
);
358 add_ddp_handler(NBP_SOCKET
, nbp_input
);
359 add_ddp_handler(DDP_SOCKET_1st_DYNAMIC
, sip_input
);
363 appletalk_hack_start();