2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1988-1998 Apple Computer, Inc.
26 * 0.01 05/12/94 Laurent Dumont Creation
28 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
32 * Router ZIP protocol functions:
34 * This file contains Routing specifics to handle ZIP requests and responses
35 * sent and received by a router node.
37 * The entry point for the zip input in ddp is valid only when we're
38 * running in router mode.
42 #include <sys/errno.h>
43 #include <sys/types.h>
44 #include <sys/param.h>
45 #include <machine/spl.h>
46 #include <sys/systm.h>
47 #include <sys/kernel.h>
49 #include <sys/filedesc.h>
50 #include <sys/fcntl.h>
52 #include <sys/ioctl.h>
53 #include <sys/malloc.h>
54 #include <sys/socket.h>
55 #include <sys/socketvar.h>
58 #include <net/if_types.h>
60 #include <netat/sysglue.h>
61 #include <netat/appletalk.h>
62 #include <netat/at_var.h>
63 #include <netat/ddp.h>
64 #include <netat/nbp.h>
65 #include <netat/zip.h>
66 #include <netat/at_pcb.h>
67 #include <netat/atp.h>
68 #include <netat/routing_tables.h>
69 #include <netat/debug.h>
71 #include <sys/kern_event.h>
73 static void zip_reply_to_getmyzone();
74 extern int at_reg_mcast(), at_unreg_mcast();
77 extern at_ifaddr_t
*ifID_table
[], *ifID_home
;
78 extern short ErrorZIPoverflow
;
80 /**********************************************************************
82 * ZIP is implemented as a "peer" of DDP, so the packets coming in
83 * to ZIP have the same headers as those coming in to DDP {ddp...}.
84 * Same applies to outgoing packets. Also, unlike DDP, ZIP assumes
85 * that an incoming packet is in a contiguous gbuf_t.
87 **********************************************************************/
89 static int netinfo_reply_pending
;
90 static void zip_netinfo_reply(at_x_zip_t
*, at_ifaddr_t
*);
91 static void zip_getnetinfo(at_ifaddr_t
*);
92 static void zip_getnetinfo_funnel(at_ifaddr_t
*);
93 static void send_phony_reply(gbuf_t
*);
96 * zip_send_getnetinfo_reply: we received a GetNetInfo packet, we need to reply
97 * with the right information for the port.
99 static void zip_send_getnetinfo_reply(m
, ifID
)
101 register at_ifaddr_t
*ifID
;
105 at_ddp_t
*ddp
, *ddp_sent
;
106 short ZoneNameProvided
= FALSE
;
107 short RequestIsBroadcasted
= FALSE
;
108 u_short znumber
, len
, packet_length
, size
, status
;
112 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
114 /* access the Zone Name info part of the GetNetInfo Request */
116 zname
= (at_nvestr_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
+ 6);
118 if (zname
->len
> ZIP_MAX_ZONE_LENGTH
) {
119 dPrintf(D_M_ZIP
, D_L_WARNING
,
120 ("zip_s_gni_r: zone len too long l=%d ddplen=%d\n",
121 zname
->len
, DDPLEN_VALUE(ddp
)));
127 ZoneNameProvided
= TRUE
;
129 GNIReply
[0] = ZIP_NETINFO_REPLY
;
130 GNIReply
[1] = ZIP_ZONENAME_INVALID
;
132 /* check if we are the originator is in the cable range for this interface */
134 if ((NET_VALUE(ddp
->src_net
) < CableStart
|| NET_VALUE(ddp
->src_net
) > CableStop
) &&
135 (NET_VALUE(ddp
->dst_net
) == 0 && ddp
->dst_node
== 0xff)) {
136 RequestIsBroadcasted
= TRUE
;
138 Entry
= rt_blookup(CableStop
);
140 if (Entry
!= NULL
&& RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
142 GNIReply
[2] = (Entry
->NetStart
& 0xFF00) >> 8;
143 GNIReply
[3] = (Entry
->NetStart
& 0x00FF);
144 GNIReply
[4] = (Entry
->NetStop
& 0xFF00) >> 8;
145 GNIReply
[5] = (Entry
->NetStop
& 0x00FF);
147 /* copy the zone name found in the request */
149 GNIReply
[6] = zname
->len
;
150 bcopy(&zname
->str
, &GNIReply
[7], zname
->len
);
153 if (znumber
= zt_find_zname(zname
)) {
155 if (ZT_ISIN_ZMAP((znumber
), Entry
->ZoneBitMap
)) {
157 GNIReply
[1] = 0; /* Zone Valid */
159 if (len
= zt_get_zmcast(ifID
, zname
, &GNIReply
[8+zname
->len
]))
160 GNIReply
[7+zname
->len
] = len
;
162 GNIReply
[1] |= ZIP_USE_BROADCAST
;
163 GNIReply
[7+zname
->len
] = 0; /* multicast address length */
165 packet_length
= 8 + zname
->len
+ len
;
171 else { /* should not happen, we are supposed to know our net */
172 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_s_gni_r: Don't know about our zone infos!!!\n"));
176 if (zt_ent_zcount(Entry
) == 1)
177 GNIReply
[1] |= ZIP_ONE_ZONE
;
179 if (GNIReply
[1] & ZIP_ZONENAME_INVALID
) {
181 short Index
= ifID
->ifDefZone
;
183 if (Index
<= 0 || Index
>= ZT_MAXEDOUT
) {
184 dPrintf(D_M_ZIP
, D_L_WARNING
,
185 ("zip_s_gni_r: Invalid starting index =%d port%d\n",
186 Index
, ifID
->ifPort
));
193 if (len
= zt_get_zmcast(ifID
, &ZT_table
[Index
].Zone
, &GNIReply
[8+zname
->len
]))
194 GNIReply
[7+zname
->len
] = len
;
196 GNIReply
[1] |= ZIP_USE_BROADCAST
;
197 GNIReply
[7+zname
->len
] = 0; /* multicast address length */
200 packet_length
= 7 + zname
->len
+ len
;
202 /* in the case the zone name asked for in the request was invalid, we need
203 * to copy the good default zone for this net
206 GNIReply
[packet_length
+ 1] = ZT_table
[Index
].Zone
.len
;
207 bcopy(&ZT_table
[Index
].Zone
.str
, &GNIReply
[packet_length
+ 2],
208 ZT_table
[Index
].Zone
.len
);
209 packet_length
= packet_length
+2 + ZT_table
[Index
].Zone
.len
;
214 * we're finally ready to send out the GetNetInfo Reply
219 size
= DDP_X_HDR_SIZE
+ packet_length
;
220 if ((m_sent
= gbuf_alloc(AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
221 return; /* was return(ENOBUFS); */
224 gbuf_rinc(m_sent
,AT_WR_OFFSET
);
225 gbuf_wset(m_sent
,size
);
226 ddp_sent
= (at_ddp_t
*)(gbuf_rptr(m_sent
));
228 /* Prepare the DDP header */
230 ddp_sent
->unused
= ddp_sent
->hopcount
= 0;
231 UAS_ASSIGN(ddp
->checksum
, 0);
232 DDPLEN_ASSIGN(ddp_sent
, size
);
233 NET_ASSIGN(ddp_sent
->src_net
, ifID
->ifThisNode
.s_net
);
234 ddp_sent
->src_node
= ifID
->ifThisNode
.s_node
;
235 ddp_sent
->src_socket
= ZIP_SOCKET
;
236 ddp_sent
->dst_socket
= ddp
->src_socket
;
238 if (RequestIsBroadcasted
) { /* if this was a broadcast, must respond from that */
240 NET_ASSIGN(ddp_sent
->dst_net
, 0);
241 ddp_sent
->dst_node
= 0xFF;
245 NET_NET(ddp_sent
->dst_net
, ddp
->src_net
);
246 ddp_sent
->dst_node
= ddp
->src_node
;
248 ddp_sent
->type
= DDP_ZIP
;
250 bcopy(&GNIReply
, &ddp_sent
->data
, packet_length
);
252 dPrintf(D_M_ZIP_LOW
, D_L_ROUTING
,
253 ("zip_s_gni_r: send to %d:%d port#%d pack_len=%d\n",
254 NET_VALUE(ddp_sent
->dst_net
), ddp_sent
->dst_node
,
255 ifID
->ifPort
, packet_length
));
257 ddp_router_output(m_sent
, ifID
, AT_ADDR
,
258 NET_VALUE(ddp_sent
->dst_net
), ddp_sent
->dst_node
, 0))) {
259 dPrintf(D_M_ZIP
, D_L_ERROR
,
260 ("zip_s_gni_r: ddp_router_output returns =%d\n", status
));
261 return; /* was return(status); */
263 } /* zip_send_getnetinfo_reply */
267 * build_ZIP_reply_packet: is used to create and send a DDP packet and use the
268 * provided buffer as a ZIP reply. This is used by zip_send_ext_reply_to_query
269 * and zip_send_reply_to_query for sending their replies to ZIP queries.
271 gbuf_t
*prep_ZIP_reply_packet(m
, ifID
)
272 register gbuf_t
*m
; /* this is the original zip query */
273 register at_ifaddr_t
*ifID
;
275 register gbuf_t
*m_sent
;
276 register at_ddp_t
*ddp
, *src_ddp
;
278 /* access the source Net and Node informations */
280 src_ddp
= (at_ddp_t
*)gbuf_rptr(m
);
282 if ((m_sent
= gbuf_alloc (AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
283 return((gbuf_t
*)NULL
);
285 gbuf_rinc(m_sent
,AT_WR_OFFSET
);
286 gbuf_wset(m_sent
,DDP_X_HDR_SIZE
);
287 ddp
= (at_ddp_t
*)(gbuf_rptr(m_sent
));
289 /* Prepare the DDP header */
291 ddp
->unused
= ddp
->hopcount
= 0;
292 UAS_ASSIGN(ddp
->checksum
, 0);
294 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
295 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
296 ddp
->src_socket
= ZIP_SOCKET
;
298 ddp
->dst_socket
= src_ddp
->src_socket
;
299 NET_NET(ddp
->dst_net
, src_ddp
->src_net
);
300 ddp
->dst_node
= src_ddp
->src_node
;
307 * zip_send_ext_reply_to_query: this function deals with ZIP Queries for extended nets.
308 * When we recognize an extended net (that might have several zone name associated with
309 * it), we send A SEPARATE ZIP reply for that network. This is called from the
310 * regular zip_send_reply_to_query, that just deals with non-ext nets.
313 static void zip_send_ext_reply_to_query(mreceived
, ifID
, Entry
, NetAsked
)
314 register gbuf_t
*mreceived
;
315 register at_ifaddr_t
*ifID
;
316 RT_entry
*Entry
; /* info about the network we're looking for */
320 register at_ddp_t
*ddp
;
321 short i
, j
, reply_length
, Index
, zone_count
, status
;
323 char *ReplyBuff
, *ZonesInPacket
;
325 zone_count
= zt_ent_zcount(Entry
);
326 zmap
= Entry
->ZoneBitMap
;
332 if (!(m
= prep_ZIP_reply_packet (mreceived
, ifID
))) {
333 return; /* was return(ENOBUFS); */
336 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
337 ReplyBuff
= (char *)(ddp
->data
);
340 *ReplyBuff
++ = 8; /* ZIP function = 8 [extended reply] */
342 ZonesInPacket
= ReplyBuff
;
345 reply_length
= 2; /* 1st byte is ZIP reply code, 2nd is network count */
348 /* For all zones, we check if they belong to the map for that Network */
350 for (; i
>= 0; i
--) {
352 /* find the zones defined in this entry bitmap */
356 if (zmap
[i
] << j
& 0x80) { /* bingo */
358 Index
= i
*8 + j
; /* zone index in zone table */
360 if (reply_length
+ 3 + ZT_table
[Index
].Zone
.len
> DDP_DATA_SIZE
) {
362 /* we need to send the packet before, this won't fit... */
364 zone_count
-= *ZonesInPacket
;
366 DDPLEN_ASSIGN(ddp
, reply_length
+ DDP_X_HDR_SIZE
);
367 gbuf_winc(m
,reply_length
);
369 ddp_router_output(m
, ifID
, AT_ADDR
,
370 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, 0))) {
371 dPrintf(D_M_ZIP
, D_L_ERROR
,
372 ("zip_s_ext_repl: ddp_router_output returns =%d\n",
374 return; /* was return (status); */
380 /* this should fit in this packet, build the NetNumber, ZoneLen,
384 if (ZT_table
[Index
].Zone
.len
) {
385 *ZonesInPacket
+= 1; /* bump NetCount field */
386 *ReplyBuff
++ = (NetAsked
& 0xFF00) >> 8;
387 *ReplyBuff
++ = (NetAsked
& 0x00FF) ;
388 *ReplyBuff
++ = ZT_table
[Index
].Zone
.len
;
390 bcopy(&ZT_table
[Index
].Zone
.str
, ReplyBuff
,
391 ZT_table
[Index
].Zone
.len
);
393 ReplyBuff
+= ZT_table
[Index
].Zone
.len
;
394 reply_length
+= ZT_table
[Index
].Zone
.len
+3;
399 j
= 0; /* reset the bit count */
402 /* if we have some zone info in a half-empty packet, send it now.
403 * Remember, for extended nets we send *at least* one Reply
407 DDPLEN_ASSIGN(ddp
, reply_length
+ DDP_X_HDR_SIZE
);
408 gbuf_winc(m
,reply_length
);
410 ddp_router_output(m
, ifID
, AT_ADDR
,
411 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, 0))) {
412 dPrintf(D_M_ZIP
, D_L_ERROR
,
413 ("zip_s_ext_reply: ddp_router_output returns =%d\n", status
));
414 return; /* was return (status); */
417 else /* free the buffer not used */
420 } /* zip_send_ext_reply_to_query */
423 * zip_send_reply_to_query: we received a ZIPQuery packet, we need to reply
424 * with the right information for the nets requested (if we have
425 * the right information.
427 static void zip_send_reply_to_query(mreceived
, ifID
)
428 register gbuf_t
*mreceived
;
429 register at_ifaddr_t
*ifID
;
432 register at_ddp_t
*ddp
, *ddp_received
;
434 short i
, reply_length
, Index
, status
;
435 u_char network_count
;
437 char *ReplyBuff
, *ZonesInPacket
;
439 ddp_received
= (at_ddp_t
*)gbuf_rptr(mreceived
);
441 /* access the number of nets requested in the Query */
442 network_count
= *((char *)(ddp_received
->data
) + 1);
443 NetAsked
= (u_short
*)(ddp_received
->data
+ 2);
445 /* check the validity of the Query packet */
447 if (DDPLEN_VALUE(ddp_received
) !=
448 (2 + network_count
* 2 + DDP_X_HDR_SIZE
)) {
450 dPrintf(D_M_ZIP
, D_L_WARNING
,
451 ("zip_s_reply_to_q: bad length netcount=%d len=%d\n",
452 network_count
, DDPLEN_VALUE(ddp
)));
453 return; /* was return(1); */
456 /* walk the Query Network list */
457 /* we want to build a response with the network number followed by the zone name
458 * length and the zone name. If there is more than one zone per network asked,
459 * we repeat the network number and stick the zone length and zone name.
460 * We need to be carefull with the max DDP size for data. If we see that a new
461 * NetNum, ZoneLen, ZoneName sequence won't fit, we send the previous packet and
462 * begin to build a new one.
467 if (!(m
= prep_ZIP_reply_packet (mreceived
, ifID
))) {
468 return; /* was return(ENOBUFS); */
471 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
472 ReplyBuff
= (char *)(ddp
->data
);
474 *ReplyBuff
++ = 2; /* ZIP function = 2 [Non extended reply] */
475 ZonesInPacket
= ReplyBuff
;
478 reply_length
= 2; /* 1st byte is ZIP reply code, 2nd is network count */
480 for (i
= 0 ; i
< network_count
; i
++, NetAsked
++) {
481 Entry
= rt_blookup(*NetAsked
);
483 if (Entry
!= NULL
&& ((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
484 RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
486 if (Entry
->NetStart
== 0) { /* asking for a NON EXTENDED network */
488 if ( (Index
= zt_ent_zindex(Entry
->ZoneBitMap
)) == 0)
493 if (reply_length
+ 3 + ZT_table
[Index
].Zone
.len
> DDP_DATA_SIZE
) {
495 /* we need to send the packet before, this won't fit... */
497 DDPLEN_ASSIGN(ddp
, reply_length
+ DDP_X_HDR_SIZE
);
498 gbuf_winc(m
,reply_length
);
501 ddp_router_output(m
, ifID
, AT_ADDR
,
502 NET_VALUE(ddp
->dst_net
),
503 ddp
->dst_node
, 0))) {
504 dPrintf(D_M_ZIP
, D_L_ERROR
,
505 ("zip_s_reply: ddp_router_output returns =%d\n",
507 return; /* was return (status); */
510 /* this is not nice, I know, but we reenter the loop with
511 * a packet is sent with the next network field in the Query
519 /* this should fit in this packet, build the NetNumber, ZoneLen,
523 if (ZT_table
[Index
].Zone
.len
) {
524 ZonesInPacket
+= 1; /* bump NetCount field */
525 *ReplyBuff
++ = (*NetAsked
& 0xFF00) >> 8;
526 *ReplyBuff
++ = (*NetAsked
& 0x00FF) ;
527 *ReplyBuff
++ = ZT_table
[Index
].Zone
.len
;
528 bcopy(&ZT_table
[Index
].Zone
.str
, ReplyBuff
,
529 ZT_table
[Index
].Zone
.len
);
531 ReplyBuff
+= ZT_table
[Index
].Zone
.len
;
533 reply_length
+= ZT_table
[Index
].Zone
.len
+ 3;
540 else { /* extended network, check for multiple zone name attached
541 * and build a separate packet for each extended network requested
544 zip_send_ext_reply_to_query(mreceived
, ifID
, Entry
, *NetAsked
);
550 /* If we have a non extended packet (code 2) with some stuff in it,
551 * we need to send it now
554 if ( reply_length
> 2) {
555 DDPLEN_ASSIGN(ddp
, reply_length
+ DDP_X_HDR_SIZE
);
556 gbuf_winc(m
,reply_length
);
558 ddp_router_output(m
, ifID
, AT_ADDR
,
559 NET_VALUE(ddp
->dst_net
),
560 ddp
->dst_node
, 0))) {
561 dPrintf(D_M_ZIP
, D_L_ERROR
,
562 ("zip_send_reply: ddp_router_output returns =%d\n", status
));
563 return; /* was return (status); */
566 else /* free the buffer not used */
568 } /* zip_send_reply_to_query */
570 /***********************************************************************
573 **********************************************************************/
575 void zip_router_input (m
, ifID
)
577 register at_ifaddr_t
*ifID
;
579 register at_ddp_t
*ddp
;
580 register at_atp_t
*atp
;
581 register at_zip_t
*zip
;
582 register u_long user_bytes
;
583 register u_short user_byte
;
585 /* variables for ZipNotify processing */
586 register char old_zone_len
;
587 register char new_zone_len
;
588 register char *old_zone
;
590 void zip_sched_getnetinfo(); /* forward reference */
592 if (gbuf_type(m
) != MSG_DATA
) {
593 /* If this is a M_ERROR message, DDP is shutting down,
594 * nothing to do here...If it's something else, we don't
595 * understand what it is
597 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_router_input: not an M_DATA message\n"));
603 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_router_input: BAD ifID\n"));
609 * The ZIP listener receives two types of requests:
611 * ATP requests: GetZoneList, GetLocalZone, or GetMyZone
612 * ZIP requests: Netinfo, Query, Reply, takedown, bringup
615 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
617 if (ddp
->type
== DDP_ZIP
) {
618 zip
= (at_zip_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
619 dPrintf(D_M_ZIP_LOW
, D_L_INPUT
,
620 ("zip_input: received a ZIP_DDP command=%d\n",
622 switch (zip
->command
) {
623 case ZIP_QUERY
: /* we received a Zip Query request */
624 dPrintf(D_M_ZIP
, D_L_INPUT
,
625 ("zip_input: Received a Zip Query in from %d.%d\n",
626 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
628 if (!RT_LOOKUP_OKAY(ifID
, ddp
)) {
629 dPrintf(D_M_ZIP
, D_L_INPUT
,
630 ("zip_input:: refused ZIP_QUERY from %d:%d\n",
631 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
634 zip_send_reply_to_query(m
, ifID
);
638 case ZIP_REPLY
: /* we received a Zip Query Reply packet */
639 case ZIP_EXTENDED_REPLY
:
640 if (ifID
->ifRoutingState
== PORT_OFFLINE
) {
641 dPrintf(D_M_ZIP
, D_L_INPUT
,
642 ("zip_input: Received a Zip Reply in user mode\n"));
645 zip_reply_received(m
, ifID
, zip
->command
);
650 /* we received a Zip Takedown packet */
651 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_input: Received a Zip takedown!!!\n"));
656 /* we received a Zip BringUp packet */
657 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_input: Received a Zip BringUp!!!\n"));
661 case ZIP_GETNETINFO
: /* we received a GetNetInfo request */
662 dPrintf(D_M_ZIP
, D_L_INPUT
,
663 ("zip_input: Received a GetNetInfo Req in from %d.%d\n",
664 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
665 if (RT_LOOKUP_OKAY(ifID
, ddp
)) {
666 dPrintf(D_M_ZIP
, D_L_OUTPUT
,
667 ("zip_input: we, as node %d:%d send GNI reply to %d:%d\n",
668 ifID
->ifThisNode
.s_net
, ifID
->ifThisNode
.s_node
,
669 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
670 zip_send_getnetinfo_reply(m
, ifID
);
676 case ZIP_NETINFO_REPLY
:
678 /* If we are not waiting for a GetNetInfo reply
679 * to arrive, this must be a broadcast
680 * message for someone else on the zone, so
681 * no need to even look at it!
684 ((NET_VALUE(ddp
->src_net
) != ifID
->ifThisNode
.s_net
) ||
685 (ddp
->src_node
!= ifID
->ifThisNode
.s_node
)) && netinfo_reply_pending
)
687 extern void trackrouter();
688 dPrintf(D_M_ZIP
, D_L_INPUT
,
689 ("zip_input: Received a GetNetInfo Reply from %d.%d\n",
690 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
691 trackrouter(ifID
, NET_VALUE(ddp
->src_net
), ddp
->src_node
);
692 zip_netinfo_reply((at_x_zip_t
*)zip
, ifID
);
699 /* processing of ZipNotify message : first, change
700 * our zone name, then if NIS is open, let NBP demon
701 process know of this change...(just forward the
704 /* First, check if this is really a packet for us */
705 old_zone
= &zip
->data
[4];
706 if (!zonename_equal(&ifID
->ifZoneName
,
707 (at_nvestr_t
*)old_zone
)) {
708 /* the old zone name in the packet is not the
709 * same as ours, so this packet couldn't be
716 old_zone_len
= *old_zone
;
717 new_zone_len
= zip
->data
[4 + old_zone_len
+ 1];
718 new_zone
= old_zone
+ old_zone_len
;
720 /* Reset the zone multicast address */
721 (void)at_unreg_mcast(ifID
, (caddr_t
)&ifID
->ZoneMcastAddr
);
722 bzero((caddr_t
)&ifID
->ZoneMcastAddr
, ETHERNET_ADDR_LEN
);
724 /* change the zone name - copy both the length and the string */
725 bcopy((caddr_t
)new_zone
, (caddr_t
)&ifID
->ifZoneName
,
728 /* Send network zone change event and new zone for this interface. */
729 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONEUPDATED
, 0, &(ifID
->ifZoneName
));
730 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONELISTCHANGED
, 0, 0);
732 /* add the new zone to the list of local zones */
733 if (!MULTIPORT_MODE
&& !DEFAULT_ZONE(&ifID
->ifZoneName
))
734 (void)setLocalZones(&ifID
->ifZoneName
,
735 (ifID
->ifZoneName
.len
+1));
737 /* Before trying to request our new multicast address,
738 * wait a while... someone might have alredy requested
739 * it, so we may see some broadcast messages flying
740 * by... Set up the structures so that it appears that
741 * we have already requested the NetInfo.
743 ifID
->ifNumRetries
= ZIP_NETINFO_RETRIES
;
744 netinfo_reply_pending
= 1;
745 timeout(zip_sched_getnetinfo
, (caddr_t
) ifID
,
751 routing_needed(m
, ifID
, TRUE
);
755 else if (ddp
->type
== DDP_ATP
&&
756 RT_LOOKUP_OKAY(ifID
, ddp
)) {
757 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
758 atp
= (at_atp_t
*)(gbuf_rptr(m
)+DDP_X_HDR_SIZE
);
760 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
762 /* Get the user bytes in network order */
764 user_bytes
= UAL_VALUE(atp
->user_bytes
);
765 user_byte
= user_bytes
>> 24; /* Get the zeroth byte */
767 dPrintf(D_M_ZIP
, D_L_INPUT
,
768 ("zip_input: received a ZIP_ATP command=%d\n", user_byte
));
772 zip_reply_to_getmyzone(ifID
, m
);
776 case ZIP_GETZONELIST
:
777 zip_reply_to_getzonelist(ifID
, m
);
781 case ZIP_GETLOCALZONES
:
782 zip_reply_to_getlocalzones(ifID
, m
);
787 dPrintf(D_M_ZIP
, D_L_WARNING
,
788 ("zip_input: received unknown ZIP_ATP command=%d\n", user_byte
));
789 routing_needed(m
, ifID
, TRUE
);
796 } /* zip_router_input */
798 /***********************************************************************
803 **********************************************************************/
804 int zonename_equal (zone1
, zone2
)
805 register at_nvestr_t
*zone1
, *zone2
;
807 register char c1
, c2
;
811 if (zone1
->len
!= zone2
->len
)
814 for (i
=0; i
< (int) zone1
->len
; i
++) {
817 if (c1
>= 'a' && c1
<= 'z')
819 if (c2
>= 'a' && c2
<= 'z')
837 static unsigned char lower_case
[] =
838 {0x8a, 0x8c, 0x8d, 0x8e, 0x96, 0x9a, 0x9f, 0xbe,
839 0xbf, 0xcf, 0x9b, 0x8b, 0x88, 0};
840 static unsigned char upper_case
[] =
841 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0xae,
842 0xaf, 0xce, 0xcd, 0xcc, 0xcb, 0};
844 for (i
=0; lower_case
[i
]; i
++)
845 if (ch
== lower_case
[i
])
846 return (upper_case
[i
]);
852 /***********************************************************************
853 * zip_netinfo_reply ()
857 **********************************************************************/
858 static void zip_netinfo_reply (netinfo
, ifID
)
859 register at_x_zip_t
*netinfo
;
860 register at_ifaddr_t
*ifID
;
863 void zip_sched_getnetinfo(); /* forward reference */
864 register at_net_al this_net
;
866 register u_char zone_name_len
;
868 /* There may be multiple zones on the cable.... we need to
869 * worry about whether or not this packet is addressed
872 /* *** Do we really need to check this? *** */
873 if (!zonename_equal((at_nvestr_t
*)netinfo
->data
, &ifID
->ifZoneName
)) {
874 dPrintf(D_M_ZIP
, D_L_INFO
, ("zip_netinfo_reply, !zonename_equal!!!"));
878 ifID
->ifThisCableStart
= NET_VALUE(netinfo
->cable_range_start
);
879 ifID
->ifThisCableEnd
= NET_VALUE(netinfo
->cable_range_end
);
880 dPrintf(D_M_ZIP
, D_L_OUTPUT
, ("Zip_netinfo_reply: Set cable to %d-%d\n",
881 ifID
->ifThisCableStart
, ifID
->ifThisCableEnd
));
883 /* The packet is in response to our request */
884 untimeout (zip_sched_getnetinfo
, (caddr_t
) ifID
);
885 netinfo_reply_pending
= 0;
886 zone_name_len
= netinfo
->data
[0];
887 mcast_len
= netinfo
->data
[zone_name_len
+ 1];
889 if (netinfo
->flags
& ZIP_ZONENAME_INVALID
) {
890 /* copy out the default zone name from packet */
891 default_zone
= (char *)&netinfo
->data
[zone_name_len
+1+mcast_len
+1];
892 bcopy((caddr_t
)default_zone
, (caddr_t
)&ifID
->ifZoneName
,
896 /* add the new zone to the list of local zones */
897 if (!MULTIPORT_MODE
&& !DEFAULT_ZONE(&ifID
->ifZoneName
))
898 (void)setLocalZones(&ifID
->ifZoneName
, (ifID
->ifZoneName
.len
+1));
900 /* get the multicast address out of the GetNetInfo reply, if there is one */
901 if (!(netinfo
->flags
& ZIP_USE_BROADCAST
)) {
902 /* If ZIP_USE_BROADCAST is set, we will use the cable
903 broadcast address as the multicast address, however
904 the cable multicast address has already been registered.
906 /* This packet contains a multicast address, so
907 * send to elap to register it.
909 if (FDDI_OR_TOKENRING(ifID
->aa_ifp
->if_type
))
910 ddp_bit_reverse(&netinfo
->data
[zone_name_len
+ 2]);
912 bcopy((caddr_t
)&netinfo
->data
[zone_name_len
+ 2],
913 (caddr_t
)&ifID
->ZoneMcastAddr
, ETHERNET_ADDR_LEN
);
914 (void)at_reg_mcast(ifID
, (caddr_t
)&ifID
->ZoneMcastAddr
);
917 this_net
= ifID
->ifThisNode
.s_net
;
918 if ((this_net
>= ifID
->ifThisCableStart
) &&
919 (this_net
<= ifID
->ifThisCableEnd
)) {
920 /* ThisNet is in the range of valid network numbers
921 * for the cable. Do nothing.
924 /* ThisNet is not in the range of valid network
925 * numbers for the cable. This may be either because
926 * the chosen number was from start-up range, or
927 * because the user has a misconception of where the
928 * machine is!! Since ThisCableRange is set up, next
929 * time aarp is invoked, it would select address in
933 /* to reset initial_net and initial_node to zero, so
934 * that aarp is forced to choose new values
936 ifID
->initial_addr
.s_net
= 0;
937 ifID
->initial_addr
.s_node
= 0;
939 /* Wake up elap_online sleeping on this interface. */
940 ZIPwakeup(ifID
, ZIP_RE_AARP
);
944 if (!ifID
->startup_inprogress
) {
945 /* Send event with zone info. This covers case where we get zone info
946 after startup. During startup this event is sent from ZIPwakeup. */
947 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONEUPDATED
, 0, &(ifID
->ifZoneName
));
950 ZIPwakeup(ifID
, 0); /* no error */
952 } /* zip_netinfo_reply */
955 /**********************************************************************
958 **********************************************************************/
959 int zip_control (ifID
, control
)
960 register at_ifaddr_t
*ifID
;
963 dPrintf(D_M_ZIP
, D_L_INFO
, ("zip_control called port=%d control=%d\n",
964 ifID
->ifPort
, control
));
967 case ZIP_LATE_ROUTER
:
968 ifID
->ifNumRetries
= 0;
969 /* Get the desired zone name from elap and put it in
970 * ifID for zip_getnetinfo() to use.
972 if (ifID
->startup_zone
.len
)
973 ifID
->ifZoneName
= ifID
->startup_zone
;
974 zip_getnetinfo(ifID
);
977 ifID
->ifZoneName
.len
= 1;
978 ifID
->ifZoneName
.str
[0] = '*';
979 ifID
->ifZoneName
.str
[1] = '\0';
981 /* Send event with zone info. */
982 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONEUPDATED
, 0, &(ifID
->ifZoneName
));
991 /* funnel version of zip_getnetinfo */
992 static void zip_getnetinfo_funnel(ifID
)
993 register at_ifaddr_t
*ifID
;
995 thread_funnel_set(network_flock
, TRUE
);
996 zip_getnetinfo(ifID
);
997 thread_funnel_set(network_flock
, FALSE
);
1001 /**********************************************************************
1004 **********************************************************************/
1005 static void zip_getnetinfo (ifID
)
1006 register at_ifaddr_t
*ifID
;
1008 register at_x_zip_t
*zip
;
1010 register at_ddp_t
*ddp
;
1011 void zip_sched_getnetinfo();
1012 register struct atalk_addr
*at_dest
;
1015 size
= DDP_X_HDR_SIZE
+ ZIP_X_HDR_SIZE
+ ifID
->ifZoneName
.len
+ 1
1016 + sizeof(struct atalk_addr
) + 1;
1017 if ((m
= gbuf_alloc (AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
1018 /* This time, we're unable to allocate buffer to
1019 * send a packet out, so schedule to send a packet
1020 * out later, and exit.
1022 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_getnetinfo: no buffer, call later port=%d\n",
1024 timeout (zip_getnetinfo_funnel
, (caddr_t
) ifID
, ZIP_TIMER_INT
/10);
1028 gbuf_rinc(m
,AT_WR_OFFSET
);
1030 *(u_char
*)gbuf_rptr(m
) = AT_ADDR
;
1031 at_dest
= (struct atalk_addr
*)(gbuf_rptr(m
) + 1);
1032 ddp
= (at_ddp_t
*)(gbuf_rptr(m
) + sizeof(struct atalk_addr
) + 1);
1033 zip
= (at_x_zip_t
*)ddp
->data
;
1036 zip
->command
= ZIP_GETNETINFO
;
1038 NET_ASSIGN(zip
->cable_range_start
, 0);
1039 NET_ASSIGN(zip
->cable_range_end
, 0);
1040 if (ifID
->ifZoneName
.len
) /* has to match reply exactly */
1041 bcopy((caddr_t
)&ifID
->ifZoneName
, (caddr_t
)zip
->data
,
1042 ifID
->ifZoneName
.len
+ 1);
1044 zip
->data
[0] = 0; /* No zone name is availbale */
1046 /* let the lap fields be uninitialized, 'cause it doesn't
1049 DDPLEN_ASSIGN(ddp
, size
- (sizeof(struct atalk_addr
) + 1));
1050 UAS_ASSIGN(ddp
->checksum
, 0);
1051 ddp
->hopcount
= ddp
->unused
= 0;
1052 NET_ASSIGN(ddp
->dst_net
, 0); /* cable-wide broadcast */
1053 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1054 /* By this time, AARP is done */
1056 ddp
->dst_node
= 0xff;
1057 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1058 ddp
->dst_socket
= ZIP_SOCKET
;
1059 ddp
->src_socket
= ZIP_SOCKET
;
1060 ddp
->type
= DDP_ZIP
;
1062 at_dest
->atalk_unused
= 0;
1063 NET_NET(at_dest
->atalk_net
, ddp
->dst_net
);
1064 at_dest
->atalk_node
= ddp
->dst_node
;
1066 dPrintf(D_M_ZIP
, D_L_INPUT
, ("zip_getnetinfo: called for port=%d\n",
1069 if (elap_dataput(m
, ifID
, 0, NULL
)) {
1070 dPrintf(D_M_ZIP
, D_L_ERROR
,
1071 ("zip_getnetinfo: error sending zip_getnetinfo\n"));
1075 ifID
->ifNumRetries
++;
1076 netinfo_reply_pending
= 1;
1078 timeout (zip_sched_getnetinfo
, (caddr_t
) ifID
, ZIP_TIMER_INT
);
1079 } /* zip_getnetinfo */
1082 /**********************************************************************
1083 * zip_sched_getnetinfo()
1085 **********************************************************************/
1087 void zip_sched_getnetinfo (ifID
)
1088 register at_ifaddr_t
*ifID
;
1090 boolean_t funnel_state
;
1092 funnel_state
= thread_funnel_set(network_flock
, TRUE
);
1094 if (ifID
->ifNumRetries
>= ZIP_NETINFO_RETRIES
) {
1095 /* enough packets sent.... give up! */
1096 /* we didn't get any response from the net, so
1097 * assume there's no router around and the given
1098 * zone name, if any, is not valid. Change the
1101 ifID
->ifZoneName
.len
= 1;
1102 ifID
->ifZoneName
.str
[0] = '*';
1103 ifID
->ifZoneName
.str
[1] = '\0';
1104 /* Should NBP be notified of this "new" zone name?? */
1105 netinfo_reply_pending
= 0;
1107 ifID
->ifRouterState
= NO_ROUTER
;
1108 ifID
->ifARouter
.s_net
= 0;
1109 ifID
->ifARouter
.s_node
= 0;
1111 dPrintf(D_M_ZIP
, D_L_INFO
, ("zip_sched_getnetinfo: Reset Cable Range\n"));
1113 ifID
->ifThisCableStart
= DDP_MIN_NETWORK
;
1114 ifID
->ifThisCableEnd
= DDP_MAX_NETWORK
;
1116 if (ifID
->ifState
== LAP_ONLINE_FOR_ZIP
)
1117 ZIPwakeup (ifID
, 0); /* no error */
1119 zip_getnetinfo(ifID
);
1121 (void) thread_funnel_set(network_flock
, FALSE
);
1125 /**********************************************************************
1129 * This routine checks whether or not the packet contained in "m"
1130 * is an (outgoing) ZIP packet. If not, it returns 0. If it is a
1131 * ZIP packet, it returns the ZIP packet type (ZIP command). "m"
1132 * points to a packet with extended DDP header. The rest of the
1133 * DDP data may or may not be in the first gbuf.
1135 **********************************************************************/
1136 int zip_type_packet (m
)
1139 register at_atp_t
*atp
;
1140 register at_ddp_t
*ddp
;
1141 register at_zip_t
*zip
;
1142 register u_long user_bytes
;
1143 register int user_byte
;
1145 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1146 if (ddp
->dst_socket
== ZIP_SOCKET
) {
1147 switch (ddp
->type
) {
1149 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1150 zip
= (at_zip_t
*)(gbuf_rptr(m
)
1153 zip
=(at_zip_t
*)(gbuf_rptr(gbuf_cont(m
)));
1154 return ((int)zip
->command
);
1156 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1157 atp
= (at_atp_t
*)(gbuf_rptr(m
)+DDP_X_HDR_SIZE
);
1159 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1160 /* Get the user bytes in network order */
1161 user_bytes
= UAL_VALUE(atp
->user_bytes
);
1162 user_byte
= user_bytes
>> 24; /* Get the zeroth byte */
1163 if ((user_byte
== ZIP_GETMYZONE
) ||
1164 (user_byte
== ZIP_GETZONELIST
) ||
1165 (user_byte
== ZIP_GETLOCALZONES
))
1176 /**********************************************************************
1177 * zip_handle_getmyzone()
1180 * Routine to handle ZIP GetMyZone request locally. It generates
1181 * a phony response to the outgoing ATP request and sends it up.
1183 * 07/12/94 : remark2 only called from ddp.c / ddp_output
1184 * should only be called from the home port, but
1185 * when we are a router we should know the infos for all
1186 * anyway, so reply locally with what we have in stock...
1188 **********************************************************************/
1190 int zip_handle_getmyzone(ifID
, m
)
1191 register at_ifaddr_t
*ifID
;
1195 register at_ddp_t
*ddp
;
1196 register at_ddp_t
*r_ddp
;
1197 register at_atp_t
*r_atp
;
1198 gbuf_t
*rm
; /* reply message */
1202 dPrintf(D_M_ZIP
, D_L_INFO
,
1203 ("zip_handle_getmyzone: local reply for port=%d\n",
1206 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ 1 + ifID
->ifZoneName
.len
;
1207 /* space for two headers and the zone name */
1208 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
1209 dPrintf(D_M_ZIP
, D_L_WARNING
,
1210 ("zip_handle_getmyzone: no buffer, port=%d\n",
1215 gbuf_rinc(rm
,AT_WR_OFFSET
);
1217 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1218 r_atp
= (at_atp_t
*)r_ddp
->data
;
1221 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1222 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1223 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1225 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1227 /* fill up the ddp header for reply */
1228 DDPLEN_ASSIGN(r_ddp
, size
);
1229 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1230 UAS_ASSIGN(r_ddp
->checksum
, 0);
1231 NET_ASSIGN(r_ddp
->dst_net
, ifID
->ifThisNode
.s_net
);
1232 NET_NET(r_ddp
->src_net
, ddp
->dst_net
);
1233 r_ddp
->dst_node
= ifID
->ifThisNode
.s_node
;
1234 r_ddp
->src_node
= ddp
->dst_node
;
1235 r_ddp
->dst_socket
= ddp
->src_socket
;
1236 r_ddp
->src_socket
= ZIP_SOCKET
;
1237 r_ddp
->type
= DDP_ATP
;
1239 /* fill up the atp header */
1240 r_atp
->cmd
= ATP_CMD_TRESP
;
1246 UAS_UAS(r_atp
->tid
, atp
->tid
);
1248 ulongtmp
= htonl(ulongtmp
);
1249 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
); /* no of zones */
1251 /* fill up atp data part */
1252 bcopy((caddr_t
) &ifID
->ifZoneName
, (caddr_t
) r_atp
->data
, ifID
->ifZoneName
.len
+1);
1254 /* all set to send the packet back up */
1256 timeout(send_phony_reply
, (caddr_t
) rm
, HZ
/20);
1261 send_phony_reply(rm
)
1264 boolean_t funnel_state
;
1266 funnel_state
= thread_funnel_set(network_flock
, TRUE
);
1268 ddp_input(rm
, ifID_home
);
1270 (void) thread_funnel_set(network_flock
, FALSE
);
1276 * zip_prep_query_packet: build the actual ddp packet for the zip query
1279 gbuf_t
*zip_prep_query_packet(ifID
, RouterNet
, RouterNode
)
1281 at_net_al RouterNet
; /* we want to send the Zip Query to that router */
1286 register at_ddp_t
*ddp
;
1288 if ((m
= gbuf_alloc (AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
1289 dPrintf(D_M_ZIP
, D_L_WARNING
,
1290 ("zip_send_query_packet: no buffer, port=%d\n",
1292 return((gbuf_t
*)NULL
);
1294 gbuf_rinc(m
,AT_WR_OFFSET
);
1297 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
1299 /* Prepare the DDP header */
1301 ddp
->unused
= ddp
->hopcount
= 0;
1302 UAS_ASSIGN(ddp
->checksum
, 0);
1303 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1304 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1305 ddp
->src_socket
= ZIP_SOCKET
;
1307 ddp
->dst_socket
= ZIP_SOCKET
;
1308 NET_ASSIGN(ddp
->dst_net
, RouterNet
);
1309 ddp
->dst_node
= RouterNode
;
1311 ddp
->type
= DDP_ZIP
;
1314 } /* zip_prep_query_packet */
1318 * zip_send_queries: this function send queries for the routing table entries that
1319 * need to know their zones. It scans the routing table for entries with unknown
1320 * zones and build Query packets accordingly.
1321 * Note: this is called on a per port basis.
1324 void zip_send_queries(ifID
, RouterNet
, RouterNode
)
1325 register at_ifaddr_t
*ifID
;
1326 at_net_al RouterNet
; /* we want to send the Zip Query to that router */
1329 RT_entry
*Entry
= &RT_table
[0];
1331 register at_ddp_t
*ddp
;
1333 short Query_index
, EntryNumber
= 0 ;
1334 register u_char port
= ifID
->ifPort
;
1335 char *QueryBuff
, *ZoneCount
;
1336 short zip_sent
= FALSE
;
1340 if (!(m
= zip_prep_query_packet(ifID
, RouterNet
, RouterNode
))) {
1341 return; /* was return (ENOBUFS); */
1344 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
1345 QueryBuff
= (char *)ddp
->data
;
1347 *QueryBuff
++ = ZIP_QUERY
;
1348 ZoneCount
= QueryBuff
; /* network count */
1354 while (EntryNumber
< RT_maxentry
) {
1356 /* scan the table, and build the packet with the right entries:
1357 * - entry in use and on the right Port
1358 * - with unknwon zones and in an active state
1359 * - talking to the right router
1362 if ((Query_index
) > 2*254 +2) {
1364 /* we need to send the packet now, but we can't have more than 256
1365 * requests for networks: the Netcount field is a 8bit in the zip query
1366 * packet format as defined in Inside Atalk
1369 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1370 ("zip_send_query: FULL query for %d nets on port#%d.(len=%d)\n",
1371 *ZoneCount
, port
, Query_index
));
1374 gbuf_winc(m
,DDP_X_HDR_SIZE
+ Query_index
);
1375 DDPLEN_ASSIGN(ddp
, DDP_X_HDR_SIZE
+ Query_index
);
1378 ddp_router_output(m
, ifID
, AT_ADDR
,
1379 RouterNet
, RouterNode
, 0))) {
1380 dPrintf(D_M_ZIP
, D_L_ERROR
,
1381 ("zip_send_query: ddp_router_output returns =%d\n", status
));
1382 return; /* was return (status); */
1389 if (((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
1390 (Entry
->NetStop
) && (Entry
->NetPort
== port
) &&
1391 (!RT_ALL_ZONES_KNOWN(Entry
))){
1393 /* we're ready to had that to our list of stuff to send */
1395 if (Entry
->NetStart
) { /* extended net*/
1397 *QueryBuff
++ = (Entry
->NetStart
& 0xFF00) >> 8;
1398 *QueryBuff
++ = (Entry
->NetStart
& 0x00FF);
1402 *QueryBuff
++ = (Entry
->NetStop
& 0xFF00) >> 8;
1403 *QueryBuff
++ = (Entry
->NetStop
& 0x00FF);
1407 *ZoneCount
+= 1;/* bump the number of network requested */
1416 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1417 ("zip_send_query: query for %d nets on port#%d.(len=%d)\n",
1418 *ZoneCount
, port
, Query_index
));
1420 if (*ZoneCount
) { /* non-full Query needs to be sent */
1422 gbuf_winc(m
,DDP_X_HDR_SIZE
+ Query_index
);
1423 DDPLEN_ASSIGN(ddp
, DDP_X_HDR_SIZE
+ Query_index
);
1426 ddp_router_output(m
, ifID
, AT_ADDR
,
1427 RouterNet
, RouterNode
, 0))) {
1428 dPrintf(D_M_ZIP
, D_L_ERROR
,
1429 ("zip_send_query: ddp_router_output returns =%d\n",
1431 return; /* was return (status); */
1437 if (!zip_sent
) /* we didn't need to send anything for that port */
1438 ifID
->ifZipNeedQueries
= 0;
1439 } /* zip_send_queries */
1441 /* zip_reply_received: we recieved the reply to one of our query, update the
1442 * zone bitmap and stuffs with was we received.
1443 * we receive two types of replies: non extended and extended.
1444 * For extended replies, the network count is the Total of zones for that net.
1447 zip_reply_received(m
, ifID
, reply_type
)
1449 register at_ifaddr_t
*ifID
;
1452 register at_nvestr_t
*zname
;
1453 RT_entry
*Entry
= &RT_table
[0];
1454 register at_ddp_t
*ddp
;
1456 u_short payload_len
, result
;
1457 u_char network_count
;
1460 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1462 /* access the number of nets provided in the ZIP Reply */
1464 network_count
= *(u_char
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
+ 1);
1466 PacketPtr
= (char *)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
+ 2);
1468 payload_len
= DDPLEN_VALUE(ddp
) - (DDP_X_HDR_SIZE
+ 2);
1470 dPrintf(D_M_ZIP_LOW
, D_L_INPUT
, ("zip_reply_received from %d:%d type=%d netcount=%d\n",
1471 NET_VALUE(ddp
->src_net
), ddp
->src_node
, reply_type
, network_count
));
1474 while (payload_len
> 0 && network_count
>0) {
1476 Network
= *(at_net_al
*)PacketPtr
;
1478 zname
= (at_nvestr_t
*)PacketPtr
;
1480 payload_len
= payload_len
-(zname
->len
+ 3);
1482 if (zname
->len
<= 0) { /* not valid, we got a problem here... */
1483 dPrintf(D_M_ZIP
, D_L_WARNING
,
1484 ("zip_reply_received: Problem zlen=0 for net=%d from %d:%d type=%d netcnt=%d\n",
1485 Network
, NET_VALUE(ddp
->src_net
), ddp
->src_node
, reply_type
, network_count
));
1491 Entry
= rt_blookup(Network
);
1493 if (Entry
!= NULL
) {
1495 if (Entry
->EntryState
>= RTE_STATE_SUSPECT
) {
1497 result
= zt_add_zonename(zname
);
1499 if (result
== ZT_MAXEDOUT
) {
1501 dPrintf(D_M_ZIP
, D_L_ERROR
,
1502 ("zip_reply_received: ZTable full from %d:%d on zone '%s'\n",
1503 NET_VALUE(ddp
->src_net
), ddp
->src_node
, zname
->str
));
1504 ErrorZIPoverflow
= 1;
1508 zt_set_zmap(result
, Entry
->ZoneBitMap
);
1510 RT_SET_ZONE_KNOWN(Entry
);
1514 dPrintf(D_M_ZIP
, D_L_INPUT
,
1515 ("zip_reply_received: entry %d-%d not updated, cause state=%d\n",
1516 Entry
->NetStart
, Entry
->NetStop
, Entry
->EntryState
));
1520 dPrintf(D_M_ZIP
, D_L_WARNING
,
1521 ("zip_reply_received: network %d not found in RT\n", Network
));
1525 /* now bump the PacketPtr pointer */
1526 PacketPtr
+= zname
->len
+ 1;
1530 if ((reply_type
== ZIP_REPLY
) && network_count
> 0) {
1532 dPrintf(D_M_ZIP
, D_L_WARNING
,
1533 ("zip_reply_received: Problem decoding zone (after net:%d-%d)\n",
1534 Entry
->NetStart
, Entry
->NetStop
));
1535 ifID
->ifZipNeedQueries
= 1;
1538 ifID
->ifZipNeedQueries
= 0;
1540 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1541 ("zip_reply_received: entry %d-%d all zones known\n",
1542 Entry
->NetStart
, Entry
->NetStop
));
1547 * zip_reply_to_getmyzone: replies to ZIP GetMyZone received from the Net
1550 static void zip_reply_to_getmyzone (ifID
, m
)
1551 register at_ifaddr_t
*ifID
;
1555 register at_ddp_t
*ddp
;
1556 register at_ddp_t
*r_ddp
;
1557 register at_atp_t
*r_atp
;
1558 register gbuf_t
*rm
; /* reply message */
1559 register int size
, Index
, status
;
1564 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ 1 + ifID
->ifZoneName
.len
;
1565 /* space for two headers and the zone name */
1566 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
1567 dPrintf(D_M_ZIP
, D_L_WARNING
,
1568 ("zip_reply_to_getmyzone: no buffer, port=%d\n", ifID
->ifPort
));
1569 return; /* was return (ENOBUFS); */
1571 gbuf_rinc(rm
,AT_WR_OFFSET
);
1573 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1574 r_atp
= (at_atp_t
*)r_ddp
->data
;
1576 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1577 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1578 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1580 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1582 /* fill up the ddp header for reply */
1583 DDPLEN_ASSIGN(r_ddp
, size
);
1584 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1585 UAS_ASSIGN(r_ddp
->checksum
, 0);
1587 NET_ASSIGN(r_ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1588 NET_NET(r_ddp
->dst_net
, ddp
->src_net
);
1590 r_ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1591 r_ddp
->dst_node
= ddp
->src_node
;
1593 r_ddp
->dst_socket
= ddp
->src_socket
;
1594 r_ddp
->src_socket
= ZIP_SOCKET
;
1595 r_ddp
->type
= DDP_ATP
;
1597 /* fill up the atp header */
1598 r_atp
->cmd
= ATP_CMD_TRESP
;
1604 UAS_UAS(r_atp
->tid
, atp
->tid
);
1606 ulongtmp
= htonl(ulongtmp
);
1607 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
); /* no of zones */
1609 data_ptr
= (char *)r_atp
->data
;
1612 * fill up atp data part with the zone name if we can find it...
1615 Entry
= rt_blookup(NET_VALUE(ddp
->src_net
));
1616 if (Entry
!= NULL
&& ((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
1617 RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
1619 Index
= zt_ent_zindex(Entry
->ZoneBitMap
) -1;
1621 *data_ptr
= ZT_table
[Index
].Zone
.len
;
1622 bcopy((caddr_t
) &ZT_table
[Index
].Zone
.str
, (caddr_t
) ++data_ptr
,
1623 ZT_table
[Index
].Zone
.len
);
1625 /* all set to send the packet back up */
1626 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1627 ("zip_reply_to_GMZ: ddp_router_output to %d:%d port %d\n",
1628 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, ifID
->ifPort
));
1631 ddp_router_output(rm
, ifID
, AT_ADDR
,
1632 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, 0))) {
1633 dPrintf(D_M_ZIP
, D_L_ERROR
,
1634 ("zip_reply_to_GMZ: ddp_r_output returns =%d\n", status
));
1635 return; /* was return (status); */
1643 * zip_reply_to_getzonelist: replies to ZIP GetZoneList requested from the Net
1646 zip_reply_to_getzonelist (ifID
, m
)
1647 register at_ifaddr_t
*ifID
;
1651 register at_ddp_t
*ddp
;
1652 register at_ddp_t
*r_ddp
;
1653 register at_atp_t
*r_atp
;
1654 register gbuf_t
*rm
; /* reply message */
1655 register int size
, status
;
1656 register short Index
=0, StartPoint
, ZLength
, PacketLen
=0;
1660 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1661 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1662 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1664 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1667 /* space for two headers and the zone name */
1669 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
1673 gbuf_rinc(rm
,AT_WR_OFFSET
);
1675 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1676 r_atp
= (at_atp_t
*)r_ddp
->data
;
1678 /* fill up the ddp header for reply */
1680 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1681 UAS_ASSIGN(r_ddp
->checksum
, 0);
1682 NET_ASSIGN(r_ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1683 NET_NET(r_ddp
->dst_net
, ddp
->src_net
);
1684 r_ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1685 r_ddp
->dst_node
= ddp
->src_node
;
1686 r_ddp
->dst_socket
= ddp
->src_socket
;
1687 r_ddp
->src_socket
= ZIP_SOCKET
;
1688 r_ddp
->type
= DDP_ATP
;
1690 /* fill up the atp header */
1692 r_atp
->cmd
= ATP_CMD_TRESP
;
1698 UAS_UAS(r_atp
->tid
, atp
->tid
);
1700 Reply
= (char *)r_atp
->data
;
1702 /* get the start index from the ATP request */
1704 StartPoint
= (UAL_VALUE(atp
->user_bytes
) & 0xffff) -1;
1706 /* find the next zone to send */
1708 while ((Index
< ZT_maxentry
) && StartPoint
> 0) {
1709 if (ZT_table
[Index
].Zone
.len
)
1715 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
, ("zip_reply_to_GZL: Index=%d\n", Index
));
1717 * fill up atp data part with the zone name if we can find it...
1720 while (Index
< ZT_maxentry
) {
1722 ZLength
= ZT_table
[Index
].Zone
.len
;
1724 if (ZT_table
[Index
].ZoneCount
&& ZLength
) {
1727 if (PacketLen
+ 8 + ZLength
+1 > DDP_DATA_SIZE
) /* packet full */
1731 bcopy((caddr_t
) &ZT_table
[Index
].Zone
.str
,
1734 PacketLen
+= ZLength
+ 1;
1740 if (Index
>= ZT_maxentry
) /* this is the end of the list */
1742 ulongtmp
+= 0x01000000;
1745 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
); /* # of zones and flag*/
1747 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ PacketLen
;
1749 DDPLEN_ASSIGN(r_ddp
, size
);
1751 /* all set to send the packet back up */
1753 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1754 ("zip_r_GZL: send packet to %d:%d port %d atp_len =%d\n",
1755 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, ifID
->ifPort
, PacketLen
));
1758 if (status
= ddp_router_output(rm
, ifID
, AT_ADDR
,
1759 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, 0)) {
1760 dPrintf(D_M_ZIP
, D_L_ERROR
, ("zip_reply_to_GZL: ddp_router_output returns=%d\n",
1769 * zip_reply_to_getlocalzones: replies to ZIP GetLocalZones requested from the Net
1772 int zip_reply_to_getlocalzones (ifID
, m
)
1773 register at_ifaddr_t
*ifID
;
1777 register at_ddp_t
*ddp
;
1778 register at_ddp_t
*r_ddp
;
1779 register at_atp_t
*r_atp
;
1780 register gbuf_t
*rm
; /* reply message */
1782 short Index
, Index_wanted
, ZLength
;
1783 short i
,j
, packet_len
;
1784 short zCount
, ZoneCount
, ZonesInPacket
;
1785 char *zmap
, last_flag
= 0;
1789 u_long ulongtmp
= 0;
1791 Index
= Index_wanted
= ZLength
= i
= j
= packet_len
= zCount
= ZoneCount
=
1794 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1795 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1796 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1798 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1800 /* space for two headers and the zone name */
1802 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
1806 gbuf_rinc(rm
,AT_WR_OFFSET
);
1808 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1809 r_atp
= (at_atp_t
*)r_ddp
->data
;
1811 Reply
= (char *)r_atp
->data
;
1814 /* get the start index from the ATP request */
1816 Index_wanted
= (UAL_VALUE(atp
->user_bytes
) & 0xffff) -1;
1818 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1819 ("zip_r_GLZ: for station %d:%d Index_wanted = %d\n",
1820 NET_VALUE(ddp
->src_net
), ddp
->src_node
, Index_wanted
));
1822 Entry
= rt_blookup(NET_VALUE(ddp
->src_net
));
1824 if (Entry
!= NULL
&& ((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
1825 RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
1827 ZoneCount
= zt_ent_zcount(Entry
) ;
1829 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1830 ("zip_reply_GLZ: for %d:%d ZoneCount=%d\n",
1831 NET_VALUE(ddp
->src_net
), ddp
->src_node
, ZoneCount
));
1833 zmap
= &Entry
->ZoneBitMap
[0];
1836 * first of all, we want to find the "first next zone" in the bitmap,
1837 * to do so, we need to scan the bitmap and add the number of valid
1838 * zones we find until we reach the next zone to be sent in the reply
1841 if (ZoneCount
> Index_wanted
) {
1843 ZoneCount
-= Index_wanted
;
1845 /* find the starting point in the bitmap according to index */
1847 for (i
= 0; Index_wanted
>= 0 && i
< ZT_BYTES
; i
++)
1849 if (Index_wanted
< 8) {
1850 /* how many zones in the bitmap byte */
1851 for (j
= 0, zCount
=0; j
< 8 ; j
++)
1852 if ((zmap
[i
] << j
) & 0x80)
1854 if (Index_wanted
< zCount
) {
1855 for (j
= 0 ; Index_wanted
> 0 && j
< 8 ; j
++)
1856 if ((zmap
[i
] << j
) & 0x80)
1861 Index_wanted
-= zCount
;
1864 for (j
= 0 ; j
< 8 ; j
++)
1865 if ((zmap
[i
] << j
) & 0x80)
1870 * now, we point to the begining of our next zones in the bitmap
1873 while (i
< ZT_BYTES
) {
1877 if ((zmap
[i
] << j
) & 0x80) {
1878 Index
= i
*8 + j
; /* get the index in ZT */
1880 ZLength
= ZT_table
[Index
].Zone
.len
;
1882 if (ZT_table
[Index
].ZoneCount
&& ZLength
) {
1883 if (packet_len
+ ATP_HDR_SIZE
+ ZLength
+ 1 >
1888 bcopy((caddr_t
) &ZT_table
[Index
].Zone
.str
,
1891 packet_len
+= ZLength
+ 1;
1893 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1894 ("zip_reply_GLZ: add z#%d to packet (l=%d)\n",
1895 Index
, packet_len
));
1898 dPrintf(D_M_ZIP
, D_L_WARNING
,
1899 ("zip_reply_GLZ: no len for index=%d\n",
1908 else /* set the "last flag" bit in the reply */
1911 else /* set the "last flag" bit in the reply */
1916 if (ZonesInPacket
== ZoneCount
)
1920 /* fill up the ddp header for reply */
1922 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1923 UAS_ASSIGN(r_ddp
->checksum
, 0);
1925 NET_ASSIGN(r_ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1926 NET_NET(r_ddp
->dst_net
, ddp
->src_net
);
1928 r_ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1929 r_ddp
->dst_node
= ddp
->src_node
;
1931 r_ddp
->dst_socket
= ddp
->src_socket
;
1932 r_ddp
->src_socket
= ZIP_SOCKET
;
1933 r_ddp
->type
= DDP_ATP
;
1935 /* fill up the atp header */
1936 r_atp
->cmd
= ATP_CMD_TRESP
;
1942 UAS_UAS(r_atp
->tid
, atp
->tid
);
1943 ulongtmp
= ((last_flag
<< 24) & 0xFF000000) + ZonesInPacket
; /* # of zones and flag*/
1944 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
);
1945 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ packet_len
;
1947 DDPLEN_ASSIGN(r_ddp
, size
);
1949 /* all set to send the packet back up */
1951 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1952 ("zip_r_GLZ: send packet to %d:%d port %d atp_len =%d\n",
1953 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, ifID
->ifPort
, packet_len
));
1955 if (status
= ddp_router_output(rm
, ifID
, AT_ADDR
,
1956 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, 0)) {
1957 dPrintf(D_M_ZIP
, D_L_ERROR
,
1958 ("zip_reply_to_GLZ: ddp_router_output returns =%d\n",
1963 } /* zip_reply_to_getlocalzones */
1965 int regDefaultZone(ifID
)
1969 char data
[ETHERNET_ADDR_LEN
];
1974 zt_get_zmcast(ifID
, &ifID
->ifZoneName
, data
);
1975 if (FDDI_OR_TOKENRING(ifID
->aa_ifp
->if_type
))
1976 ddp_bit_reverse(data
);
1977 bcopy((caddr_t
)data
, (caddr_t
)&ifID
->ZoneMcastAddr
, ETHERNET_ADDR_LEN
);
1978 (void)at_reg_mcast(ifID
, (caddr_t
)&ifID
->ZoneMcastAddr
);