]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/aurp_tx.c
729b6e953c8e59ddbcbf42b7e15e1af0362c551c
[apple/xnu.git] / bsd / netat / aurp_tx.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * Copyright (c) 1996 Apple Computer, Inc.
30 *
31 * Created April 8, 1996 by Tuyen Nguyen
32 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
33 *
34 * File: tx.c
35 */
36 #include <sys/errno.h>
37 #include <sys/types.h>
38 #include <sys/param.h>
39 #include <machine/spl.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/proc.h>
43 #include <sys/filedesc.h>
44 #include <sys/fcntl.h>
45 #include <sys/mbuf.h>
46 #include <sys/socket.h>
47 #include <sys/socketvar.h>
48 #include <net/if.h>
49
50 #include <netat/sysglue.h>
51 #include <netat/appletalk.h>
52 #include <netat/at_var.h>
53 #include <netat/routing_tables.h>
54 #include <netat/at_pcb.h>
55 #include <netat/aurp.h>
56 #include <netat/debug.h>
57
58 /*
59 * Any AURP protocol or appletalk data (ddp) packets flowing through
60 * are inserted into the kernel aurpd process's (atalk) input queue.
61 * Assume here that we deal with single packets, i.e., someone earlier
62 * in the food chain has broken up packet chains.
63 */
64 void AURPsend(mdata, type, node)
65 gbuf_t *mdata;
66 int type, node;
67 {
68 struct aurp_domain *domain;
69 gbuf_t *m;
70 int msize = AT_WR_OFFSET+32+IP_DOMAINSIZE;
71
72 /* Add the domain header */
73 if ((m = gbuf_alloc(msize, PRI_MED)) == 0) {
74 gbuf_freem(mdata);
75 dPrintf(D_M_AURP, D_L_WARNING, ("AURPsend: gbuf_alloc failed\n"));
76 return;
77 }
78 gbuf_wset(m,msize);
79 gbuf_rinc(m,AT_WR_OFFSET+32);
80 gbuf_cont(m) = mdata;
81 domain = (struct aurp_domain *)gbuf_rptr(m);
82 domain->dst_length = IP_LENGTH;
83 domain->dst_authority = IP_AUTHORITY;
84 domain->dst_distinguisher = IP_DISTINGUISHER;
85 domain->src_length = IP_LENGTH;
86 domain->src_authority = IP_AUTHORITY;
87 domain->src_distinguisher = IP_DISTINGUISHER;
88 domain->src_address = aurp_global.src_addr;
89 domain->version = AUD_Version;
90 domain->reserved = 0;
91 domain->type = type;
92 domain->dst_address = aurp_global.dst_addr[node];
93 atalk_to_ip(m);
94 }
95
96 /*
97 * Called from within ddp (via ddp_AURPsendx) to handle data (DDP) packets
98 * sent from the AppleTalk stack, routing updates, and routing info
99 * initialization.
100 */
101 void AURPcmdx(code, mdata, param)
102 int code;
103 gbuf_t *mdata;
104 int param;
105 {
106 unsigned char node;
107 gbuf_t *mdata_next;
108
109 if (mdata == 0)
110 return;
111 if (aurp_gref == 0) {
112 if (code != AURPCODE_DEBUGINFO)
113 AURPfreemsg(mdata);
114 return;
115 }
116
117 switch (code) {
118 case AURPCODE_DATAPKT: /* data packet */
119 node = (unsigned char)param;
120 if (gbuf_next(mdata)) {
121 mdata_next = gbuf_next(mdata);
122 gbuf_next(mdata) = 0;
123 AURPsend(mdata, AUD_Atalk, node);
124 do {
125 mdata = mdata_next;
126 mdata_next = gbuf_next(mdata);
127 gbuf_next(mdata) = 0;
128 /* Indicate non-AURP packet, node id of peer */
129 AURPsend(mdata, AUD_Atalk, node);
130 } while (mdata_next);
131 } else
132 AURPsend(mdata, AUD_Atalk, node);
133 break;
134
135 case AURPCODE_RTUPDATE:
136 AURPrtupdate((RT_entry *)mdata, param);
137 break;
138
139 case AURPCODE_DEBUGINFO: /* debug info */
140 dbgBits = *(dbgBits_t *)mdata;
141 net_port = param;
142 break;
143
144 default:
145 dPrintf(D_M_AURP, D_L_ERROR, ("AURPcmdx: bad code, %d\n", code));
146 }
147 }