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