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