]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/ddp_usrreq.c
adec74e17c6528f3a9bfff0541bd3858dce13efa
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright (c) 1998 Apple Computer, Inc.
30 #include <sys/errno.h>
31 #include <sys/types.h>
32 #include <sys/param.h>
33 #include <machine/spl.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
37 #include <sys/filedesc.h>
38 #include <sys/fcntl.h>
40 #include <sys/ioctl.h>
41 #include <sys/malloc.h>
42 #include <sys/socket.h>
43 #include <sys/socketvar.h>
44 #include <sys/protosw.h>
48 #include <netat/appletalk.h>
49 #include <netat/at_var.h>
50 #include <netat/sysglue.h>
51 #include <netat/ddp.h>
53 #include <netat/rtmp.h>
54 #include <netat/zip.h>
55 #include <netat/at_pcb.h>
56 #include <netat/routing_tables.h>
57 #include <netat/nbp.h>
59 extern int at_control(), at_memzone_init();
60 extern void nbp_input(), ep_input(), zip_router_input(),
61 sip_input(), add_ddp_handler(), init_ddp_handler(),
62 ddp_start(), ddp_input(), appletalk_hack_start();
63 extern u_short
ddp_checksum();
64 extern at_ifaddr_t
*forUs();
65 extern struct mbuf
*m_dup(struct mbuf
*, int);
67 extern at_ifaddr_t
*ifID_home
;
70 struct atpcb ddp_head
;
71 u_long ddp_sendspace
= 600, /* *** what should this value be? *** */
72 ddp_recvspace
= 50 * (600 + sizeof(struct sockaddr_at
));
74 int ddp_pru_control(struct socket
*so
, u_long cmd
, caddr_t data
,
75 struct ifnet
*ifp
, struct proc
*p
)
77 return(at_control(so
, cmd
, data
, ifp
));
81 int ddp_pru_attach(struct socket
*so
, int proto
,
86 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
88 error
= soreserve(so
, ddp_sendspace
, ddp_recvspace
);
93 error
= at_pcballoc(so
, &ddp_head
);
97 pcb
= (struct atpcb
*)((so
)->so_pcb
);
98 pcb
->pid
= proc_selfpid();
99 pcb
->ddptype
= (u_char
) proto
; /* set in socreate() */
100 pcb
->proto
= ATPROTO_DDP
;
106 int ddp_pru_disconnect(struct socket
*so
)
110 at_ddp_t
*ddp
= NULL
;
111 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
116 if ((so
->so_state
& SS_ISCONNECTED
) == 0)
119 soisdisconnected(so
);
128 int ddp_pru_abort(struct socket
*so
)
131 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
136 soisdisconnected(so
);
144 int ddp_pru_detach(struct socket
*so
)
147 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
158 int ddp_pru_shutdown(struct socket
*so
)
160 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
170 int ddp_pru_bind(struct socket
*so
, struct sockaddr
*nam
,
173 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
178 return (at_pcbbind(pcb
, nam
));
182 int ddp_pru_send(struct socket
*so
, int flags
, struct mbuf
*m
,
183 struct sockaddr
*addr
, struct mbuf
*control
,
186 at_ddp_t
*ddp
= NULL
;
187 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
193 * Set type to MSG_DATA. Otherwise looped back packet is not
194 * recognized by atp_input() and possibly other protocols.
197 MCHTYPE(m
, MSG_DATA
);
199 if (!(pcb
->ddp_flags
& DDPFLG_HDRINCL
)) {
200 /* prepend a DDP header */
201 M_PREPEND(m
, DDP_X_HDR_SIZE
, M_WAIT
);
202 ddp
= mtod(m
, at_ddp_t
*);
205 if (so
->so_state
& SS_ISCONNECTED
) {
210 NET_ASSIGN(ddp
->dst_net
, pcb
->raddr
.s_net
);
211 ddp
->dst_node
= pcb
->raddr
.s_node
;
212 ddp
->dst_socket
= pcb
->rport
;
219 struct sockaddr_at
*dst
=
220 (struct sockaddr_at
*) addr
;
221 NET_ASSIGN(ddp
->dst_net
, dst
->sat_addr
.s_net
);
222 ddp
->dst_node
= dst
->sat_addr
.s_node
;
223 ddp
->dst_socket
= dst
->sat_port
;
227 ddp
->length
= m
->m_pkthdr
.len
;
228 UAS_ASSIGN(ddp
->checksum
,
229 (pcb
->ddp_flags
& DDPFLG_CHKSUM
)? 1: 0);
230 ddp
->type
= (pcb
->ddptype
)? pcb
->ddptype
: DEFAULT_OT_DDPTYPE
;
232 NET_ASSIGN(ddp
->src_net
, pcb
->laddr
.s_net
);
233 ddp
->src_node
= pcb
->laddr
.s_node
;
234 ddp
->src_socket
= pcb
->lport
;
237 ddp
= mtod(m
, at_ddp_t
*);
239 if (NET_VALUE(ddp
->dst_net
) == ATADDR_ANYNET
&&
240 ddp
->dst_node
== ATADDR_BCASTNODE
&&
241 (pcb
->ddp_flags
& DDPFLG_SLFSND
)) {
244 if ((n
= m_dup(m
, M_DONTWAIT
))) {
247 *ifIDTmp
= (at_ifaddr_t
*)NULL
;
249 /* as in ddp_output() loop processing, fill in the
250 rest of the header */
251 ddp
= mtod(n
, at_ddp_t
*);
252 if (MULTIHOME_MODE
&& (ifIDTmp
= forUs(ddp
)))
254 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
255 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
256 ddp
->src_socket
= pcb
->lport
;
257 if (UAS_VALUE(ddp
->checksum
))
258 UAS_ASSIGN(ddp
->checksum
, ddp_checksum(m
, 4));
262 return(ddp_output(&m
, pcb
->lport
, FALSE
));
265 int ddp_pru_sockaddr(struct socket
*so
,
266 struct sockaddr
**nam
)
270 struct sockaddr_at
*sat
;
272 MALLOC(sat
, struct sockaddr_at
*, sizeof *sat
, M_SONAME
, M_WAITOK
);
275 bzero((caddr_t
)sat
, sizeof(*sat
));
278 if ((pcb
= sotoatpcb(so
)) == NULL
) {
284 sat
->sat_family
= AF_APPLETALK
;
285 sat
->sat_len
= sizeof(*sat
);
286 sat
->sat_port
= pcb
->lport
;
287 sat
->sat_addr
= pcb
->laddr
;
290 *nam
= (struct sockaddr
*)sat
;
295 int ddp_pru_peeraddr(struct socket
*so
,
296 struct sockaddr
**nam
)
300 struct sockaddr_at
*sat
;
302 MALLOC(sat
, struct sockaddr_at
*, sizeof *sat
, M_SONAME
, M_WAITOK
);
305 bzero((caddr_t
)sat
, sizeof(*sat
));
308 if ((pcb
= sotoatpcb(so
)) == NULL
) {
314 sat
->sat_family
= AF_APPLETALK
;
315 sat
->sat_len
= sizeof(*sat
);
316 sat
->sat_port
= pcb
->rport
;
317 sat
->sat_addr
= pcb
->raddr
;
320 *nam
= (struct sockaddr
*)sat
;
325 int ddp_pru_connect(struct socket
*so
, struct sockaddr
*nam
,
328 struct atpcb
*pcb
= (struct atpcb
*)((so
)->so_pcb
);
329 struct sockaddr_at
*faddr
= (struct sockaddr_at
*) nam
;
335 return (EADDRNOTAVAIL
);
337 if (faddr
->sat_family
!= AF_APPLETALK
)
338 return (EAFNOSUPPORT
);
340 pcb
->raddr
= faddr
->sat_addr
;
348 * One-time AppleTalk initialization
353 ddp_head
.atpcb_next
= ddp_head
.atpcb_prev
= &ddp_head
;
356 /* Initialize protocols implemented in the kernel */
357 add_ddp_handler(EP_SOCKET
, ep_input
);
358 add_ddp_handler(ZIP_SOCKET
, zip_router_input
);
359 add_ddp_handler(NBP_SOCKET
, nbp_input
);
360 add_ddp_handler(DDP_SOCKET_1st_DYNAMIC
, sip_input
);
364 appletalk_hack_start();