]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/aurp_tx.c
bf725fa1e2213a8e847b4aafbafb9b76594fc824
[apple/xnu.git] / bsd / netat / aurp_tx.c
1 /*
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * Copyright (c) 1996 Apple Computer, Inc.
32 *
33 * Created April 8, 1996 by Tuyen Nguyen
34 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
35 *
36 * File: tx.c
37 */
38 #include <sys/errno.h>
39 #include <sys/types.h>
40 #include <sys/param.h>
41 #include <machine/spl.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
44 #include <sys/proc.h>
45 #include <sys/filedesc.h>
46 #include <sys/fcntl.h>
47 #include <sys/mbuf.h>
48 #include <sys/socket.h>
49 #include <sys/socketvar.h>
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/routing_tables.h>
56 #include <netat/at_pcb.h>
57 #include <netat/aurp.h>
58 #include <netat/debug.h>
59
60 /*
61 * Any AURP protocol or appletalk data (ddp) packets flowing through
62 * are inserted into the kernel aurpd process's (atalk) input queue.
63 * Assume here that we deal with single packets, i.e., someone earlier
64 * in the food chain has broken up packet chains.
65 */
66 void AURPsend(mdata, type, node)
67 gbuf_t *mdata;
68 int type, node;
69 {
70 struct aurp_domain *domain;
71 gbuf_t *m;
72 int msize = AT_WR_OFFSET+32+IP_DOMAINSIZE;
73
74 /* Add the domain header */
75 if ((m = gbuf_alloc(msize, PRI_MED)) == 0) {
76 gbuf_freem(mdata);
77 dPrintf(D_M_AURP, D_L_WARNING, ("AURPsend: gbuf_alloc failed\n"));
78 return;
79 }
80 gbuf_wset(m,msize);
81 gbuf_rinc(m,AT_WR_OFFSET+32);
82 gbuf_cont(m) = mdata;
83 domain = (struct aurp_domain *)gbuf_rptr(m);
84 domain->dst_length = IP_LENGTH;
85 domain->dst_authority = IP_AUTHORITY;
86 domain->dst_distinguisher = IP_DISTINGUISHER;
87 domain->src_length = IP_LENGTH;
88 domain->src_authority = IP_AUTHORITY;
89 domain->src_distinguisher = IP_DISTINGUISHER;
90 domain->src_address = aurp_global.src_addr;
91 domain->version = AUD_Version;
92 domain->reserved = 0;
93 domain->type = type;
94 domain->dst_address = aurp_global.dst_addr[node];
95 atalk_to_ip(m);
96 }
97
98 /*
99 * Called from within ddp (via ddp_AURPsendx) to handle data (DDP) packets
100 * sent from the AppleTalk stack, routing updates, and routing info
101 * initialization.
102 */
103 void AURPcmdx(code, mdata, param)
104 int code;
105 gbuf_t *mdata;
106 int param;
107 {
108 unsigned char node;
109 gbuf_t *mdata_next;
110
111 if (mdata == 0)
112 return;
113 if (aurp_gref == 0) {
114 if (code != AURPCODE_DEBUGINFO)
115 AURPfreemsg(mdata);
116 return;
117 }
118
119 switch (code) {
120 case AURPCODE_DATAPKT: /* data packet */
121 node = (unsigned char)param;
122 if (gbuf_next(mdata)) {
123 mdata_next = gbuf_next(mdata);
124 gbuf_next(mdata) = 0;
125 AURPsend(mdata, AUD_Atalk, node);
126 do {
127 mdata = mdata_next;
128 mdata_next = gbuf_next(mdata);
129 gbuf_next(mdata) = 0;
130 /* Indicate non-AURP packet, node id of peer */
131 AURPsend(mdata, AUD_Atalk, node);
132 } while (mdata_next);
133 } else
134 AURPsend(mdata, AUD_Atalk, node);
135 break;
136
137 case AURPCODE_RTUPDATE:
138 AURPrtupdate((RT_entry *)mdata, param);
139 break;
140
141 case AURPCODE_DEBUGINFO: /* debug info */
142 dbgBits = *(dbgBits_t *)mdata;
143 net_port = param;
144 break;
145
146 default:
147 dPrintf(D_M_AURP, D_L_ERROR, ("AURPcmdx: bad code, %d\n", code));
148 }
149 }