]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/ddp_proto.c
xnu-344.49.tar.gz
[apple/xnu.git] / bsd / netat / ddp_proto.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
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
13 * file.
14 *
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.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Copyright (c) 1988, 1989, 1997, 1998 Apple Computer, Inc.
27 *
28 * Modified for MP, 1996 by Tuyen Nguyen
29 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
30 */
31
32 /* ddp_proto.c: 2.0, 1.23; 10/18/93; Apple Computer, Inc. */
33
34 #include <sys/errno.h>
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <machine/spl.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/proc.h>
41 #include <sys/filedesc.h>
42 #include <sys/fcntl.h>
43 #include <sys/mbuf.h>
44 #include <sys/ioctl.h>
45 #include <sys/malloc.h>
46 #include <sys/socket.h>
47 #include <sys/socketvar.h>
48 #include <sys/buf.h>
49
50 #include <net/if.h>
51
52 #include <netat/sysglue.h>
53 #include <netat/appletalk.h>
54 #include <netat/at_var.h>
55 #include <netat/ddp.h>
56 #include <netat/zip.h>
57 #include <netat/at_pcb.h>
58
59 extern at_ifaddr_t *ifID_home;
60
61 void ddp_putmsg(gref, mp)
62 gref_t *gref;
63 gbuf_t *mp;
64 {
65 u_char socket;
66 register ioc_t *iocbp;
67 register int error;
68 at_ddp_t *ddp;
69
70 switch(gbuf_type(mp)) {
71 case MSG_DATA :
72 /* If this message is going out on a socket that's not bound,
73 * nail it.
74 */
75 ddp = (at_ddp_t *)gbuf_rptr(mp);
76 if ((ddp->type == DDP_ATP) || (ddp->type == DDP_ADSP)) {
77 if ((gref == 0) || (gref->lport == 0)) {
78 int src_addr_included =
79 ((ddp->type==DDP_ATP) && ddp->src_node)? 1 : 0;
80 (void)ddp_output(&mp, ddp->src_socket,
81 src_addr_included);
82 return;
83 }
84 }
85
86 if (gref && (gref->lport == 0)) {
87 gbuf_freel(mp);
88 atalk_notify(gref, ENOTCONN);
89 return;
90 }
91 if ((error = ddp_output(&mp, gref->lport, 0)) != 0) {
92 if (gref)
93 atalk_notify(gref, error);
94 }
95 return;
96
97 case MSG_IOCTL :
98 iocbp = (ioc_t *)gbuf_rptr(mp);
99 if (DDP_IOC_MYIOCTL(iocbp->ioc_cmd)) {
100 switch(iocbp->ioc_cmd) {
101 case DDP_IOC_GET_CFG :
102 /* Note that DDP_IOC_GET_CFG / AppleTalk ddp_config()
103 fills in the net and node of the ddp_addr_t param
104 with the net and node of the default interface,
105 not the net and node that has been bound, as
106 getsockname() and sockopt DDP_GETSOCKNAME do.
107 */
108 #ifdef APPLETALK_DEBUG
109 kprintf("ddp_putmsg: DDP_IOC_GET_CFG\n");
110 #endif
111 if (gbuf_cont(mp))
112 gbuf_freem(gbuf_cont(mp));
113 if ((gbuf_cont(mp) =
114 gbuf_alloc(sizeof(ddp_addr_t),
115 PRI_MED)) == NULL) {
116 ioc_ack(ENOBUFS, mp, gref);
117 break;
118 }
119 {
120 /* *** was ddp_get_cfg() *** */
121 ddp_addr_t *cfgp =
122 (ddp_addr_t *)gbuf_rptr(gbuf_cont(mp));
123 cfgp->inet.net = ifID_home->ifThisNode.s_net;
124 cfgp->inet.node = ifID_home->ifThisNode.s_node;
125 #ifdef NOT_YET
126 cfgp->inet.net = gref->laddr.s_net;
127 cfgp->inet.node = gref->laddr.s_node;
128 #endif
129 cfgp->inet.socket = gref->lport;
130 cfgp->ddptype = gref->ddptype;
131 }
132 gbuf_wset(gbuf_cont(mp), sizeof(ddp_addr_t));
133 iocbp->ioc_count = sizeof(ddp_addr_t);
134 ioc_ack(0, mp, gref);
135 break;
136 default:
137 ioc_ack(EINVAL, mp, gref);
138 break;
139 }
140 } else {
141 /* Unknown ioctl */
142 ioc_ack(EINVAL, mp, gref);
143 }
144 break;
145 default :
146 #ifdef APPLETALK_DEBUG
147 kprintf("unexpected message type in ddp_putmsg: %d/n",
148 gbuf_type(mp));
149 #endif
150 gbuf_freem(mp);
151 break;
152 }
153 return;
154 } /* ddp_putmsg */
155
156 gbuf_t *ddp_compress_msg(mp)
157 register gbuf_t *mp;
158 {
159 register gbuf_t *tmp;
160
161 while (gbuf_len(mp) == 0) {
162 tmp = mp;
163 mp = gbuf_cont(mp);
164 gbuf_freeb(tmp);
165
166 if (mp == NULL)
167 break;
168 }
169 return (mp);
170 }