2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1988-1998 Apple Computer, Inc.
32 * 0.01 05/12/94 Laurent Dumont Creation
34 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
38 * Router ZIP protocol functions:
40 * This file contains Routing specifics to handle ZIP requests and responses
41 * sent and received by a router node.
43 * The entry point for the zip input in ddp is valid only when we're
44 * running in router mode.
48 #include <sys/errno.h>
49 #include <sys/types.h>
50 #include <sys/param.h>
51 #include <machine/spl.h>
52 #include <sys/systm.h>
53 #include <sys/kernel.h>
55 #include <sys/filedesc.h>
56 #include <sys/fcntl.h>
58 #include <sys/ioctl.h>
59 #include <sys/malloc.h>
60 #include <sys/socket.h>
61 #include <sys/socketvar.h>
64 #include <net/if_types.h>
66 #include <netat/sysglue.h>
67 #include <netat/appletalk.h>
68 #include <netat/at_var.h>
69 #include <netat/ddp.h>
70 #include <netat/nbp.h>
71 #include <netat/zip.h>
72 #include <netat/at_pcb.h>
73 #include <netat/atp.h>
74 #include <netat/routing_tables.h>
75 #include <netat/debug.h>
77 #include <sys/kern_event.h>
79 static void zip_reply_to_getmyzone();
80 extern int at_reg_mcast(), at_unreg_mcast();
83 extern at_ifaddr_t
*ifID_table
[], *ifID_home
;
84 extern short ErrorZIPoverflow
;
86 /**********************************************************************
88 * ZIP is implemented as a "peer" of DDP, so the packets coming in
89 * to ZIP have the same headers as those coming in to DDP {ddp...}.
90 * Same applies to outgoing packets. Also, unlike DDP, ZIP assumes
91 * that an incoming packet is in a contiguous gbuf_t.
93 **********************************************************************/
95 static int netinfo_reply_pending
;
96 static void zip_netinfo_reply(at_x_zip_t
*, at_ifaddr_t
*);
97 static void zip_getnetinfo(at_ifaddr_t
*);
98 static void zip_getnetinfo_locked(void *);
99 static void send_phony_reply(void *);
102 * zip_send_getnetinfo_reply: we received a GetNetInfo packet, we need to reply
103 * with the right information for the port.
105 static void zip_send_getnetinfo_reply(m
, ifID
)
107 register at_ifaddr_t
*ifID
;
111 at_ddp_t
*ddp
, *ddp_sent
;
112 short ZoneNameProvided
= FALSE
;
113 short RequestIsBroadcasted
= FALSE
;
114 u_short znumber
, len
, packet_length
, size
, status
;
118 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
120 /* access the Zone Name info part of the GetNetInfo Request */
122 zname
= (at_nvestr_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
+ 6);
124 if (zname
->len
> ZIP_MAX_ZONE_LENGTH
) {
125 dPrintf(D_M_ZIP
, D_L_WARNING
,
126 ("zip_s_gni_r: zone len too long l=%d ddplen=%d\n",
127 zname
->len
, DDPLEN_VALUE(ddp
)));
133 ZoneNameProvided
= TRUE
;
135 GNIReply
[0] = ZIP_NETINFO_REPLY
;
136 GNIReply
[1] = ZIP_ZONENAME_INVALID
;
138 /* check if we are the originator is in the cable range for this interface */
140 if ((NET_VALUE(ddp
->src_net
) < CableStart
|| NET_VALUE(ddp
->src_net
) > CableStop
) &&
141 (NET_VALUE(ddp
->dst_net
) == 0 && ddp
->dst_node
== 0xff)) {
142 RequestIsBroadcasted
= TRUE
;
144 Entry
= rt_blookup(CableStop
);
146 if (Entry
!= NULL
&& RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
148 GNIReply
[2] = (Entry
->NetStart
& 0xFF00) >> 8;
149 GNIReply
[3] = (Entry
->NetStart
& 0x00FF);
150 GNIReply
[4] = (Entry
->NetStop
& 0xFF00) >> 8;
151 GNIReply
[5] = (Entry
->NetStop
& 0x00FF);
153 /* copy the zone name found in the request */
155 GNIReply
[6] = zname
->len
;
156 bcopy(&zname
->str
, &GNIReply
[7], zname
->len
);
159 if (znumber
= zt_find_zname(zname
)) {
161 if (ZT_ISIN_ZMAP((znumber
), Entry
->ZoneBitMap
)) {
163 GNIReply
[1] = 0; /* Zone Valid */
165 if (len
= zt_get_zmcast(ifID
, zname
, &GNIReply
[8+zname
->len
]))
166 GNIReply
[7+zname
->len
] = len
;
168 GNIReply
[1] |= ZIP_USE_BROADCAST
;
169 GNIReply
[7+zname
->len
] = 0; /* multicast address length */
171 packet_length
= 8 + zname
->len
+ len
;
177 else { /* should not happen, we are supposed to know our net */
178 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_s_gni_r: Don't know about our zone infos!!!\n"));
182 if (zt_ent_zcount(Entry
) == 1)
183 GNIReply
[1] |= ZIP_ONE_ZONE
;
185 if (GNIReply
[1] & ZIP_ZONENAME_INVALID
) {
187 short Index
= ifID
->ifDefZone
;
189 if (Index
<= 0 || Index
>= ZT_MAXEDOUT
) {
190 dPrintf(D_M_ZIP
, D_L_WARNING
,
191 ("zip_s_gni_r: Invalid starting index =%d port%d\n",
192 Index
, ifID
->ifPort
));
199 if (len
= zt_get_zmcast(ifID
, &ZT_table
[Index
].Zone
, &GNIReply
[8+zname
->len
]))
200 GNIReply
[7+zname
->len
] = len
;
202 GNIReply
[1] |= ZIP_USE_BROADCAST
;
203 GNIReply
[7+zname
->len
] = 0; /* multicast address length */
206 packet_length
= 7 + zname
->len
+ len
;
208 /* in the case the zone name asked for in the request was invalid, we need
209 * to copy the good default zone for this net
212 GNIReply
[packet_length
+ 1] = ZT_table
[Index
].Zone
.len
;
213 bcopy(&ZT_table
[Index
].Zone
.str
, &GNIReply
[packet_length
+ 2],
214 ZT_table
[Index
].Zone
.len
);
215 packet_length
= packet_length
+2 + ZT_table
[Index
].Zone
.len
;
220 * we're finally ready to send out the GetNetInfo Reply
225 size
= DDP_X_HDR_SIZE
+ packet_length
;
226 if ((m_sent
= gbuf_alloc(AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
227 return; /* was return(ENOBUFS); */
230 gbuf_rinc(m_sent
,AT_WR_OFFSET
);
231 gbuf_wset(m_sent
,size
);
232 ddp_sent
= (at_ddp_t
*)(gbuf_rptr(m_sent
));
234 /* Prepare the DDP header */
236 ddp_sent
->unused
= ddp_sent
->hopcount
= 0;
237 UAS_ASSIGN(ddp
->checksum
, 0);
238 DDPLEN_ASSIGN(ddp_sent
, size
);
239 NET_ASSIGN(ddp_sent
->src_net
, ifID
->ifThisNode
.s_net
);
240 ddp_sent
->src_node
= ifID
->ifThisNode
.s_node
;
241 ddp_sent
->src_socket
= ZIP_SOCKET
;
242 ddp_sent
->dst_socket
= ddp
->src_socket
;
244 if (RequestIsBroadcasted
) { /* if this was a broadcast, must respond from that */
246 NET_ASSIGN(ddp_sent
->dst_net
, 0);
247 ddp_sent
->dst_node
= 0xFF;
251 NET_NET(ddp_sent
->dst_net
, ddp
->src_net
);
252 ddp_sent
->dst_node
= ddp
->src_node
;
254 ddp_sent
->type
= DDP_ZIP
;
256 bcopy(&GNIReply
, &ddp_sent
->data
, packet_length
);
258 dPrintf(D_M_ZIP_LOW
, D_L_ROUTING
,
259 ("zip_s_gni_r: send to %d:%d port#%d pack_len=%d\n",
260 NET_VALUE(ddp_sent
->dst_net
), ddp_sent
->dst_node
,
261 ifID
->ifPort
, packet_length
));
263 ddp_router_output(m_sent
, ifID
, AT_ADDR
,
264 NET_VALUE(ddp_sent
->dst_net
), ddp_sent
->dst_node
, 0))) {
265 dPrintf(D_M_ZIP
, D_L_ERROR
,
266 ("zip_s_gni_r: ddp_router_output returns =%d\n", status
));
267 return; /* was return(status); */
269 } /* zip_send_getnetinfo_reply */
273 * build_ZIP_reply_packet: is used to create and send a DDP packet and use the
274 * provided buffer as a ZIP reply. This is used by zip_send_ext_reply_to_query
275 * and zip_send_reply_to_query for sending their replies to ZIP queries.
277 gbuf_t
*prep_ZIP_reply_packet(m
, ifID
)
278 register gbuf_t
*m
; /* this is the original zip query */
279 register at_ifaddr_t
*ifID
;
281 register gbuf_t
*m_sent
;
282 register at_ddp_t
*ddp
, *src_ddp
;
284 /* access the source Net and Node informations */
286 src_ddp
= (at_ddp_t
*)gbuf_rptr(m
);
288 if ((m_sent
= gbuf_alloc (AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
289 return((gbuf_t
*)NULL
);
291 gbuf_rinc(m_sent
,AT_WR_OFFSET
);
292 gbuf_wset(m_sent
,DDP_X_HDR_SIZE
);
293 ddp
= (at_ddp_t
*)(gbuf_rptr(m_sent
));
295 /* Prepare the DDP header */
297 ddp
->unused
= ddp
->hopcount
= 0;
298 UAS_ASSIGN(ddp
->checksum
, 0);
300 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
301 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
302 ddp
->src_socket
= ZIP_SOCKET
;
304 ddp
->dst_socket
= src_ddp
->src_socket
;
305 NET_NET(ddp
->dst_net
, src_ddp
->src_net
);
306 ddp
->dst_node
= src_ddp
->src_node
;
313 * zip_send_ext_reply_to_query: this function deals with ZIP Queries for extended nets.
314 * When we recognize an extended net (that might have several zone name associated with
315 * it), we send A SEPARATE ZIP reply for that network. This is called from the
316 * regular zip_send_reply_to_query, that just deals with non-ext nets.
319 static void zip_send_ext_reply_to_query(mreceived
, ifID
, Entry
, NetAsked
)
320 register gbuf_t
*mreceived
;
321 register at_ifaddr_t
*ifID
;
322 RT_entry
*Entry
; /* info about the network we're looking for */
326 register at_ddp_t
*ddp
;
327 short i
, j
, reply_length
, Index
, zone_count
, status
;
329 char *ReplyBuff
, *ZonesInPacket
;
331 zone_count
= zt_ent_zcount(Entry
);
332 zmap
= Entry
->ZoneBitMap
;
338 if (!(m
= prep_ZIP_reply_packet (mreceived
, ifID
))) {
339 return; /* was return(ENOBUFS); */
342 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
343 ReplyBuff
= (char *)(ddp
->data
);
346 *ReplyBuff
++ = 8; /* ZIP function = 8 [extended reply] */
348 ZonesInPacket
= ReplyBuff
;
351 reply_length
= 2; /* 1st byte is ZIP reply code, 2nd is network count */
354 /* For all zones, we check if they belong to the map for that Network */
356 for (; i
>= 0; i
--) {
358 /* find the zones defined in this entry bitmap */
362 if (zmap
[i
] << j
& 0x80) { /* bingo */
364 Index
= i
*8 + j
; /* zone index in zone table */
366 if (reply_length
+ 3 + ZT_table
[Index
].Zone
.len
> DDP_DATA_SIZE
) {
368 /* we need to send the packet before, this won't fit... */
370 zone_count
-= *ZonesInPacket
;
372 DDPLEN_ASSIGN(ddp
, reply_length
+ DDP_X_HDR_SIZE
);
373 gbuf_winc(m
,reply_length
);
375 ddp_router_output(m
, ifID
, AT_ADDR
,
376 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, 0))) {
377 dPrintf(D_M_ZIP
, D_L_ERROR
,
378 ("zip_s_ext_repl: ddp_router_output returns =%d\n",
380 return; /* was return (status); */
386 /* this should fit in this packet, build the NetNumber, ZoneLen,
390 if (ZT_table
[Index
].Zone
.len
) {
391 *ZonesInPacket
+= 1; /* bump NetCount field */
392 *ReplyBuff
++ = (NetAsked
& 0xFF00) >> 8;
393 *ReplyBuff
++ = (NetAsked
& 0x00FF) ;
394 *ReplyBuff
++ = ZT_table
[Index
].Zone
.len
;
396 bcopy(&ZT_table
[Index
].Zone
.str
, ReplyBuff
,
397 ZT_table
[Index
].Zone
.len
);
399 ReplyBuff
+= ZT_table
[Index
].Zone
.len
;
400 reply_length
+= ZT_table
[Index
].Zone
.len
+3;
405 j
= 0; /* reset the bit count */
408 /* if we have some zone info in a half-empty packet, send it now.
409 * Remember, for extended nets we send *at least* one Reply
413 DDPLEN_ASSIGN(ddp
, reply_length
+ DDP_X_HDR_SIZE
);
414 gbuf_winc(m
,reply_length
);
416 ddp_router_output(m
, ifID
, AT_ADDR
,
417 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, 0))) {
418 dPrintf(D_M_ZIP
, D_L_ERROR
,
419 ("zip_s_ext_reply: ddp_router_output returns =%d\n", status
));
420 return; /* was return (status); */
423 else /* free the buffer not used */
426 } /* zip_send_ext_reply_to_query */
429 * zip_send_reply_to_query: we received a ZIPQuery packet, we need to reply
430 * with the right information for the nets requested (if we have
431 * the right information.
433 static void zip_send_reply_to_query(mreceived
, ifID
)
434 register gbuf_t
*mreceived
;
435 register at_ifaddr_t
*ifID
;
438 register at_ddp_t
*ddp
, *ddp_received
;
440 short i
, reply_length
, Index
, status
;
441 u_char network_count
;
443 char *ReplyBuff
, *ZonesInPacket
;
445 ddp_received
= (at_ddp_t
*)gbuf_rptr(mreceived
);
447 /* access the number of nets requested in the Query */
448 network_count
= *((char *)(ddp_received
->data
) + 1);
449 NetAsked
= (u_short
*)(ddp_received
->data
+ 2);
451 /* check the validity of the Query packet */
453 if (DDPLEN_VALUE(ddp_received
) !=
454 (2 + network_count
* 2 + DDP_X_HDR_SIZE
)) {
456 dPrintf(D_M_ZIP
, D_L_WARNING
,
457 ("zip_s_reply_to_q: bad length netcount=%d len=%d\n",
458 network_count
, DDPLEN_VALUE(ddp
)));
459 return; /* was return(1); */
462 /* walk the Query Network list */
463 /* we want to build a response with the network number followed by the zone name
464 * length and the zone name. If there is more than one zone per network asked,
465 * we repeat the network number and stick the zone length and zone name.
466 * We need to be carefull with the max DDP size for data. If we see that a new
467 * NetNum, ZoneLen, ZoneName sequence won't fit, we send the previous packet and
468 * begin to build a new one.
473 if (!(m
= prep_ZIP_reply_packet (mreceived
, ifID
))) {
474 return; /* was return(ENOBUFS); */
477 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
478 ReplyBuff
= (char *)(ddp
->data
);
480 *ReplyBuff
++ = 2; /* ZIP function = 2 [Non extended reply] */
481 ZonesInPacket
= ReplyBuff
;
484 reply_length
= 2; /* 1st byte is ZIP reply code, 2nd is network count */
486 for (i
= 0 ; i
< network_count
; i
++, NetAsked
++) {
487 Entry
= rt_blookup(*NetAsked
);
489 if (Entry
!= NULL
&& ((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
490 RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
492 if (Entry
->NetStart
== 0) { /* asking for a NON EXTENDED network */
494 if ( (Index
= zt_ent_zindex(Entry
->ZoneBitMap
)) == 0)
499 if (reply_length
+ 3 + ZT_table
[Index
].Zone
.len
> DDP_DATA_SIZE
) {
501 /* we need to send the packet before, this won't fit... */
503 DDPLEN_ASSIGN(ddp
, reply_length
+ DDP_X_HDR_SIZE
);
504 gbuf_winc(m
,reply_length
);
507 ddp_router_output(m
, ifID
, AT_ADDR
,
508 NET_VALUE(ddp
->dst_net
),
509 ddp
->dst_node
, 0))) {
510 dPrintf(D_M_ZIP
, D_L_ERROR
,
511 ("zip_s_reply: ddp_router_output returns =%d\n",
513 return; /* was return (status); */
516 /* this is not nice, I know, but we reenter the loop with
517 * a packet is sent with the next network field in the Query
525 /* this should fit in this packet, build the NetNumber, ZoneLen,
529 if (ZT_table
[Index
].Zone
.len
) {
530 ZonesInPacket
+= 1; /* bump NetCount field */
531 *ReplyBuff
++ = (*NetAsked
& 0xFF00) >> 8;
532 *ReplyBuff
++ = (*NetAsked
& 0x00FF) ;
533 *ReplyBuff
++ = ZT_table
[Index
].Zone
.len
;
534 bcopy(&ZT_table
[Index
].Zone
.str
, ReplyBuff
,
535 ZT_table
[Index
].Zone
.len
);
537 ReplyBuff
+= ZT_table
[Index
].Zone
.len
;
539 reply_length
+= ZT_table
[Index
].Zone
.len
+ 3;
546 else { /* extended network, check for multiple zone name attached
547 * and build a separate packet for each extended network requested
550 zip_send_ext_reply_to_query(mreceived
, ifID
, Entry
, *NetAsked
);
556 /* If we have a non extended packet (code 2) with some stuff in it,
557 * we need to send it now
560 if ( reply_length
> 2) {
561 DDPLEN_ASSIGN(ddp
, reply_length
+ DDP_X_HDR_SIZE
);
562 gbuf_winc(m
,reply_length
);
564 ddp_router_output(m
, ifID
, AT_ADDR
,
565 NET_VALUE(ddp
->dst_net
),
566 ddp
->dst_node
, 0))) {
567 dPrintf(D_M_ZIP
, D_L_ERROR
,
568 ("zip_send_reply: ddp_router_output returns =%d\n", status
));
569 return; /* was return (status); */
572 else /* free the buffer not used */
574 } /* zip_send_reply_to_query */
576 /***********************************************************************
579 **********************************************************************/
581 void zip_router_input (m
, ifID
)
583 register at_ifaddr_t
*ifID
;
585 register at_ddp_t
*ddp
;
586 register at_atp_t
*atp
;
587 register at_zip_t
*zip
;
588 register u_long user_bytes
;
589 register u_short user_byte
;
591 /* variables for ZipNotify processing */
592 register char old_zone_len
;
593 register char new_zone_len
;
594 register char *old_zone
;
596 void zip_sched_getnetinfo(); /* forward reference */
598 if (gbuf_type(m
) != MSG_DATA
) {
599 /* If this is a M_ERROR message, DDP is shutting down,
600 * nothing to do here...If it's something else, we don't
601 * understand what it is
603 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_router_input: not an M_DATA message\n"));
609 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_router_input: BAD ifID\n"));
615 * The ZIP listener receives two types of requests:
617 * ATP requests: GetZoneList, GetLocalZone, or GetMyZone
618 * ZIP requests: Netinfo, Query, Reply, takedown, bringup
621 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
623 if (ddp
->type
== DDP_ZIP
) {
624 zip
= (at_zip_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
625 dPrintf(D_M_ZIP_LOW
, D_L_INPUT
,
626 ("zip_input: received a ZIP_DDP command=%d\n",
628 switch (zip
->command
) {
629 case ZIP_QUERY
: /* we received a Zip Query request */
630 dPrintf(D_M_ZIP
, D_L_INPUT
,
631 ("zip_input: Received a Zip Query in from %d.%d\n",
632 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
634 if (!RT_LOOKUP_OKAY(ifID
, ddp
)) {
635 dPrintf(D_M_ZIP
, D_L_INPUT
,
636 ("zip_input:: refused ZIP_QUERY from %d:%d\n",
637 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
640 zip_send_reply_to_query(m
, ifID
);
644 case ZIP_REPLY
: /* we received a Zip Query Reply packet */
645 case ZIP_EXTENDED_REPLY
:
646 if (ifID
->ifRoutingState
== PORT_OFFLINE
) {
647 dPrintf(D_M_ZIP
, D_L_INPUT
,
648 ("zip_input: Received a Zip Reply in user mode\n"));
651 zip_reply_received(m
, ifID
, zip
->command
);
656 /* we received a Zip Takedown packet */
657 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_input: Received a Zip takedown!!!\n"));
662 /* we received a Zip BringUp packet */
663 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_input: Received a Zip BringUp!!!\n"));
667 case ZIP_GETNETINFO
: /* we received a GetNetInfo request */
668 dPrintf(D_M_ZIP
, D_L_INPUT
,
669 ("zip_input: Received a GetNetInfo Req in from %d.%d\n",
670 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
671 if (RT_LOOKUP_OKAY(ifID
, ddp
)) {
672 dPrintf(D_M_ZIP
, D_L_OUTPUT
,
673 ("zip_input: we, as node %d:%d send GNI reply to %d:%d\n",
674 ifID
->ifThisNode
.s_net
, ifID
->ifThisNode
.s_node
,
675 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
676 zip_send_getnetinfo_reply(m
, ifID
);
682 case ZIP_NETINFO_REPLY
:
684 /* If we are not waiting for a GetNetInfo reply
685 * to arrive, this must be a broadcast
686 * message for someone else on the zone, so
687 * no need to even look at it!
690 ((NET_VALUE(ddp
->src_net
) != ifID
->ifThisNode
.s_net
) ||
691 (ddp
->src_node
!= ifID
->ifThisNode
.s_node
)) && netinfo_reply_pending
)
693 extern void trackrouter();
694 dPrintf(D_M_ZIP
, D_L_INPUT
,
695 ("zip_input: Received a GetNetInfo Reply from %d.%d\n",
696 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
697 trackrouter(ifID
, NET_VALUE(ddp
->src_net
), ddp
->src_node
);
698 zip_netinfo_reply((at_x_zip_t
*)zip
, ifID
);
705 /* processing of ZipNotify message : first, change
706 * our zone name, then if NIS is open, let NBP demon
707 process know of this change...(just forward the
710 /* First, check if this is really a packet for us */
711 old_zone
= &zip
->data
[4];
712 if (!zonename_equal(&ifID
->ifZoneName
,
713 (at_nvestr_t
*)old_zone
)) {
714 /* the old zone name in the packet is not the
715 * same as ours, so this packet couldn't be
722 old_zone_len
= *old_zone
;
723 new_zone_len
= zip
->data
[4 + old_zone_len
+ 1];
724 new_zone
= old_zone
+ old_zone_len
;
726 /* Reset the zone multicast address */
727 (void)at_unreg_mcast(ifID
, (caddr_t
)&ifID
->ZoneMcastAddr
);
728 bzero((caddr_t
)&ifID
->ZoneMcastAddr
, ETHERNET_ADDR_LEN
);
730 /* change the zone name - copy both the length and the string */
731 bcopy((caddr_t
)new_zone
, (caddr_t
)&ifID
->ifZoneName
,
734 /* Send network zone change event and new zone for this interface. */
735 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONEUPDATED
, 0, &(ifID
->ifZoneName
));
736 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONELISTCHANGED
, 0, 0);
738 /* add the new zone to the list of local zones */
739 if (!MULTIPORT_MODE
&& !DEFAULT_ZONE(&ifID
->ifZoneName
))
740 (void)setLocalZones(&ifID
->ifZoneName
,
741 (ifID
->ifZoneName
.len
+1));
743 /* Before trying to request our new multicast address,
744 * wait a while... someone might have alredy requested
745 * it, so we may see some broadcast messages flying
746 * by... Set up the structures so that it appears that
747 * we have already requested the NetInfo.
749 ifID
->ifNumRetries
= ZIP_NETINFO_RETRIES
;
750 netinfo_reply_pending
= 1;
751 ifID
->ifGNIScheduled
= 1;
752 timeout(zip_sched_getnetinfo
, (caddr_t
) ifID
,
758 routing_needed(m
, ifID
, TRUE
);
762 else if (ddp
->type
== DDP_ATP
&&
763 RT_LOOKUP_OKAY(ifID
, ddp
)) {
764 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
765 atp
= (at_atp_t
*)(gbuf_rptr(m
)+DDP_X_HDR_SIZE
);
767 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
769 /* Get the user bytes in network order */
771 user_bytes
= UAL_VALUE(atp
->user_bytes
);
772 user_byte
= user_bytes
>> 24; /* Get the zeroth byte */
774 dPrintf(D_M_ZIP
, D_L_INPUT
,
775 ("zip_input: received a ZIP_ATP command=%d\n", user_byte
));
779 zip_reply_to_getmyzone(ifID
, m
);
783 case ZIP_GETZONELIST
:
784 zip_reply_to_getzonelist(ifID
, m
);
788 case ZIP_GETLOCALZONES
:
789 zip_reply_to_getlocalzones(ifID
, m
);
794 dPrintf(D_M_ZIP
, D_L_WARNING
,
795 ("zip_input: received unknown ZIP_ATP command=%d\n", user_byte
));
796 routing_needed(m
, ifID
, TRUE
);
803 } /* zip_router_input */
805 /***********************************************************************
810 **********************************************************************/
811 int zonename_equal (zone1
, zone2
)
812 register at_nvestr_t
*zone1
, *zone2
;
814 register char c1
, c2
;
818 if (zone1
->len
!= zone2
->len
)
821 for (i
=0; i
< (int) zone1
->len
; i
++) {
824 if (c1
>= 'a' && c1
<= 'z')
826 if (c2
>= 'a' && c2
<= 'z')
844 static unsigned char lower_case
[] =
845 {0x8a, 0x8c, 0x8d, 0x8e, 0x96, 0x9a, 0x9f, 0xbe,
846 0xbf, 0xcf, 0x9b, 0x8b, 0x88, 0};
847 static unsigned char upper_case
[] =
848 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0xae,
849 0xaf, 0xce, 0xcd, 0xcc, 0xcb, 0};
851 for (i
=0; lower_case
[i
]; i
++)
852 if (ch
== lower_case
[i
])
853 return (upper_case
[i
]);
859 /***********************************************************************
860 * zip_netinfo_reply ()
864 **********************************************************************/
865 static void zip_netinfo_reply (netinfo
, ifID
)
866 register at_x_zip_t
*netinfo
;
867 register at_ifaddr_t
*ifID
;
870 void zip_sched_getnetinfo(); /* forward reference */
871 register at_net_al this_net
;
873 register u_char zone_name_len
;
875 /* There may be multiple zones on the cable.... we need to
876 * worry about whether or not this packet is addressed
879 /* *** Do we really need to check this? *** */
880 if (!zonename_equal((at_nvestr_t
*)netinfo
->data
, &ifID
->ifZoneName
)) {
881 dPrintf(D_M_ZIP
, D_L_INFO
, ("zip_netinfo_reply, !zonename_equal!!!"));
885 ifID
->ifThisCableStart
= NET_VALUE(netinfo
->cable_range_start
);
886 ifID
->ifThisCableEnd
= NET_VALUE(netinfo
->cable_range_end
);
887 dPrintf(D_M_ZIP
, D_L_OUTPUT
, ("Zip_netinfo_reply: Set cable to %d-%d\n",
888 ifID
->ifThisCableStart
, ifID
->ifThisCableEnd
));
890 /* The packet is in response to our request */
891 ifID
->ifGNIScheduled
= 0;
892 untimeout (zip_sched_getnetinfo
, (caddr_t
) ifID
);
893 netinfo_reply_pending
= 0;
894 zone_name_len
= netinfo
->data
[0];
895 mcast_len
= netinfo
->data
[zone_name_len
+ 1];
897 if (netinfo
->flags
& ZIP_ZONENAME_INVALID
) {
898 /* copy out the default zone name from packet */
899 default_zone
= (char *)&netinfo
->data
[zone_name_len
+1+mcast_len
+1];
900 bcopy((caddr_t
)default_zone
, (caddr_t
)&ifID
->ifZoneName
,
904 /* add the new zone to the list of local zones */
905 if (!MULTIPORT_MODE
&& !DEFAULT_ZONE(&ifID
->ifZoneName
))
906 (void)setLocalZones(&ifID
->ifZoneName
, (ifID
->ifZoneName
.len
+1));
908 /* get the multicast address out of the GetNetInfo reply, if there is one */
909 if (!(netinfo
->flags
& ZIP_USE_BROADCAST
)) {
910 /* If ZIP_USE_BROADCAST is set, we will use the cable
911 broadcast address as the multicast address, however
912 the cable multicast address has already been registered.
914 /* This packet contains a multicast address, so
915 * send to elap to register it.
917 if (FDDI_OR_TOKENRING(ifID
->aa_ifp
->if_type
))
918 ddp_bit_reverse(&netinfo
->data
[zone_name_len
+ 2]);
920 bcopy((caddr_t
)&netinfo
->data
[zone_name_len
+ 2],
921 (caddr_t
)&ifID
->ZoneMcastAddr
, ETHERNET_ADDR_LEN
);
922 (void)at_reg_mcast(ifID
, (caddr_t
)&ifID
->ZoneMcastAddr
);
925 this_net
= ifID
->ifThisNode
.s_net
;
926 if ((this_net
>= ifID
->ifThisCableStart
) &&
927 (this_net
<= ifID
->ifThisCableEnd
)) {
928 /* ThisNet is in the range of valid network numbers
929 * for the cable. Do nothing.
932 /* ThisNet is not in the range of valid network
933 * numbers for the cable. This may be either because
934 * the chosen number was from start-up range, or
935 * because the user has a misconception of where the
936 * machine is!! Since ThisCableRange is set up, next
937 * time aarp is invoked, it would select address in
941 /* to reset initial_net and initial_node to zero, so
942 * that aarp is forced to choose new values
944 ifID
->initial_addr
.s_net
= 0;
945 ifID
->initial_addr
.s_node
= 0;
947 /* Wake up elap_online sleeping on this interface. */
948 ZIPwakeup(ifID
, ZIP_RE_AARP
);
952 if (!ifID
->startup_inprogress
) {
953 /* Send event with zone info. This covers case where we get zone info
954 after startup. During startup this event is sent from ZIPwakeup. */
955 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONEUPDATED
, 0, &(ifID
->ifZoneName
));
958 ZIPwakeup(ifID
, 0); /* no error */
960 } /* zip_netinfo_reply */
963 /**********************************************************************
966 **********************************************************************/
967 int zip_control (ifID
, control
)
968 register at_ifaddr_t
*ifID
;
971 dPrintf(D_M_ZIP
, D_L_INFO
, ("zip_control called port=%d control=%d\n",
972 ifID
->ifPort
, control
));
975 case ZIP_LATE_ROUTER
:
976 if (!ifID
->ifGNIScheduled
) {
977 ifID
->ifNumRetries
= 0;
978 /* Get the desired zone name from elap and put it in
979 * ifID for zip_getnetinfo() to use.
981 if (ifID
->startup_zone
.len
)
982 ifID
->ifZoneName
= ifID
->startup_zone
;
983 zip_getnetinfo(ifID
);
987 ifID
->ifZoneName
.len
= 1;
988 ifID
->ifZoneName
.str
[0] = '*';
989 ifID
->ifZoneName
.str
[1] = '\0';
991 /* Send event with zone info. */
992 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONEUPDATED
, 0, &(ifID
->ifZoneName
));
1001 /* locked version of zip_getnetinfo */
1002 static void zip_getnetinfo_locked(arg
)
1008 if (ifID
!= NULL
) { // make sure it hasn't been closed
1009 ifID
= (at_ifaddr_t
*)arg
;
1010 ifID
->ifGNIScheduled
= 0;
1011 zip_getnetinfo(ifID
);
1017 /**********************************************************************
1020 **********************************************************************/
1021 static void zip_getnetinfo (ifID
)
1022 register at_ifaddr_t
*ifID
;
1024 register at_x_zip_t
*zip
;
1026 register at_ddp_t
*ddp
;
1027 void zip_sched_getnetinfo();
1028 register struct atalk_addr
*at_dest
;
1032 size
= DDP_X_HDR_SIZE
+ ZIP_X_HDR_SIZE
+ ifID
->ifZoneName
.len
+ 1
1033 + sizeof(struct atalk_addr
) + 1;
1034 if ((m
= gbuf_alloc (AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
1035 /* This time, we're unable to allocate buffer to
1036 * send a packet out, so schedule to send a packet
1037 * out later, and exit.
1039 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_getnetinfo: no buffer, call later port=%d\n",
1041 ifID
->ifGNIScheduled
= 1;
1042 timeout (zip_getnetinfo_locked
, (caddr_t
) ifID
, ZIP_TIMER_INT
/10);
1046 gbuf_rinc(m
,AT_WR_OFFSET
);
1048 *(u_char
*)gbuf_rptr(m
) = AT_ADDR
;
1049 at_dest
= (struct atalk_addr
*)(gbuf_rptr(m
) + 1);
1050 ddp
= (at_ddp_t
*)(gbuf_rptr(m
) + sizeof(struct atalk_addr
) + 1);
1051 zip
= (at_x_zip_t
*)ddp
->data
;
1054 zip
->command
= ZIP_GETNETINFO
;
1056 NET_ASSIGN(zip
->cable_range_start
, 0);
1057 NET_ASSIGN(zip
->cable_range_end
, 0);
1058 if (ifID
->ifZoneName
.len
) /* has to match reply exactly */
1059 bcopy((caddr_t
)&ifID
->ifZoneName
, (caddr_t
)zip
->data
,
1060 ifID
->ifZoneName
.len
+ 1);
1062 zip
->data
[0] = 0; /* No zone name is availbale */
1064 /* let the lap fields be uninitialized, 'cause it doesn't
1067 DDPLEN_ASSIGN(ddp
, size
- (sizeof(struct atalk_addr
) + 1));
1068 UAS_ASSIGN(ddp
->checksum
, 0);
1069 ddp
->hopcount
= ddp
->unused
= 0;
1070 NET_ASSIGN(ddp
->dst_net
, 0); /* cable-wide broadcast */
1071 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1072 /* By this time, AARP is done */
1074 ddp
->dst_node
= 0xff;
1075 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1076 ddp
->dst_socket
= ZIP_SOCKET
;
1077 ddp
->src_socket
= ZIP_SOCKET
;
1078 ddp
->type
= DDP_ZIP
;
1080 at_dest
->atalk_unused
= 0;
1081 NET_NET(at_dest
->atalk_net
, ddp
->dst_net
);
1082 at_dest
->atalk_node
= ddp
->dst_node
;
1084 dPrintf(D_M_ZIP
, D_L_INPUT
, ("zip_getnetinfo: called for port=%d\n",
1087 if (elap_dataput(m
, ifID
, 0, NULL
)) {
1088 dPrintf(D_M_ZIP
, D_L_ERROR
,
1089 ("zip_getnetinfo: error sending zip_getnetinfo\n"));
1093 ifID
->ifNumRetries
++;
1094 netinfo_reply_pending
= 1;
1095 ifID
->ifGNIScheduled
= 1;
1096 timeout (zip_sched_getnetinfo
, (caddr_t
) ifID
, ZIP_TIMER_INT
);
1097 } /* zip_getnetinfo */
1100 /**********************************************************************
1101 * zip_sched_getnetinfo()
1103 **********************************************************************/
1105 void zip_sched_getnetinfo (ifID
)
1106 register at_ifaddr_t
*ifID
;
1111 ifID
->ifGNIScheduled
= 0;
1113 if (ifID
->ifNumRetries
>= ZIP_NETINFO_RETRIES
) {
1114 /* enough packets sent.... give up! */
1115 /* we didn't get any response from the net, so
1116 * assume there's no router around and the given
1117 * zone name, if any, is not valid. Change the
1120 ifID
->ifZoneName
.len
= 1;
1121 ifID
->ifZoneName
.str
[0] = '*';
1122 ifID
->ifZoneName
.str
[1] = '\0';
1123 /* Should NBP be notified of this "new" zone name?? */
1124 netinfo_reply_pending
= 0;
1126 ifID
->ifRouterState
= NO_ROUTER
;
1127 ifID
->ifARouter
.s_net
= 0;
1128 ifID
->ifARouter
.s_node
= 0;
1130 dPrintf(D_M_ZIP
, D_L_INFO
, ("zip_sched_getnetinfo: Reset Cable Range\n"));
1132 ifID
->ifThisCableStart
= DDP_MIN_NETWORK
;
1133 ifID
->ifThisCableEnd
= DDP_MAX_NETWORK
;
1135 if (ifID
->ifState
== LAP_ONLINE_FOR_ZIP
)
1136 ZIPwakeup (ifID
, 0); /* no error */
1138 zip_getnetinfo(ifID
);
1144 /**********************************************************************
1148 * This routine checks whether or not the packet contained in "m"
1149 * is an (outgoing) ZIP packet. If not, it returns 0. If it is a
1150 * ZIP packet, it returns the ZIP packet type (ZIP command). "m"
1151 * points to a packet with extended DDP header. The rest of the
1152 * DDP data may or may not be in the first gbuf.
1154 **********************************************************************/
1155 int zip_type_packet (m
)
1158 register at_atp_t
*atp
;
1159 register at_ddp_t
*ddp
;
1160 register at_zip_t
*zip
;
1161 register u_long user_bytes
;
1162 register int user_byte
;
1164 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1165 if (ddp
->dst_socket
== ZIP_SOCKET
) {
1166 switch (ddp
->type
) {
1168 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1169 zip
= (at_zip_t
*)(gbuf_rptr(m
)
1172 zip
=(at_zip_t
*)(gbuf_rptr(gbuf_cont(m
)));
1173 return ((int)zip
->command
);
1175 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1176 atp
= (at_atp_t
*)(gbuf_rptr(m
)+DDP_X_HDR_SIZE
);
1178 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1179 /* Get the user bytes in network order */
1180 user_bytes
= UAL_VALUE(atp
->user_bytes
);
1181 user_byte
= user_bytes
>> 24; /* Get the zeroth byte */
1182 if ((user_byte
== ZIP_GETMYZONE
) ||
1183 (user_byte
== ZIP_GETZONELIST
) ||
1184 (user_byte
== ZIP_GETLOCALZONES
))
1195 /**********************************************************************
1196 * zip_handle_getmyzone()
1199 * Routine to handle ZIP GetMyZone request locally. It generates
1200 * a phony response to the outgoing ATP request and sends it up.
1202 * 07/12/94 : remark2 only called from ddp.c / ddp_output
1203 * should only be called from the home port, but
1204 * when we are a router we should know the infos for all
1205 * anyway, so reply locally with what we have in stock...
1207 **********************************************************************/
1209 int zip_handle_getmyzone(ifID
, m
)
1210 register at_ifaddr_t
*ifID
;
1214 register at_ddp_t
*ddp
;
1215 register at_ddp_t
*r_ddp
;
1216 register at_atp_t
*r_atp
;
1217 gbuf_t
*rm
; /* reply message */
1221 dPrintf(D_M_ZIP
, D_L_INFO
,
1222 ("zip_handle_getmyzone: local reply for port=%d\n",
1225 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ 1 + ifID
->ifZoneName
.len
;
1226 /* space for two headers and the zone name */
1227 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
1228 dPrintf(D_M_ZIP
, D_L_WARNING
,
1229 ("zip_handle_getmyzone: no buffer, port=%d\n",
1234 gbuf_rinc(rm
,AT_WR_OFFSET
);
1236 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1237 r_atp
= (at_atp_t
*)r_ddp
->data
;
1240 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1241 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1242 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1244 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1246 /* fill up the ddp header for reply */
1247 DDPLEN_ASSIGN(r_ddp
, size
);
1248 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1249 UAS_ASSIGN(r_ddp
->checksum
, 0);
1250 NET_ASSIGN(r_ddp
->dst_net
, ifID
->ifThisNode
.s_net
);
1251 NET_NET(r_ddp
->src_net
, ddp
->dst_net
);
1252 r_ddp
->dst_node
= ifID
->ifThisNode
.s_node
;
1253 r_ddp
->src_node
= ddp
->dst_node
;
1254 r_ddp
->dst_socket
= ddp
->src_socket
;
1255 r_ddp
->src_socket
= ZIP_SOCKET
;
1256 r_ddp
->type
= DDP_ATP
;
1258 /* fill up the atp header */
1259 r_atp
->cmd
= ATP_CMD_TRESP
;
1265 UAS_UAS(r_atp
->tid
, atp
->tid
);
1267 ulongtmp
= htonl(ulongtmp
);
1268 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
); /* no of zones */
1270 /* fill up atp data part */
1271 bcopy((caddr_t
) &ifID
->ifZoneName
, (caddr_t
) r_atp
->data
, ifID
->ifZoneName
.len
+1);
1273 /* all set to send the packet back up */
1275 timeout(send_phony_reply
, (caddr_t
) rm
, HZ
/20);
1280 send_phony_reply(arg
)
1283 gbuf_t
*rm
= (gbuf_t
*)arg
;
1286 ddp_input(rm
, ifID_home
);
1294 * zip_prep_query_packet: build the actual ddp packet for the zip query
1297 gbuf_t
*zip_prep_query_packet(ifID
, RouterNet
, RouterNode
)
1299 at_net_al RouterNet
; /* we want to send the Zip Query to that router */
1304 register at_ddp_t
*ddp
;
1306 if ((m
= gbuf_alloc (AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
1307 dPrintf(D_M_ZIP
, D_L_WARNING
,
1308 ("zip_send_query_packet: no buffer, port=%d\n",
1310 return((gbuf_t
*)NULL
);
1312 gbuf_rinc(m
,AT_WR_OFFSET
);
1315 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
1317 /* Prepare the DDP header */
1319 ddp
->unused
= ddp
->hopcount
= 0;
1320 UAS_ASSIGN(ddp
->checksum
, 0);
1321 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1322 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1323 ddp
->src_socket
= ZIP_SOCKET
;
1325 ddp
->dst_socket
= ZIP_SOCKET
;
1326 NET_ASSIGN(ddp
->dst_net
, RouterNet
);
1327 ddp
->dst_node
= RouterNode
;
1329 ddp
->type
= DDP_ZIP
;
1332 } /* zip_prep_query_packet */
1336 * zip_send_queries: this function send queries for the routing table entries that
1337 * need to know their zones. It scans the routing table for entries with unknown
1338 * zones and build Query packets accordingly.
1339 * Note: this is called on a per port basis.
1342 void zip_send_queries(ifID
, RouterNet
, RouterNode
)
1343 register at_ifaddr_t
*ifID
;
1344 at_net_al RouterNet
; /* we want to send the Zip Query to that router */
1347 RT_entry
*Entry
= &RT_table
[0];
1349 register at_ddp_t
*ddp
;
1351 short Query_index
, EntryNumber
= 0 ;
1352 register u_char port
= ifID
->ifPort
;
1353 char *QueryBuff
, *ZoneCount
;
1354 short zip_sent
= FALSE
;
1358 if (!(m
= zip_prep_query_packet(ifID
, RouterNet
, RouterNode
))) {
1359 return; /* was return (ENOBUFS); */
1362 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
1363 QueryBuff
= (char *)ddp
->data
;
1365 *QueryBuff
++ = ZIP_QUERY
;
1366 ZoneCount
= QueryBuff
; /* network count */
1372 while (EntryNumber
< RT_maxentry
) {
1374 /* scan the table, and build the packet with the right entries:
1375 * - entry in use and on the right Port
1376 * - with unknwon zones and in an active state
1377 * - talking to the right router
1380 if ((Query_index
) > 2*254 +2) {
1382 /* we need to send the packet now, but we can't have more than 256
1383 * requests for networks: the Netcount field is a 8bit in the zip query
1384 * packet format as defined in Inside Atalk
1387 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1388 ("zip_send_query: FULL query for %d nets on port#%d.(len=%d)\n",
1389 *ZoneCount
, port
, Query_index
));
1392 gbuf_winc(m
,DDP_X_HDR_SIZE
+ Query_index
);
1393 DDPLEN_ASSIGN(ddp
, DDP_X_HDR_SIZE
+ Query_index
);
1396 ddp_router_output(m
, ifID
, AT_ADDR
,
1397 RouterNet
, RouterNode
, 0))) {
1398 dPrintf(D_M_ZIP
, D_L_ERROR
,
1399 ("zip_send_query: ddp_router_output returns =%d\n", status
));
1400 return; /* was return (status); */
1407 if (((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
1408 (Entry
->NetStop
) && (Entry
->NetPort
== port
) &&
1409 (!RT_ALL_ZONES_KNOWN(Entry
))){
1411 /* we're ready to had that to our list of stuff to send */
1413 if (Entry
->NetStart
) { /* extended net*/
1415 *QueryBuff
++ = (Entry
->NetStart
& 0xFF00) >> 8;
1416 *QueryBuff
++ = (Entry
->NetStart
& 0x00FF);
1420 *QueryBuff
++ = (Entry
->NetStop
& 0xFF00) >> 8;
1421 *QueryBuff
++ = (Entry
->NetStop
& 0x00FF);
1425 *ZoneCount
+= 1;/* bump the number of network requested */
1434 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1435 ("zip_send_query: query for %d nets on port#%d.(len=%d)\n",
1436 *ZoneCount
, port
, Query_index
));
1438 if (*ZoneCount
) { /* non-full Query needs to be sent */
1440 gbuf_winc(m
,DDP_X_HDR_SIZE
+ Query_index
);
1441 DDPLEN_ASSIGN(ddp
, DDP_X_HDR_SIZE
+ Query_index
);
1444 ddp_router_output(m
, ifID
, AT_ADDR
,
1445 RouterNet
, RouterNode
, 0))) {
1446 dPrintf(D_M_ZIP
, D_L_ERROR
,
1447 ("zip_send_query: ddp_router_output returns =%d\n",
1449 return; /* was return (status); */
1455 if (!zip_sent
) /* we didn't need to send anything for that port */
1456 ifID
->ifZipNeedQueries
= 0;
1457 } /* zip_send_queries */
1459 /* zip_reply_received: we recieved the reply to one of our query, update the
1460 * zone bitmap and stuffs with was we received.
1461 * we receive two types of replies: non extended and extended.
1462 * For extended replies, the network count is the Total of zones for that net.
1465 zip_reply_received(m
, ifID
, reply_type
)
1467 register at_ifaddr_t
*ifID
;
1470 register at_nvestr_t
*zname
;
1471 RT_entry
*Entry
= &RT_table
[0];
1472 register at_ddp_t
*ddp
;
1474 u_short payload_len
, result
;
1475 u_char network_count
;
1478 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1480 /* access the number of nets provided in the ZIP Reply */
1482 network_count
= *(u_char
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
+ 1);
1484 PacketPtr
= (char *)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
+ 2);
1486 payload_len
= DDPLEN_VALUE(ddp
) - (DDP_X_HDR_SIZE
+ 2);
1488 dPrintf(D_M_ZIP_LOW
, D_L_INPUT
, ("zip_reply_received from %d:%d type=%d netcount=%d\n",
1489 NET_VALUE(ddp
->src_net
), ddp
->src_node
, reply_type
, network_count
));
1492 while (payload_len
> 0 && network_count
>0) {
1494 Network
= *(at_net_al
*)PacketPtr
;
1496 zname
= (at_nvestr_t
*)PacketPtr
;
1498 payload_len
= payload_len
-(zname
->len
+ 3);
1500 if (zname
->len
<= 0) { /* not valid, we got a problem here... */
1501 dPrintf(D_M_ZIP
, D_L_WARNING
,
1502 ("zip_reply_received: Problem zlen=0 for net=%d from %d:%d type=%d netcnt=%d\n",
1503 Network
, NET_VALUE(ddp
->src_net
), ddp
->src_node
, reply_type
, network_count
));
1509 Entry
= rt_blookup(Network
);
1511 if (Entry
!= NULL
) {
1513 if (Entry
->EntryState
>= RTE_STATE_SUSPECT
) {
1515 result
= zt_add_zonename(zname
);
1517 if (result
== ZT_MAXEDOUT
) {
1519 dPrintf(D_M_ZIP
, D_L_ERROR
,
1520 ("zip_reply_received: ZTable full from %d:%d on zone '%s'\n",
1521 NET_VALUE(ddp
->src_net
), ddp
->src_node
, zname
->str
));
1522 ErrorZIPoverflow
= 1;
1526 zt_set_zmap(result
, Entry
->ZoneBitMap
);
1528 RT_SET_ZONE_KNOWN(Entry
);
1532 dPrintf(D_M_ZIP
, D_L_INPUT
,
1533 ("zip_reply_received: entry %d-%d not updated, cause state=%d\n",
1534 Entry
->NetStart
, Entry
->NetStop
, Entry
->EntryState
));
1538 dPrintf(D_M_ZIP
, D_L_WARNING
,
1539 ("zip_reply_received: network %d not found in RT\n", Network
));
1543 /* now bump the PacketPtr pointer */
1544 PacketPtr
+= zname
->len
+ 1;
1548 if ((reply_type
== ZIP_REPLY
) && network_count
> 0) {
1550 dPrintf(D_M_ZIP
, D_L_WARNING
,
1551 ("zip_reply_received: Problem decoding zone (after net:%d-%d)\n",
1552 Entry
->NetStart
, Entry
->NetStop
));
1553 ifID
->ifZipNeedQueries
= 1;
1556 ifID
->ifZipNeedQueries
= 0;
1558 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1559 ("zip_reply_received: entry %d-%d all zones known\n",
1560 Entry
->NetStart
, Entry
->NetStop
));
1565 * zip_reply_to_getmyzone: replies to ZIP GetMyZone received from the Net
1568 static void zip_reply_to_getmyzone (ifID
, m
)
1569 register at_ifaddr_t
*ifID
;
1573 register at_ddp_t
*ddp
;
1574 register at_ddp_t
*r_ddp
;
1575 register at_atp_t
*r_atp
;
1576 register gbuf_t
*rm
; /* reply message */
1577 register int size
, Index
, status
;
1582 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ 1 + ifID
->ifZoneName
.len
;
1583 /* space for two headers and the zone name */
1584 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
1585 dPrintf(D_M_ZIP
, D_L_WARNING
,
1586 ("zip_reply_to_getmyzone: no buffer, port=%d\n", ifID
->ifPort
));
1587 return; /* was return (ENOBUFS); */
1589 gbuf_rinc(rm
,AT_WR_OFFSET
);
1591 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1592 r_atp
= (at_atp_t
*)r_ddp
->data
;
1594 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1595 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1596 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1598 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1600 /* fill up the ddp header for reply */
1601 DDPLEN_ASSIGN(r_ddp
, size
);
1602 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1603 UAS_ASSIGN(r_ddp
->checksum
, 0);
1605 NET_ASSIGN(r_ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1606 NET_NET(r_ddp
->dst_net
, ddp
->src_net
);
1608 r_ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1609 r_ddp
->dst_node
= ddp
->src_node
;
1611 r_ddp
->dst_socket
= ddp
->src_socket
;
1612 r_ddp
->src_socket
= ZIP_SOCKET
;
1613 r_ddp
->type
= DDP_ATP
;
1615 /* fill up the atp header */
1616 r_atp
->cmd
= ATP_CMD_TRESP
;
1622 UAS_UAS(r_atp
->tid
, atp
->tid
);
1624 ulongtmp
= htonl(ulongtmp
);
1625 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
); /* no of zones */
1627 data_ptr
= (char *)r_atp
->data
;
1630 * fill up atp data part with the zone name if we can find it...
1633 Entry
= rt_blookup(NET_VALUE(ddp
->src_net
));
1634 if (Entry
!= NULL
&& ((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
1635 RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
1637 Index
= zt_ent_zindex(Entry
->ZoneBitMap
) -1;
1639 *data_ptr
= ZT_table
[Index
].Zone
.len
;
1640 bcopy((caddr_t
) &ZT_table
[Index
].Zone
.str
, (caddr_t
) ++data_ptr
,
1641 ZT_table
[Index
].Zone
.len
);
1643 /* all set to send the packet back up */
1644 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1645 ("zip_reply_to_GMZ: ddp_router_output to %d:%d port %d\n",
1646 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, ifID
->ifPort
));
1649 ddp_router_output(rm
, ifID
, AT_ADDR
,
1650 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, 0))) {
1651 dPrintf(D_M_ZIP
, D_L_ERROR
,
1652 ("zip_reply_to_GMZ: ddp_r_output returns =%d\n", status
));
1653 return; /* was return (status); */
1661 * zip_reply_to_getzonelist: replies to ZIP GetZoneList requested from the Net
1664 zip_reply_to_getzonelist (ifID
, m
)
1665 register at_ifaddr_t
*ifID
;
1669 register at_ddp_t
*ddp
;
1670 register at_ddp_t
*r_ddp
;
1671 register at_atp_t
*r_atp
;
1672 register gbuf_t
*rm
; /* reply message */
1673 register int size
, status
;
1674 register short Index
=0, StartPoint
, ZLength
, PacketLen
=0;
1678 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1679 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1680 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1682 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1685 /* space for two headers and the zone name */
1687 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
1691 gbuf_rinc(rm
,AT_WR_OFFSET
);
1693 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1694 r_atp
= (at_atp_t
*)r_ddp
->data
;
1696 /* fill up the ddp header for reply */
1698 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1699 UAS_ASSIGN(r_ddp
->checksum
, 0);
1700 NET_ASSIGN(r_ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1701 NET_NET(r_ddp
->dst_net
, ddp
->src_net
);
1702 r_ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1703 r_ddp
->dst_node
= ddp
->src_node
;
1704 r_ddp
->dst_socket
= ddp
->src_socket
;
1705 r_ddp
->src_socket
= ZIP_SOCKET
;
1706 r_ddp
->type
= DDP_ATP
;
1708 /* fill up the atp header */
1710 r_atp
->cmd
= ATP_CMD_TRESP
;
1716 UAS_UAS(r_atp
->tid
, atp
->tid
);
1718 Reply
= (char *)r_atp
->data
;
1720 /* get the start index from the ATP request */
1722 StartPoint
= (UAL_VALUE(atp
->user_bytes
) & 0xffff) -1;
1724 /* find the next zone to send */
1726 while ((Index
< ZT_maxentry
) && StartPoint
> 0) {
1727 if (ZT_table
[Index
].Zone
.len
)
1733 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
, ("zip_reply_to_GZL: Index=%d\n", Index
));
1735 * fill up atp data part with the zone name if we can find it...
1738 while (Index
< ZT_maxentry
) {
1740 ZLength
= ZT_table
[Index
].Zone
.len
;
1742 if (ZT_table
[Index
].ZoneCount
&& ZLength
) {
1745 if (PacketLen
+ 8 + ZLength
+1 > DDP_DATA_SIZE
) /* packet full */
1749 bcopy((caddr_t
) &ZT_table
[Index
].Zone
.str
,
1752 PacketLen
+= ZLength
+ 1;
1758 if (Index
>= ZT_maxentry
) /* this is the end of the list */
1760 ulongtmp
+= 0x01000000;
1763 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
); /* # of zones and flag*/
1765 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ PacketLen
;
1767 DDPLEN_ASSIGN(r_ddp
, size
);
1769 /* all set to send the packet back up */
1771 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1772 ("zip_r_GZL: send packet to %d:%d port %d atp_len =%d\n",
1773 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, ifID
->ifPort
, PacketLen
));
1776 if (status
= ddp_router_output(rm
, ifID
, AT_ADDR
,
1777 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, 0)) {
1778 dPrintf(D_M_ZIP
, D_L_ERROR
, ("zip_reply_to_GZL: ddp_router_output returns=%d\n",
1787 * zip_reply_to_getlocalzones: replies to ZIP GetLocalZones requested from the Net
1790 int zip_reply_to_getlocalzones (ifID
, m
)
1791 register at_ifaddr_t
*ifID
;
1795 register at_ddp_t
*ddp
;
1796 register at_ddp_t
*r_ddp
;
1797 register at_atp_t
*r_atp
;
1798 register gbuf_t
*rm
; /* reply message */
1800 short Index
, Index_wanted
, ZLength
;
1801 short i
,j
, packet_len
;
1802 short zCount
, ZoneCount
, ZonesInPacket
;
1803 char *zmap
, last_flag
= 0;
1807 u_long ulongtmp
= 0;
1809 Index
= Index_wanted
= ZLength
= i
= j
= packet_len
= zCount
= ZoneCount
=
1812 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1813 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1814 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1816 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1818 /* space for two headers and the zone name */
1820 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
1824 gbuf_rinc(rm
,AT_WR_OFFSET
);
1826 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1827 r_atp
= (at_atp_t
*)r_ddp
->data
;
1829 Reply
= (char *)r_atp
->data
;
1832 /* get the start index from the ATP request */
1834 Index_wanted
= (UAL_VALUE(atp
->user_bytes
) & 0xffff) -1;
1836 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1837 ("zip_r_GLZ: for station %d:%d Index_wanted = %d\n",
1838 NET_VALUE(ddp
->src_net
), ddp
->src_node
, Index_wanted
));
1840 Entry
= rt_blookup(NET_VALUE(ddp
->src_net
));
1842 if (Entry
!= NULL
&& ((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
1843 RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
1845 ZoneCount
= zt_ent_zcount(Entry
) ;
1847 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1848 ("zip_reply_GLZ: for %d:%d ZoneCount=%d\n",
1849 NET_VALUE(ddp
->src_net
), ddp
->src_node
, ZoneCount
));
1851 zmap
= &Entry
->ZoneBitMap
[0];
1854 * first of all, we want to find the "first next zone" in the bitmap,
1855 * to do so, we need to scan the bitmap and add the number of valid
1856 * zones we find until we reach the next zone to be sent in the reply
1859 if (ZoneCount
> Index_wanted
) {
1861 ZoneCount
-= Index_wanted
;
1863 /* find the starting point in the bitmap according to index */
1865 for (i
= 0; Index_wanted
>= 0 && i
< ZT_BYTES
; i
++)
1867 if (Index_wanted
< 8) {
1868 /* how many zones in the bitmap byte */
1869 for (j
= 0, zCount
=0; j
< 8 ; j
++)
1870 if ((zmap
[i
] << j
) & 0x80)
1872 if (Index_wanted
< zCount
) {
1873 for (j
= 0 ; Index_wanted
> 0 && j
< 8 ; j
++)
1874 if ((zmap
[i
] << j
) & 0x80)
1879 Index_wanted
-= zCount
;
1882 for (j
= 0 ; j
< 8 ; j
++)
1883 if ((zmap
[i
] << j
) & 0x80)
1888 * now, we point to the begining of our next zones in the bitmap
1891 while (i
< ZT_BYTES
) {
1895 if ((zmap
[i
] << j
) & 0x80) {
1896 Index
= i
*8 + j
; /* get the index in ZT */
1898 ZLength
= ZT_table
[Index
].Zone
.len
;
1900 if (ZT_table
[Index
].ZoneCount
&& ZLength
) {
1901 if (packet_len
+ ATP_HDR_SIZE
+ ZLength
+ 1 >
1906 bcopy((caddr_t
) &ZT_table
[Index
].Zone
.str
,
1909 packet_len
+= ZLength
+ 1;
1911 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1912 ("zip_reply_GLZ: add z#%d to packet (l=%d)\n",
1913 Index
, packet_len
));
1916 dPrintf(D_M_ZIP
, D_L_WARNING
,
1917 ("zip_reply_GLZ: no len for index=%d\n",
1926 else /* set the "last flag" bit in the reply */
1929 else /* set the "last flag" bit in the reply */
1934 if (ZonesInPacket
== ZoneCount
)
1938 /* fill up the ddp header for reply */
1940 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1941 UAS_ASSIGN(r_ddp
->checksum
, 0);
1943 NET_ASSIGN(r_ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1944 NET_NET(r_ddp
->dst_net
, ddp
->src_net
);
1946 r_ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1947 r_ddp
->dst_node
= ddp
->src_node
;
1949 r_ddp
->dst_socket
= ddp
->src_socket
;
1950 r_ddp
->src_socket
= ZIP_SOCKET
;
1951 r_ddp
->type
= DDP_ATP
;
1953 /* fill up the atp header */
1954 r_atp
->cmd
= ATP_CMD_TRESP
;
1960 UAS_UAS(r_atp
->tid
, atp
->tid
);
1961 ulongtmp
= ((last_flag
<< 24) & 0xFF000000) + ZonesInPacket
; /* # of zones and flag*/
1962 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
);
1963 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ packet_len
;
1965 DDPLEN_ASSIGN(r_ddp
, size
);
1967 /* all set to send the packet back up */
1969 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1970 ("zip_r_GLZ: send packet to %d:%d port %d atp_len =%d\n",
1971 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, ifID
->ifPort
, packet_len
));
1973 if (status
= ddp_router_output(rm
, ifID
, AT_ADDR
,
1974 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, 0)) {
1975 dPrintf(D_M_ZIP
, D_L_ERROR
,
1976 ("zip_reply_to_GLZ: ddp_router_output returns =%d\n",
1981 } /* zip_reply_to_getlocalzones */
1983 int regDefaultZone(ifID
)
1987 char data
[ETHERNET_ADDR_LEN
];
1992 zt_get_zmcast(ifID
, &ifID
->ifZoneName
, data
);
1993 if (FDDI_OR_TOKENRING(ifID
->aa_ifp
->if_type
))
1994 ddp_bit_reverse(data
);
1995 bcopy((caddr_t
)data
, (caddr_t
)&ifID
->ZoneMcastAddr
, ETHERNET_ADDR_LEN
);
1996 (void)at_reg_mcast(ifID
, (caddr_t
)&ifID
->ZoneMcastAddr
);