2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright (c) 1988-1998 Apple Computer, Inc.
34 * 0.01 05/12/94 Laurent Dumont Creation
36 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
40 * Router ZIP protocol functions:
42 * This file contains Routing specifics to handle ZIP requests and responses
43 * sent and received by a router node.
45 * The entry point for the zip input in ddp is valid only when we're
46 * running in router mode.
50 #include <sys/errno.h>
51 #include <sys/types.h>
52 #include <sys/param.h>
53 #include <machine/spl.h>
54 #include <sys/systm.h>
55 #include <sys/kernel.h>
57 #include <sys/filedesc.h>
58 #include <sys/fcntl.h>
60 #include <sys/ioctl.h>
61 #include <sys/malloc.h>
62 #include <sys/socket.h>
63 #include <sys/socketvar.h>
66 #include <net/if_types.h>
68 #include <netat/sysglue.h>
69 #include <netat/appletalk.h>
70 #include <netat/at_var.h>
71 #include <netat/ddp.h>
72 #include <netat/nbp.h>
73 #include <netat/zip.h>
74 #include <netat/at_pcb.h>
75 #include <netat/atp.h>
76 #include <netat/routing_tables.h>
77 #include <netat/debug.h>
79 #include <sys/kern_event.h>
81 static void zip_reply_to_getmyzone();
82 extern int at_reg_mcast(), at_unreg_mcast();
85 extern at_ifaddr_t
*ifID_table
[], *ifID_home
;
86 extern short ErrorZIPoverflow
;
88 /**********************************************************************
90 * ZIP is implemented as a "peer" of DDP, so the packets coming in
91 * to ZIP have the same headers as those coming in to DDP {ddp...}.
92 * Same applies to outgoing packets. Also, unlike DDP, ZIP assumes
93 * that an incoming packet is in a contiguous gbuf_t.
95 **********************************************************************/
97 static int netinfo_reply_pending
;
98 static void zip_netinfo_reply(at_x_zip_t
*, at_ifaddr_t
*);
99 static void zip_getnetinfo(at_ifaddr_t
*);
100 static void zip_getnetinfo_locked(void *);
101 static void send_phony_reply(void *);
104 * zip_send_getnetinfo_reply: we received a GetNetInfo packet, we need to reply
105 * with the right information for the port.
107 static void zip_send_getnetinfo_reply(m
, ifID
)
109 register at_ifaddr_t
*ifID
;
113 at_ddp_t
*ddp
, *ddp_sent
;
114 short ZoneNameProvided
= FALSE
;
115 short RequestIsBroadcasted
= FALSE
;
116 u_short znumber
, len
, packet_length
, size
, status
;
120 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
122 /* access the Zone Name info part of the GetNetInfo Request */
124 zname
= (at_nvestr_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
+ 6);
126 if (zname
->len
> ZIP_MAX_ZONE_LENGTH
) {
127 dPrintf(D_M_ZIP
, D_L_WARNING
,
128 ("zip_s_gni_r: zone len too long l=%d ddplen=%d\n",
129 zname
->len
, DDPLEN_VALUE(ddp
)));
135 ZoneNameProvided
= TRUE
;
137 GNIReply
[0] = ZIP_NETINFO_REPLY
;
138 GNIReply
[1] = ZIP_ZONENAME_INVALID
;
140 /* check if we are the originator is in the cable range for this interface */
142 if ((NET_VALUE(ddp
->src_net
) < CableStart
|| NET_VALUE(ddp
->src_net
) > CableStop
) &&
143 (NET_VALUE(ddp
->dst_net
) == 0 && ddp
->dst_node
== 0xff)) {
144 RequestIsBroadcasted
= TRUE
;
146 Entry
= rt_blookup(CableStop
);
148 if (Entry
!= NULL
&& RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
150 GNIReply
[2] = (Entry
->NetStart
& 0xFF00) >> 8;
151 GNIReply
[3] = (Entry
->NetStart
& 0x00FF);
152 GNIReply
[4] = (Entry
->NetStop
& 0xFF00) >> 8;
153 GNIReply
[5] = (Entry
->NetStop
& 0x00FF);
155 /* copy the zone name found in the request */
157 GNIReply
[6] = zname
->len
;
158 bcopy(&zname
->str
, &GNIReply
[7], zname
->len
);
161 if (znumber
= zt_find_zname(zname
)) {
163 if (ZT_ISIN_ZMAP((znumber
), Entry
->ZoneBitMap
)) {
165 GNIReply
[1] = 0; /* Zone Valid */
167 if (len
= zt_get_zmcast(ifID
, zname
, &GNIReply
[8+zname
->len
]))
168 GNIReply
[7+zname
->len
] = len
;
170 GNIReply
[1] |= ZIP_USE_BROADCAST
;
171 GNIReply
[7+zname
->len
] = 0; /* multicast address length */
173 packet_length
= 8 + zname
->len
+ len
;
179 else { /* should not happen, we are supposed to know our net */
180 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_s_gni_r: Don't know about our zone infos!!!\n"));
184 if (zt_ent_zcount(Entry
) == 1)
185 GNIReply
[1] |= ZIP_ONE_ZONE
;
187 if (GNIReply
[1] & ZIP_ZONENAME_INVALID
) {
189 short Index
= ifID
->ifDefZone
;
191 if (Index
<= 0 || Index
>= ZT_MAXEDOUT
) {
192 dPrintf(D_M_ZIP
, D_L_WARNING
,
193 ("zip_s_gni_r: Invalid starting index =%d port%d\n",
194 Index
, ifID
->ifPort
));
201 if (len
= zt_get_zmcast(ifID
, &ZT_table
[Index
].Zone
, &GNIReply
[8+zname
->len
]))
202 GNIReply
[7+zname
->len
] = len
;
204 GNIReply
[1] |= ZIP_USE_BROADCAST
;
205 GNIReply
[7+zname
->len
] = 0; /* multicast address length */
208 packet_length
= 7 + zname
->len
+ len
;
210 /* in the case the zone name asked for in the request was invalid, we need
211 * to copy the good default zone for this net
214 GNIReply
[packet_length
+ 1] = ZT_table
[Index
].Zone
.len
;
215 bcopy(&ZT_table
[Index
].Zone
.str
, &GNIReply
[packet_length
+ 2],
216 ZT_table
[Index
].Zone
.len
);
217 packet_length
= packet_length
+2 + ZT_table
[Index
].Zone
.len
;
222 * we're finally ready to send out the GetNetInfo Reply
227 size
= DDP_X_HDR_SIZE
+ packet_length
;
228 if ((m_sent
= gbuf_alloc(AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
229 return; /* was return(ENOBUFS); */
232 gbuf_rinc(m_sent
,AT_WR_OFFSET
);
233 gbuf_wset(m_sent
,size
);
234 ddp_sent
= (at_ddp_t
*)(gbuf_rptr(m_sent
));
236 /* Prepare the DDP header */
238 ddp_sent
->unused
= ddp_sent
->hopcount
= 0;
239 UAS_ASSIGN(ddp
->checksum
, 0);
240 DDPLEN_ASSIGN(ddp_sent
, size
);
241 NET_ASSIGN(ddp_sent
->src_net
, ifID
->ifThisNode
.s_net
);
242 ddp_sent
->src_node
= ifID
->ifThisNode
.s_node
;
243 ddp_sent
->src_socket
= ZIP_SOCKET
;
244 ddp_sent
->dst_socket
= ddp
->src_socket
;
246 if (RequestIsBroadcasted
) { /* if this was a broadcast, must respond from that */
248 NET_ASSIGN(ddp_sent
->dst_net
, 0);
249 ddp_sent
->dst_node
= 0xFF;
253 NET_NET(ddp_sent
->dst_net
, ddp
->src_net
);
254 ddp_sent
->dst_node
= ddp
->src_node
;
256 ddp_sent
->type
= DDP_ZIP
;
258 bcopy(&GNIReply
, &ddp_sent
->data
, packet_length
);
260 dPrintf(D_M_ZIP_LOW
, D_L_ROUTING
,
261 ("zip_s_gni_r: send to %d:%d port#%d pack_len=%d\n",
262 NET_VALUE(ddp_sent
->dst_net
), ddp_sent
->dst_node
,
263 ifID
->ifPort
, packet_length
));
265 ddp_router_output(m_sent
, ifID
, AT_ADDR
,
266 NET_VALUE(ddp_sent
->dst_net
), ddp_sent
->dst_node
, 0))) {
267 dPrintf(D_M_ZIP
, D_L_ERROR
,
268 ("zip_s_gni_r: ddp_router_output returns =%d\n", status
));
269 return; /* was return(status); */
271 } /* zip_send_getnetinfo_reply */
275 * build_ZIP_reply_packet: is used to create and send a DDP packet and use the
276 * provided buffer as a ZIP reply. This is used by zip_send_ext_reply_to_query
277 * and zip_send_reply_to_query for sending their replies to ZIP queries.
279 gbuf_t
*prep_ZIP_reply_packet(m
, ifID
)
280 register gbuf_t
*m
; /* this is the original zip query */
281 register at_ifaddr_t
*ifID
;
283 register gbuf_t
*m_sent
;
284 register at_ddp_t
*ddp
, *src_ddp
;
286 /* access the source Net and Node informations */
288 src_ddp
= (at_ddp_t
*)gbuf_rptr(m
);
290 if ((m_sent
= gbuf_alloc (AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
291 return((gbuf_t
*)NULL
);
293 gbuf_rinc(m_sent
,AT_WR_OFFSET
);
294 gbuf_wset(m_sent
,DDP_X_HDR_SIZE
);
295 ddp
= (at_ddp_t
*)(gbuf_rptr(m_sent
));
297 /* Prepare the DDP header */
299 ddp
->unused
= ddp
->hopcount
= 0;
300 UAS_ASSIGN(ddp
->checksum
, 0);
302 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
303 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
304 ddp
->src_socket
= ZIP_SOCKET
;
306 ddp
->dst_socket
= src_ddp
->src_socket
;
307 NET_NET(ddp
->dst_net
, src_ddp
->src_net
);
308 ddp
->dst_node
= src_ddp
->src_node
;
315 * zip_send_ext_reply_to_query: this function deals with ZIP Queries for extended nets.
316 * When we recognize an extended net (that might have several zone name associated with
317 * it), we send A SEPARATE ZIP reply for that network. This is called from the
318 * regular zip_send_reply_to_query, that just deals with non-ext nets.
321 static void zip_send_ext_reply_to_query(mreceived
, ifID
, Entry
, NetAsked
)
322 register gbuf_t
*mreceived
;
323 register at_ifaddr_t
*ifID
;
324 RT_entry
*Entry
; /* info about the network we're looking for */
328 register at_ddp_t
*ddp
;
329 short i
, j
, reply_length
, Index
, zone_count
, status
;
331 char *ReplyBuff
, *ZonesInPacket
;
333 zone_count
= zt_ent_zcount(Entry
);
334 zmap
= Entry
->ZoneBitMap
;
340 if (!(m
= prep_ZIP_reply_packet (mreceived
, ifID
))) {
341 return; /* was return(ENOBUFS); */
344 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
345 ReplyBuff
= (char *)(ddp
->data
);
348 *ReplyBuff
++ = 8; /* ZIP function = 8 [extended reply] */
350 ZonesInPacket
= ReplyBuff
;
353 reply_length
= 2; /* 1st byte is ZIP reply code, 2nd is network count */
356 /* For all zones, we check if they belong to the map for that Network */
358 for (; i
>= 0; i
--) {
360 /* find the zones defined in this entry bitmap */
364 if (zmap
[i
] << j
& 0x80) { /* bingo */
366 Index
= i
*8 + j
; /* zone index in zone table */
368 if (reply_length
+ 3 + ZT_table
[Index
].Zone
.len
> DDP_DATA_SIZE
) {
370 /* we need to send the packet before, this won't fit... */
372 zone_count
-= *ZonesInPacket
;
374 DDPLEN_ASSIGN(ddp
, reply_length
+ DDP_X_HDR_SIZE
);
375 gbuf_winc(m
,reply_length
);
377 ddp_router_output(m
, ifID
, AT_ADDR
,
378 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, 0))) {
379 dPrintf(D_M_ZIP
, D_L_ERROR
,
380 ("zip_s_ext_repl: ddp_router_output returns =%d\n",
382 return; /* was return (status); */
388 /* this should fit in this packet, build the NetNumber, ZoneLen,
392 if (ZT_table
[Index
].Zone
.len
) {
393 *ZonesInPacket
+= 1; /* bump NetCount field */
394 *ReplyBuff
++ = (NetAsked
& 0xFF00) >> 8;
395 *ReplyBuff
++ = (NetAsked
& 0x00FF) ;
396 *ReplyBuff
++ = ZT_table
[Index
].Zone
.len
;
398 bcopy(&ZT_table
[Index
].Zone
.str
, ReplyBuff
,
399 ZT_table
[Index
].Zone
.len
);
401 ReplyBuff
+= ZT_table
[Index
].Zone
.len
;
402 reply_length
+= ZT_table
[Index
].Zone
.len
+3;
407 j
= 0; /* reset the bit count */
410 /* if we have some zone info in a half-empty packet, send it now.
411 * Remember, for extended nets we send *at least* one Reply
415 DDPLEN_ASSIGN(ddp
, reply_length
+ DDP_X_HDR_SIZE
);
416 gbuf_winc(m
,reply_length
);
418 ddp_router_output(m
, ifID
, AT_ADDR
,
419 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, 0))) {
420 dPrintf(D_M_ZIP
, D_L_ERROR
,
421 ("zip_s_ext_reply: ddp_router_output returns =%d\n", status
));
422 return; /* was return (status); */
425 else /* free the buffer not used */
428 } /* zip_send_ext_reply_to_query */
431 * zip_send_reply_to_query: we received a ZIPQuery packet, we need to reply
432 * with the right information for the nets requested (if we have
433 * the right information.
435 static void zip_send_reply_to_query(mreceived
, ifID
)
436 register gbuf_t
*mreceived
;
437 register at_ifaddr_t
*ifID
;
440 register at_ddp_t
*ddp
, *ddp_received
;
442 short i
, reply_length
, Index
, status
;
443 u_char network_count
;
445 char *ReplyBuff
, *ZonesInPacket
;
447 ddp_received
= (at_ddp_t
*)gbuf_rptr(mreceived
);
449 /* access the number of nets requested in the Query */
450 network_count
= *((char *)(ddp_received
->data
) + 1);
451 NetAsked
= (u_short
*)(ddp_received
->data
+ 2);
453 /* check the validity of the Query packet */
455 if (DDPLEN_VALUE(ddp_received
) !=
456 (2 + network_count
* 2 + DDP_X_HDR_SIZE
)) {
458 dPrintf(D_M_ZIP
, D_L_WARNING
,
459 ("zip_s_reply_to_q: bad length netcount=%d len=%d\n",
460 network_count
, DDPLEN_VALUE(ddp
)));
461 return; /* was return(1); */
464 /* walk the Query Network list */
465 /* we want to build a response with the network number followed by the zone name
466 * length and the zone name. If there is more than one zone per network asked,
467 * we repeat the network number and stick the zone length and zone name.
468 * We need to be carefull with the max DDP size for data. If we see that a new
469 * NetNum, ZoneLen, ZoneName sequence won't fit, we send the previous packet and
470 * begin to build a new one.
475 if (!(m
= prep_ZIP_reply_packet (mreceived
, ifID
))) {
476 return; /* was return(ENOBUFS); */
479 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
480 ReplyBuff
= (char *)(ddp
->data
);
482 *ReplyBuff
++ = 2; /* ZIP function = 2 [Non extended reply] */
483 ZonesInPacket
= ReplyBuff
;
486 reply_length
= 2; /* 1st byte is ZIP reply code, 2nd is network count */
488 for (i
= 0 ; i
< network_count
; i
++, NetAsked
++) {
489 Entry
= rt_blookup(*NetAsked
);
491 if (Entry
!= NULL
&& ((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
492 RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
494 if (Entry
->NetStart
== 0) { /* asking for a NON EXTENDED network */
496 if ( (Index
= zt_ent_zindex(Entry
->ZoneBitMap
)) == 0)
501 if (reply_length
+ 3 + ZT_table
[Index
].Zone
.len
> DDP_DATA_SIZE
) {
503 /* we need to send the packet before, this won't fit... */
505 DDPLEN_ASSIGN(ddp
, reply_length
+ DDP_X_HDR_SIZE
);
506 gbuf_winc(m
,reply_length
);
509 ddp_router_output(m
, ifID
, AT_ADDR
,
510 NET_VALUE(ddp
->dst_net
),
511 ddp
->dst_node
, 0))) {
512 dPrintf(D_M_ZIP
, D_L_ERROR
,
513 ("zip_s_reply: ddp_router_output returns =%d\n",
515 return; /* was return (status); */
518 /* this is not nice, I know, but we reenter the loop with
519 * a packet is sent with the next network field in the Query
527 /* this should fit in this packet, build the NetNumber, ZoneLen,
531 if (ZT_table
[Index
].Zone
.len
) {
532 ZonesInPacket
+= 1; /* bump NetCount field */
533 *ReplyBuff
++ = (*NetAsked
& 0xFF00) >> 8;
534 *ReplyBuff
++ = (*NetAsked
& 0x00FF) ;
535 *ReplyBuff
++ = ZT_table
[Index
].Zone
.len
;
536 bcopy(&ZT_table
[Index
].Zone
.str
, ReplyBuff
,
537 ZT_table
[Index
].Zone
.len
);
539 ReplyBuff
+= ZT_table
[Index
].Zone
.len
;
541 reply_length
+= ZT_table
[Index
].Zone
.len
+ 3;
548 else { /* extended network, check for multiple zone name attached
549 * and build a separate packet for each extended network requested
552 zip_send_ext_reply_to_query(mreceived
, ifID
, Entry
, *NetAsked
);
558 /* If we have a non extended packet (code 2) with some stuff in it,
559 * we need to send it now
562 if ( reply_length
> 2) {
563 DDPLEN_ASSIGN(ddp
, reply_length
+ DDP_X_HDR_SIZE
);
564 gbuf_winc(m
,reply_length
);
566 ddp_router_output(m
, ifID
, AT_ADDR
,
567 NET_VALUE(ddp
->dst_net
),
568 ddp
->dst_node
, 0))) {
569 dPrintf(D_M_ZIP
, D_L_ERROR
,
570 ("zip_send_reply: ddp_router_output returns =%d\n", status
));
571 return; /* was return (status); */
574 else /* free the buffer not used */
576 } /* zip_send_reply_to_query */
578 /***********************************************************************
581 **********************************************************************/
583 void zip_router_input (m
, ifID
)
585 register at_ifaddr_t
*ifID
;
587 register at_ddp_t
*ddp
;
588 register at_atp_t
*atp
;
589 register at_zip_t
*zip
;
590 register u_long user_bytes
;
591 register u_short user_byte
;
593 /* variables for ZipNotify processing */
594 register char old_zone_len
;
595 register char new_zone_len
;
596 register char *old_zone
;
598 void zip_sched_getnetinfo(); /* forward reference */
600 if (gbuf_type(m
) != MSG_DATA
) {
601 /* If this is a M_ERROR message, DDP is shutting down,
602 * nothing to do here...If it's something else, we don't
603 * understand what it is
605 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_router_input: not an M_DATA message\n"));
611 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_router_input: BAD ifID\n"));
617 * The ZIP listener receives two types of requests:
619 * ATP requests: GetZoneList, GetLocalZone, or GetMyZone
620 * ZIP requests: Netinfo, Query, Reply, takedown, bringup
623 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
625 if (ddp
->type
== DDP_ZIP
) {
626 zip
= (at_zip_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
627 dPrintf(D_M_ZIP_LOW
, D_L_INPUT
,
628 ("zip_input: received a ZIP_DDP command=%d\n",
630 switch (zip
->command
) {
631 case ZIP_QUERY
: /* we received a Zip Query request */
632 dPrintf(D_M_ZIP
, D_L_INPUT
,
633 ("zip_input: Received a Zip Query in from %d.%d\n",
634 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
636 if (!RT_LOOKUP_OKAY(ifID
, ddp
)) {
637 dPrintf(D_M_ZIP
, D_L_INPUT
,
638 ("zip_input:: refused ZIP_QUERY from %d:%d\n",
639 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
642 zip_send_reply_to_query(m
, ifID
);
646 case ZIP_REPLY
: /* we received a Zip Query Reply packet */
647 case ZIP_EXTENDED_REPLY
:
648 if (ifID
->ifRoutingState
== PORT_OFFLINE
) {
649 dPrintf(D_M_ZIP
, D_L_INPUT
,
650 ("zip_input: Received a Zip Reply in user mode\n"));
653 zip_reply_received(m
, ifID
, zip
->command
);
658 /* we received a Zip Takedown packet */
659 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_input: Received a Zip takedown!!!\n"));
664 /* we received a Zip BringUp packet */
665 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_input: Received a Zip BringUp!!!\n"));
669 case ZIP_GETNETINFO
: /* we received a GetNetInfo request */
670 dPrintf(D_M_ZIP
, D_L_INPUT
,
671 ("zip_input: Received a GetNetInfo Req in from %d.%d\n",
672 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
673 if (RT_LOOKUP_OKAY(ifID
, ddp
)) {
674 dPrintf(D_M_ZIP
, D_L_OUTPUT
,
675 ("zip_input: we, as node %d:%d send GNI reply to %d:%d\n",
676 ifID
->ifThisNode
.s_net
, ifID
->ifThisNode
.s_node
,
677 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
678 zip_send_getnetinfo_reply(m
, ifID
);
684 case ZIP_NETINFO_REPLY
:
686 /* If we are not waiting for a GetNetInfo reply
687 * to arrive, this must be a broadcast
688 * message for someone else on the zone, so
689 * no need to even look at it!
692 ((NET_VALUE(ddp
->src_net
) != ifID
->ifThisNode
.s_net
) ||
693 (ddp
->src_node
!= ifID
->ifThisNode
.s_node
)) && netinfo_reply_pending
)
695 extern void trackrouter();
696 dPrintf(D_M_ZIP
, D_L_INPUT
,
697 ("zip_input: Received a GetNetInfo Reply from %d.%d\n",
698 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
699 trackrouter(ifID
, NET_VALUE(ddp
->src_net
), ddp
->src_node
);
700 zip_netinfo_reply((at_x_zip_t
*)zip
, ifID
);
707 /* processing of ZipNotify message : first, change
708 * our zone name, then if NIS is open, let NBP demon
709 process know of this change...(just forward the
712 /* First, check if this is really a packet for us */
713 old_zone
= &zip
->data
[4];
714 if (!zonename_equal(&ifID
->ifZoneName
,
715 (at_nvestr_t
*)old_zone
)) {
716 /* the old zone name in the packet is not the
717 * same as ours, so this packet couldn't be
724 old_zone_len
= *old_zone
;
725 new_zone_len
= zip
->data
[4 + old_zone_len
+ 1];
726 new_zone
= old_zone
+ old_zone_len
;
728 /* Reset the zone multicast address */
729 (void)at_unreg_mcast(ifID
, (caddr_t
)&ifID
->ZoneMcastAddr
);
730 bzero((caddr_t
)&ifID
->ZoneMcastAddr
, ETHERNET_ADDR_LEN
);
732 /* change the zone name - copy both the length and the string */
733 bcopy((caddr_t
)new_zone
, (caddr_t
)&ifID
->ifZoneName
,
736 /* Send network zone change event and new zone for this interface. */
737 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONEUPDATED
, 0, &(ifID
->ifZoneName
));
738 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONELISTCHANGED
, 0, 0);
740 /* add the new zone to the list of local zones */
741 if (!MULTIPORT_MODE
&& !DEFAULT_ZONE(&ifID
->ifZoneName
))
742 (void)setLocalZones(&ifID
->ifZoneName
,
743 (ifID
->ifZoneName
.len
+1));
745 /* Before trying to request our new multicast address,
746 * wait a while... someone might have alredy requested
747 * it, so we may see some broadcast messages flying
748 * by... Set up the structures so that it appears that
749 * we have already requested the NetInfo.
751 ifID
->ifNumRetries
= ZIP_NETINFO_RETRIES
;
752 netinfo_reply_pending
= 1;
753 ifID
->ifGNIScheduled
= 1;
754 timeout(zip_sched_getnetinfo
, (caddr_t
) ifID
,
760 routing_needed(m
, ifID
, TRUE
);
764 else if (ddp
->type
== DDP_ATP
&&
765 RT_LOOKUP_OKAY(ifID
, ddp
)) {
766 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
767 atp
= (at_atp_t
*)(gbuf_rptr(m
)+DDP_X_HDR_SIZE
);
769 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
771 /* Get the user bytes in network order */
773 user_bytes
= UAL_VALUE(atp
->user_bytes
);
774 user_byte
= user_bytes
>> 24; /* Get the zeroth byte */
776 dPrintf(D_M_ZIP
, D_L_INPUT
,
777 ("zip_input: received a ZIP_ATP command=%d\n", user_byte
));
781 zip_reply_to_getmyzone(ifID
, m
);
785 case ZIP_GETZONELIST
:
786 zip_reply_to_getzonelist(ifID
, m
);
790 case ZIP_GETLOCALZONES
:
791 zip_reply_to_getlocalzones(ifID
, m
);
796 dPrintf(D_M_ZIP
, D_L_WARNING
,
797 ("zip_input: received unknown ZIP_ATP command=%d\n", user_byte
));
798 routing_needed(m
, ifID
, TRUE
);
805 } /* zip_router_input */
807 /***********************************************************************
812 **********************************************************************/
813 int zonename_equal (zone1
, zone2
)
814 register at_nvestr_t
*zone1
, *zone2
;
816 register char c1
, c2
;
820 if (zone1
->len
!= zone2
->len
)
823 for (i
=0; i
< (int) zone1
->len
; i
++) {
826 if (c1
>= 'a' && c1
<= 'z')
828 if (c2
>= 'a' && c2
<= 'z')
846 static unsigned char lower_case
[] =
847 {0x8a, 0x8c, 0x8d, 0x8e, 0x96, 0x9a, 0x9f, 0xbe,
848 0xbf, 0xcf, 0x9b, 0x8b, 0x88, 0};
849 static unsigned char upper_case
[] =
850 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0xae,
851 0xaf, 0xce, 0xcd, 0xcc, 0xcb, 0};
853 for (i
=0; lower_case
[i
]; i
++)
854 if (ch
== lower_case
[i
])
855 return (upper_case
[i
]);
861 /***********************************************************************
862 * zip_netinfo_reply ()
866 **********************************************************************/
867 static void zip_netinfo_reply (netinfo
, ifID
)
868 register at_x_zip_t
*netinfo
;
869 register at_ifaddr_t
*ifID
;
872 void zip_sched_getnetinfo(); /* forward reference */
873 register at_net_al this_net
;
875 register u_char zone_name_len
;
877 /* There may be multiple zones on the cable.... we need to
878 * worry about whether or not this packet is addressed
881 /* *** Do we really need to check this? *** */
882 if (!zonename_equal((at_nvestr_t
*)netinfo
->data
, &ifID
->ifZoneName
)) {
883 dPrintf(D_M_ZIP
, D_L_INFO
, ("zip_netinfo_reply, !zonename_equal!!!"));
887 ifID
->ifThisCableStart
= NET_VALUE(netinfo
->cable_range_start
);
888 ifID
->ifThisCableEnd
= NET_VALUE(netinfo
->cable_range_end
);
889 dPrintf(D_M_ZIP
, D_L_OUTPUT
, ("Zip_netinfo_reply: Set cable to %d-%d\n",
890 ifID
->ifThisCableStart
, ifID
->ifThisCableEnd
));
892 /* The packet is in response to our request */
893 ifID
->ifGNIScheduled
= 0;
894 untimeout (zip_sched_getnetinfo
, (caddr_t
) ifID
);
895 netinfo_reply_pending
= 0;
896 zone_name_len
= netinfo
->data
[0];
897 mcast_len
= netinfo
->data
[zone_name_len
+ 1];
899 if (netinfo
->flags
& ZIP_ZONENAME_INVALID
) {
900 /* copy out the default zone name from packet */
901 default_zone
= (char *)&netinfo
->data
[zone_name_len
+1+mcast_len
+1];
902 bcopy((caddr_t
)default_zone
, (caddr_t
)&ifID
->ifZoneName
,
906 /* add the new zone to the list of local zones */
907 if (!MULTIPORT_MODE
&& !DEFAULT_ZONE(&ifID
->ifZoneName
))
908 (void)setLocalZones(&ifID
->ifZoneName
, (ifID
->ifZoneName
.len
+1));
910 /* get the multicast address out of the GetNetInfo reply, if there is one */
911 if (!(netinfo
->flags
& ZIP_USE_BROADCAST
)) {
912 /* If ZIP_USE_BROADCAST is set, we will use the cable
913 broadcast address as the multicast address, however
914 the cable multicast address has already been registered.
916 /* This packet contains a multicast address, so
917 * send to elap to register it.
919 if (FDDI_OR_TOKENRING(ifID
->aa_ifp
->if_type
))
920 ddp_bit_reverse(&netinfo
->data
[zone_name_len
+ 2]);
922 bcopy((caddr_t
)&netinfo
->data
[zone_name_len
+ 2],
923 (caddr_t
)&ifID
->ZoneMcastAddr
, ETHERNET_ADDR_LEN
);
924 (void)at_reg_mcast(ifID
, (caddr_t
)&ifID
->ZoneMcastAddr
);
927 this_net
= ifID
->ifThisNode
.s_net
;
928 if ((this_net
>= ifID
->ifThisCableStart
) &&
929 (this_net
<= ifID
->ifThisCableEnd
)) {
930 /* ThisNet is in the range of valid network numbers
931 * for the cable. Do nothing.
934 /* ThisNet is not in the range of valid network
935 * numbers for the cable. This may be either because
936 * the chosen number was from start-up range, or
937 * because the user has a misconception of where the
938 * machine is!! Since ThisCableRange is set up, next
939 * time aarp is invoked, it would select address in
943 /* to reset initial_net and initial_node to zero, so
944 * that aarp is forced to choose new values
946 ifID
->initial_addr
.s_net
= 0;
947 ifID
->initial_addr
.s_node
= 0;
949 /* Wake up elap_online sleeping on this interface. */
950 ZIPwakeup(ifID
, ZIP_RE_AARP
);
954 if (!ifID
->startup_inprogress
) {
955 /* Send event with zone info. This covers case where we get zone info
956 after startup. During startup this event is sent from ZIPwakeup. */
957 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONEUPDATED
, 0, &(ifID
->ifZoneName
));
960 ZIPwakeup(ifID
, 0); /* no error */
962 } /* zip_netinfo_reply */
965 /**********************************************************************
968 **********************************************************************/
969 int zip_control (ifID
, control
)
970 register at_ifaddr_t
*ifID
;
973 dPrintf(D_M_ZIP
, D_L_INFO
, ("zip_control called port=%d control=%d\n",
974 ifID
->ifPort
, control
));
977 case ZIP_LATE_ROUTER
:
978 if (!ifID
->ifGNIScheduled
) {
979 ifID
->ifNumRetries
= 0;
980 /* Get the desired zone name from elap and put it in
981 * ifID for zip_getnetinfo() to use.
983 if (ifID
->startup_zone
.len
)
984 ifID
->ifZoneName
= ifID
->startup_zone
;
985 zip_getnetinfo(ifID
);
989 ifID
->ifZoneName
.len
= 1;
990 ifID
->ifZoneName
.str
[0] = '*';
991 ifID
->ifZoneName
.str
[1] = '\0';
993 /* Send event with zone info. */
994 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONEUPDATED
, 0, &(ifID
->ifZoneName
));
1003 /* locked version of zip_getnetinfo */
1004 static void zip_getnetinfo_locked(arg
)
1010 if (ifID
!= NULL
) { // make sure it hasn't been closed
1011 ifID
= (at_ifaddr_t
*)arg
;
1012 ifID
->ifGNIScheduled
= 0;
1013 zip_getnetinfo(ifID
);
1019 /**********************************************************************
1022 **********************************************************************/
1023 static void zip_getnetinfo (ifID
)
1024 register at_ifaddr_t
*ifID
;
1026 register at_x_zip_t
*zip
;
1028 register at_ddp_t
*ddp
;
1029 void zip_sched_getnetinfo();
1030 register struct atalk_addr
*at_dest
;
1034 size
= DDP_X_HDR_SIZE
+ ZIP_X_HDR_SIZE
+ ifID
->ifZoneName
.len
+ 1
1035 + sizeof(struct atalk_addr
) + 1;
1036 if ((m
= gbuf_alloc (AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
1037 /* This time, we're unable to allocate buffer to
1038 * send a packet out, so schedule to send a packet
1039 * out later, and exit.
1041 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_getnetinfo: no buffer, call later port=%d\n",
1043 ifID
->ifGNIScheduled
= 1;
1044 timeout (zip_getnetinfo_locked
, (caddr_t
) ifID
, ZIP_TIMER_INT
/10);
1048 gbuf_rinc(m
,AT_WR_OFFSET
);
1050 *(u_char
*)gbuf_rptr(m
) = AT_ADDR
;
1051 at_dest
= (struct atalk_addr
*)(gbuf_rptr(m
) + 1);
1052 ddp
= (at_ddp_t
*)(gbuf_rptr(m
) + sizeof(struct atalk_addr
) + 1);
1053 zip
= (at_x_zip_t
*)ddp
->data
;
1056 zip
->command
= ZIP_GETNETINFO
;
1058 NET_ASSIGN(zip
->cable_range_start
, 0);
1059 NET_ASSIGN(zip
->cable_range_end
, 0);
1060 if (ifID
->ifZoneName
.len
) /* has to match reply exactly */
1061 bcopy((caddr_t
)&ifID
->ifZoneName
, (caddr_t
)zip
->data
,
1062 ifID
->ifZoneName
.len
+ 1);
1064 zip
->data
[0] = 0; /* No zone name is availbale */
1066 /* let the lap fields be uninitialized, 'cause it doesn't
1069 DDPLEN_ASSIGN(ddp
, size
- (sizeof(struct atalk_addr
) + 1));
1070 UAS_ASSIGN(ddp
->checksum
, 0);
1071 ddp
->hopcount
= ddp
->unused
= 0;
1072 NET_ASSIGN(ddp
->dst_net
, 0); /* cable-wide broadcast */
1073 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1074 /* By this time, AARP is done */
1076 ddp
->dst_node
= 0xff;
1077 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1078 ddp
->dst_socket
= ZIP_SOCKET
;
1079 ddp
->src_socket
= ZIP_SOCKET
;
1080 ddp
->type
= DDP_ZIP
;
1082 at_dest
->atalk_unused
= 0;
1083 NET_NET(at_dest
->atalk_net
, ddp
->dst_net
);
1084 at_dest
->atalk_node
= ddp
->dst_node
;
1086 dPrintf(D_M_ZIP
, D_L_INPUT
, ("zip_getnetinfo: called for port=%d\n",
1089 if (elap_dataput(m
, ifID
, 0, NULL
)) {
1090 dPrintf(D_M_ZIP
, D_L_ERROR
,
1091 ("zip_getnetinfo: error sending zip_getnetinfo\n"));
1095 ifID
->ifNumRetries
++;
1096 netinfo_reply_pending
= 1;
1097 ifID
->ifGNIScheduled
= 1;
1098 timeout (zip_sched_getnetinfo
, (caddr_t
) ifID
, ZIP_TIMER_INT
);
1099 } /* zip_getnetinfo */
1102 /**********************************************************************
1103 * zip_sched_getnetinfo()
1105 **********************************************************************/
1107 void zip_sched_getnetinfo (ifID
)
1108 register at_ifaddr_t
*ifID
;
1113 ifID
->ifGNIScheduled
= 0;
1115 if (ifID
->ifNumRetries
>= ZIP_NETINFO_RETRIES
) {
1116 /* enough packets sent.... give up! */
1117 /* we didn't get any response from the net, so
1118 * assume there's no router around and the given
1119 * zone name, if any, is not valid. Change the
1122 ifID
->ifZoneName
.len
= 1;
1123 ifID
->ifZoneName
.str
[0] = '*';
1124 ifID
->ifZoneName
.str
[1] = '\0';
1125 /* Should NBP be notified of this "new" zone name?? */
1126 netinfo_reply_pending
= 0;
1128 ifID
->ifRouterState
= NO_ROUTER
;
1129 ifID
->ifARouter
.s_net
= 0;
1130 ifID
->ifARouter
.s_node
= 0;
1132 dPrintf(D_M_ZIP
, D_L_INFO
, ("zip_sched_getnetinfo: Reset Cable Range\n"));
1134 ifID
->ifThisCableStart
= DDP_MIN_NETWORK
;
1135 ifID
->ifThisCableEnd
= DDP_MAX_NETWORK
;
1137 if (ifID
->ifState
== LAP_ONLINE_FOR_ZIP
)
1138 ZIPwakeup (ifID
, 0); /* no error */
1140 zip_getnetinfo(ifID
);
1146 /**********************************************************************
1150 * This routine checks whether or not the packet contained in "m"
1151 * is an (outgoing) ZIP packet. If not, it returns 0. If it is a
1152 * ZIP packet, it returns the ZIP packet type (ZIP command). "m"
1153 * points to a packet with extended DDP header. The rest of the
1154 * DDP data may or may not be in the first gbuf.
1156 **********************************************************************/
1157 int zip_type_packet (m
)
1160 register at_atp_t
*atp
;
1161 register at_ddp_t
*ddp
;
1162 register at_zip_t
*zip
;
1163 register u_long user_bytes
;
1164 register int user_byte
;
1166 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1167 if (ddp
->dst_socket
== ZIP_SOCKET
) {
1168 switch (ddp
->type
) {
1170 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1171 zip
= (at_zip_t
*)(gbuf_rptr(m
)
1174 zip
=(at_zip_t
*)(gbuf_rptr(gbuf_cont(m
)));
1175 return ((int)zip
->command
);
1177 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1178 atp
= (at_atp_t
*)(gbuf_rptr(m
)+DDP_X_HDR_SIZE
);
1180 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1181 /* Get the user bytes in network order */
1182 user_bytes
= UAL_VALUE(atp
->user_bytes
);
1183 user_byte
= user_bytes
>> 24; /* Get the zeroth byte */
1184 if ((user_byte
== ZIP_GETMYZONE
) ||
1185 (user_byte
== ZIP_GETZONELIST
) ||
1186 (user_byte
== ZIP_GETLOCALZONES
))
1197 /**********************************************************************
1198 * zip_handle_getmyzone()
1201 * Routine to handle ZIP GetMyZone request locally. It generates
1202 * a phony response to the outgoing ATP request and sends it up.
1204 * 07/12/94 : remark2 only called from ddp.c / ddp_output
1205 * should only be called from the home port, but
1206 * when we are a router we should know the infos for all
1207 * anyway, so reply locally with what we have in stock...
1209 **********************************************************************/
1211 int zip_handle_getmyzone(ifID
, m
)
1212 register at_ifaddr_t
*ifID
;
1216 register at_ddp_t
*ddp
;
1217 register at_ddp_t
*r_ddp
;
1218 register at_atp_t
*r_atp
;
1219 gbuf_t
*rm
; /* reply message */
1223 dPrintf(D_M_ZIP
, D_L_INFO
,
1224 ("zip_handle_getmyzone: local reply for port=%d\n",
1227 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ 1 + ifID
->ifZoneName
.len
;
1228 /* space for two headers and the zone name */
1229 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
1230 dPrintf(D_M_ZIP
, D_L_WARNING
,
1231 ("zip_handle_getmyzone: no buffer, port=%d\n",
1236 gbuf_rinc(rm
,AT_WR_OFFSET
);
1238 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1239 r_atp
= (at_atp_t
*)r_ddp
->data
;
1242 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1243 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1244 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1246 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1248 /* fill up the ddp header for reply */
1249 DDPLEN_ASSIGN(r_ddp
, size
);
1250 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1251 UAS_ASSIGN(r_ddp
->checksum
, 0);
1252 NET_ASSIGN(r_ddp
->dst_net
, ifID
->ifThisNode
.s_net
);
1253 NET_NET(r_ddp
->src_net
, ddp
->dst_net
);
1254 r_ddp
->dst_node
= ifID
->ifThisNode
.s_node
;
1255 r_ddp
->src_node
= ddp
->dst_node
;
1256 r_ddp
->dst_socket
= ddp
->src_socket
;
1257 r_ddp
->src_socket
= ZIP_SOCKET
;
1258 r_ddp
->type
= DDP_ATP
;
1260 /* fill up the atp header */
1261 r_atp
->cmd
= ATP_CMD_TRESP
;
1267 UAS_UAS(r_atp
->tid
, atp
->tid
);
1269 ulongtmp
= htonl(ulongtmp
);
1270 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
); /* no of zones */
1272 /* fill up atp data part */
1273 bcopy((caddr_t
) &ifID
->ifZoneName
, (caddr_t
) r_atp
->data
, ifID
->ifZoneName
.len
+1);
1275 /* all set to send the packet back up */
1277 timeout(send_phony_reply
, (caddr_t
) rm
, HZ
/20);
1282 send_phony_reply(arg
)
1285 gbuf_t
*rm
= (gbuf_t
*)arg
;
1288 ddp_input(rm
, ifID_home
);
1296 * zip_prep_query_packet: build the actual ddp packet for the zip query
1299 gbuf_t
*zip_prep_query_packet(ifID
, RouterNet
, RouterNode
)
1301 at_net_al RouterNet
; /* we want to send the Zip Query to that router */
1306 register at_ddp_t
*ddp
;
1308 if ((m
= gbuf_alloc (AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
1309 dPrintf(D_M_ZIP
, D_L_WARNING
,
1310 ("zip_send_query_packet: no buffer, port=%d\n",
1312 return((gbuf_t
*)NULL
);
1314 gbuf_rinc(m
,AT_WR_OFFSET
);
1317 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
1319 /* Prepare the DDP header */
1321 ddp
->unused
= ddp
->hopcount
= 0;
1322 UAS_ASSIGN(ddp
->checksum
, 0);
1323 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1324 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1325 ddp
->src_socket
= ZIP_SOCKET
;
1327 ddp
->dst_socket
= ZIP_SOCKET
;
1328 NET_ASSIGN(ddp
->dst_net
, RouterNet
);
1329 ddp
->dst_node
= RouterNode
;
1331 ddp
->type
= DDP_ZIP
;
1334 } /* zip_prep_query_packet */
1338 * zip_send_queries: this function send queries for the routing table entries that
1339 * need to know their zones. It scans the routing table for entries with unknown
1340 * zones and build Query packets accordingly.
1341 * Note: this is called on a per port basis.
1344 void zip_send_queries(ifID
, RouterNet
, RouterNode
)
1345 register at_ifaddr_t
*ifID
;
1346 at_net_al RouterNet
; /* we want to send the Zip Query to that router */
1349 RT_entry
*Entry
= &RT_table
[0];
1351 register at_ddp_t
*ddp
;
1353 short Query_index
, EntryNumber
= 0 ;
1354 register u_char port
= ifID
->ifPort
;
1355 char *QueryBuff
, *ZoneCount
;
1356 short zip_sent
= FALSE
;
1360 if (!(m
= zip_prep_query_packet(ifID
, RouterNet
, RouterNode
))) {
1361 return; /* was return (ENOBUFS); */
1364 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
1365 QueryBuff
= (char *)ddp
->data
;
1367 *QueryBuff
++ = ZIP_QUERY
;
1368 ZoneCount
= QueryBuff
; /* network count */
1374 while (EntryNumber
< RT_maxentry
) {
1376 /* scan the table, and build the packet with the right entries:
1377 * - entry in use and on the right Port
1378 * - with unknwon zones and in an active state
1379 * - talking to the right router
1382 if ((Query_index
) > 2*254 +2) {
1384 /* we need to send the packet now, but we can't have more than 256
1385 * requests for networks: the Netcount field is a 8bit in the zip query
1386 * packet format as defined in Inside Atalk
1389 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1390 ("zip_send_query: FULL query for %d nets on port#%d.(len=%d)\n",
1391 *ZoneCount
, port
, Query_index
));
1394 gbuf_winc(m
,DDP_X_HDR_SIZE
+ Query_index
);
1395 DDPLEN_ASSIGN(ddp
, DDP_X_HDR_SIZE
+ Query_index
);
1398 ddp_router_output(m
, ifID
, AT_ADDR
,
1399 RouterNet
, RouterNode
, 0))) {
1400 dPrintf(D_M_ZIP
, D_L_ERROR
,
1401 ("zip_send_query: ddp_router_output returns =%d\n", status
));
1402 return; /* was return (status); */
1409 if (((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
1410 (Entry
->NetStop
) && (Entry
->NetPort
== port
) &&
1411 (!RT_ALL_ZONES_KNOWN(Entry
))){
1413 /* we're ready to had that to our list of stuff to send */
1415 if (Entry
->NetStart
) { /* extended net*/
1417 *QueryBuff
++ = (Entry
->NetStart
& 0xFF00) >> 8;
1418 *QueryBuff
++ = (Entry
->NetStart
& 0x00FF);
1422 *QueryBuff
++ = (Entry
->NetStop
& 0xFF00) >> 8;
1423 *QueryBuff
++ = (Entry
->NetStop
& 0x00FF);
1427 *ZoneCount
+= 1;/* bump the number of network requested */
1436 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1437 ("zip_send_query: query for %d nets on port#%d.(len=%d)\n",
1438 *ZoneCount
, port
, Query_index
));
1440 if (*ZoneCount
) { /* non-full Query needs to be sent */
1442 gbuf_winc(m
,DDP_X_HDR_SIZE
+ Query_index
);
1443 DDPLEN_ASSIGN(ddp
, DDP_X_HDR_SIZE
+ Query_index
);
1446 ddp_router_output(m
, ifID
, AT_ADDR
,
1447 RouterNet
, RouterNode
, 0))) {
1448 dPrintf(D_M_ZIP
, D_L_ERROR
,
1449 ("zip_send_query: ddp_router_output returns =%d\n",
1451 return; /* was return (status); */
1457 if (!zip_sent
) /* we didn't need to send anything for that port */
1458 ifID
->ifZipNeedQueries
= 0;
1459 } /* zip_send_queries */
1461 /* zip_reply_received: we recieved the reply to one of our query, update the
1462 * zone bitmap and stuffs with was we received.
1463 * we receive two types of replies: non extended and extended.
1464 * For extended replies, the network count is the Total of zones for that net.
1467 zip_reply_received(m
, ifID
, reply_type
)
1469 register at_ifaddr_t
*ifID
;
1472 register at_nvestr_t
*zname
;
1473 RT_entry
*Entry
= &RT_table
[0];
1474 register at_ddp_t
*ddp
;
1476 u_short payload_len
, result
;
1477 u_char network_count
;
1480 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1482 /* access the number of nets provided in the ZIP Reply */
1484 network_count
= *(u_char
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
+ 1);
1486 PacketPtr
= (char *)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
+ 2);
1488 payload_len
= DDPLEN_VALUE(ddp
) - (DDP_X_HDR_SIZE
+ 2);
1490 dPrintf(D_M_ZIP_LOW
, D_L_INPUT
, ("zip_reply_received from %d:%d type=%d netcount=%d\n",
1491 NET_VALUE(ddp
->src_net
), ddp
->src_node
, reply_type
, network_count
));
1494 while (payload_len
> 0 && network_count
>0) {
1496 Network
= *(at_net_al
*)PacketPtr
;
1498 zname
= (at_nvestr_t
*)PacketPtr
;
1500 payload_len
= payload_len
-(zname
->len
+ 3);
1502 if (zname
->len
<= 0) { /* not valid, we got a problem here... */
1503 dPrintf(D_M_ZIP
, D_L_WARNING
,
1504 ("zip_reply_received: Problem zlen=0 for net=%d from %d:%d type=%d netcnt=%d\n",
1505 Network
, NET_VALUE(ddp
->src_net
), ddp
->src_node
, reply_type
, network_count
));
1511 Entry
= rt_blookup(Network
);
1513 if (Entry
!= NULL
) {
1515 if (Entry
->EntryState
>= RTE_STATE_SUSPECT
) {
1517 result
= zt_add_zonename(zname
);
1519 if (result
== ZT_MAXEDOUT
) {
1521 dPrintf(D_M_ZIP
, D_L_ERROR
,
1522 ("zip_reply_received: ZTable full from %d:%d on zone '%s'\n",
1523 NET_VALUE(ddp
->src_net
), ddp
->src_node
, zname
->str
));
1524 ErrorZIPoverflow
= 1;
1528 zt_set_zmap(result
, Entry
->ZoneBitMap
);
1530 RT_SET_ZONE_KNOWN(Entry
);
1534 dPrintf(D_M_ZIP
, D_L_INPUT
,
1535 ("zip_reply_received: entry %d-%d not updated, cause state=%d\n",
1536 Entry
->NetStart
, Entry
->NetStop
, Entry
->EntryState
));
1540 dPrintf(D_M_ZIP
, D_L_WARNING
,
1541 ("zip_reply_received: network %d not found in RT\n", Network
));
1545 /* now bump the PacketPtr pointer */
1546 PacketPtr
+= zname
->len
+ 1;
1550 if ((reply_type
== ZIP_REPLY
) && network_count
> 0) {
1552 dPrintf(D_M_ZIP
, D_L_WARNING
,
1553 ("zip_reply_received: Problem decoding zone (after net:%d-%d)\n",
1554 Entry
->NetStart
, Entry
->NetStop
));
1555 ifID
->ifZipNeedQueries
= 1;
1558 ifID
->ifZipNeedQueries
= 0;
1560 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1561 ("zip_reply_received: entry %d-%d all zones known\n",
1562 Entry
->NetStart
, Entry
->NetStop
));
1567 * zip_reply_to_getmyzone: replies to ZIP GetMyZone received from the Net
1570 static void zip_reply_to_getmyzone (ifID
, m
)
1571 register at_ifaddr_t
*ifID
;
1575 register at_ddp_t
*ddp
;
1576 register at_ddp_t
*r_ddp
;
1577 register at_atp_t
*r_atp
;
1578 register gbuf_t
*rm
; /* reply message */
1579 register int size
, Index
, status
;
1584 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ 1 + ifID
->ifZoneName
.len
;
1585 /* space for two headers and the zone name */
1586 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
1587 dPrintf(D_M_ZIP
, D_L_WARNING
,
1588 ("zip_reply_to_getmyzone: no buffer, port=%d\n", ifID
->ifPort
));
1589 return; /* was return (ENOBUFS); */
1591 gbuf_rinc(rm
,AT_WR_OFFSET
);
1593 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1594 r_atp
= (at_atp_t
*)r_ddp
->data
;
1596 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1597 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1598 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1600 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1602 /* fill up the ddp header for reply */
1603 DDPLEN_ASSIGN(r_ddp
, size
);
1604 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1605 UAS_ASSIGN(r_ddp
->checksum
, 0);
1607 NET_ASSIGN(r_ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1608 NET_NET(r_ddp
->dst_net
, ddp
->src_net
);
1610 r_ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1611 r_ddp
->dst_node
= ddp
->src_node
;
1613 r_ddp
->dst_socket
= ddp
->src_socket
;
1614 r_ddp
->src_socket
= ZIP_SOCKET
;
1615 r_ddp
->type
= DDP_ATP
;
1617 /* fill up the atp header */
1618 r_atp
->cmd
= ATP_CMD_TRESP
;
1624 UAS_UAS(r_atp
->tid
, atp
->tid
);
1626 ulongtmp
= htonl(ulongtmp
);
1627 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
); /* no of zones */
1629 data_ptr
= (char *)r_atp
->data
;
1632 * fill up atp data part with the zone name if we can find it...
1635 Entry
= rt_blookup(NET_VALUE(ddp
->src_net
));
1636 if (Entry
!= NULL
&& ((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
1637 RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
1639 Index
= zt_ent_zindex(Entry
->ZoneBitMap
) -1;
1641 *data_ptr
= ZT_table
[Index
].Zone
.len
;
1642 bcopy((caddr_t
) &ZT_table
[Index
].Zone
.str
, (caddr_t
) ++data_ptr
,
1643 ZT_table
[Index
].Zone
.len
);
1645 /* all set to send the packet back up */
1646 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1647 ("zip_reply_to_GMZ: ddp_router_output to %d:%d port %d\n",
1648 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, ifID
->ifPort
));
1651 ddp_router_output(rm
, ifID
, AT_ADDR
,
1652 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, 0))) {
1653 dPrintf(D_M_ZIP
, D_L_ERROR
,
1654 ("zip_reply_to_GMZ: ddp_r_output returns =%d\n", status
));
1655 return; /* was return (status); */
1663 * zip_reply_to_getzonelist: replies to ZIP GetZoneList requested from the Net
1666 zip_reply_to_getzonelist (ifID
, m
)
1667 register at_ifaddr_t
*ifID
;
1671 register at_ddp_t
*ddp
;
1672 register at_ddp_t
*r_ddp
;
1673 register at_atp_t
*r_atp
;
1674 register gbuf_t
*rm
; /* reply message */
1675 register int size
, status
;
1676 register short Index
=0, StartPoint
, ZLength
, PacketLen
=0;
1680 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1681 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1682 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1684 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1687 /* space for two headers and the zone name */
1689 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
1693 gbuf_rinc(rm
,AT_WR_OFFSET
);
1695 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1696 r_atp
= (at_atp_t
*)r_ddp
->data
;
1698 /* fill up the ddp header for reply */
1700 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1701 UAS_ASSIGN(r_ddp
->checksum
, 0);
1702 NET_ASSIGN(r_ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1703 NET_NET(r_ddp
->dst_net
, ddp
->src_net
);
1704 r_ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1705 r_ddp
->dst_node
= ddp
->src_node
;
1706 r_ddp
->dst_socket
= ddp
->src_socket
;
1707 r_ddp
->src_socket
= ZIP_SOCKET
;
1708 r_ddp
->type
= DDP_ATP
;
1710 /* fill up the atp header */
1712 r_atp
->cmd
= ATP_CMD_TRESP
;
1718 UAS_UAS(r_atp
->tid
, atp
->tid
);
1720 Reply
= (char *)r_atp
->data
;
1722 /* get the start index from the ATP request */
1724 StartPoint
= (UAL_VALUE(atp
->user_bytes
) & 0xffff) -1;
1726 /* find the next zone to send */
1728 while ((Index
< ZT_maxentry
) && StartPoint
> 0) {
1729 if (ZT_table
[Index
].Zone
.len
)
1735 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
, ("zip_reply_to_GZL: Index=%d\n", Index
));
1737 * fill up atp data part with the zone name if we can find it...
1740 while (Index
< ZT_maxentry
) {
1742 ZLength
= ZT_table
[Index
].Zone
.len
;
1744 if (ZT_table
[Index
].ZoneCount
&& ZLength
) {
1747 if (PacketLen
+ 8 + ZLength
+1 > DDP_DATA_SIZE
) /* packet full */
1751 bcopy((caddr_t
) &ZT_table
[Index
].Zone
.str
,
1754 PacketLen
+= ZLength
+ 1;
1760 if (Index
>= ZT_maxentry
) /* this is the end of the list */
1762 ulongtmp
+= 0x01000000;
1765 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
); /* # of zones and flag*/
1767 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ PacketLen
;
1769 DDPLEN_ASSIGN(r_ddp
, size
);
1771 /* all set to send the packet back up */
1773 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1774 ("zip_r_GZL: send packet to %d:%d port %d atp_len =%d\n",
1775 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, ifID
->ifPort
, PacketLen
));
1778 if (status
= ddp_router_output(rm
, ifID
, AT_ADDR
,
1779 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, 0)) {
1780 dPrintf(D_M_ZIP
, D_L_ERROR
, ("zip_reply_to_GZL: ddp_router_output returns=%d\n",
1789 * zip_reply_to_getlocalzones: replies to ZIP GetLocalZones requested from the Net
1792 int zip_reply_to_getlocalzones (ifID
, m
)
1793 register at_ifaddr_t
*ifID
;
1797 register at_ddp_t
*ddp
;
1798 register at_ddp_t
*r_ddp
;
1799 register at_atp_t
*r_atp
;
1800 register gbuf_t
*rm
; /* reply message */
1802 short Index
, Index_wanted
, ZLength
;
1803 short i
,j
, packet_len
;
1804 short zCount
, ZoneCount
, ZonesInPacket
;
1805 char *zmap
, last_flag
= 0;
1809 u_long ulongtmp
= 0;
1811 Index
= Index_wanted
= ZLength
= i
= j
= packet_len
= zCount
= ZoneCount
=
1814 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1815 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1816 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1818 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1820 /* space for two headers and the zone name */
1822 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
1826 gbuf_rinc(rm
,AT_WR_OFFSET
);
1828 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1829 r_atp
= (at_atp_t
*)r_ddp
->data
;
1831 Reply
= (char *)r_atp
->data
;
1834 /* get the start index from the ATP request */
1836 Index_wanted
= (UAL_VALUE(atp
->user_bytes
) & 0xffff) -1;
1838 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1839 ("zip_r_GLZ: for station %d:%d Index_wanted = %d\n",
1840 NET_VALUE(ddp
->src_net
), ddp
->src_node
, Index_wanted
));
1842 Entry
= rt_blookup(NET_VALUE(ddp
->src_net
));
1844 if (Entry
!= NULL
&& ((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
1845 RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
1847 ZoneCount
= zt_ent_zcount(Entry
) ;
1849 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1850 ("zip_reply_GLZ: for %d:%d ZoneCount=%d\n",
1851 NET_VALUE(ddp
->src_net
), ddp
->src_node
, ZoneCount
));
1853 zmap
= &Entry
->ZoneBitMap
[0];
1856 * first of all, we want to find the "first next zone" in the bitmap,
1857 * to do so, we need to scan the bitmap and add the number of valid
1858 * zones we find until we reach the next zone to be sent in the reply
1861 if (ZoneCount
> Index_wanted
) {
1863 ZoneCount
-= Index_wanted
;
1865 /* find the starting point in the bitmap according to index */
1867 for (i
= 0; Index_wanted
>= 0 && i
< ZT_BYTES
; i
++)
1869 if (Index_wanted
< 8) {
1870 /* how many zones in the bitmap byte */
1871 for (j
= 0, zCount
=0; j
< 8 ; j
++)
1872 if ((zmap
[i
] << j
) & 0x80)
1874 if (Index_wanted
< zCount
) {
1875 for (j
= 0 ; Index_wanted
> 0 && j
< 8 ; j
++)
1876 if ((zmap
[i
] << j
) & 0x80)
1881 Index_wanted
-= zCount
;
1884 for (j
= 0 ; j
< 8 ; j
++)
1885 if ((zmap
[i
] << j
) & 0x80)
1890 * now, we point to the begining of our next zones in the bitmap
1893 while (i
< ZT_BYTES
) {
1897 if ((zmap
[i
] << j
) & 0x80) {
1898 Index
= i
*8 + j
; /* get the index in ZT */
1900 ZLength
= ZT_table
[Index
].Zone
.len
;
1902 if (ZT_table
[Index
].ZoneCount
&& ZLength
) {
1903 if (packet_len
+ ATP_HDR_SIZE
+ ZLength
+ 1 >
1908 bcopy((caddr_t
) &ZT_table
[Index
].Zone
.str
,
1911 packet_len
+= ZLength
+ 1;
1913 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1914 ("zip_reply_GLZ: add z#%d to packet (l=%d)\n",
1915 Index
, packet_len
));
1918 dPrintf(D_M_ZIP
, D_L_WARNING
,
1919 ("zip_reply_GLZ: no len for index=%d\n",
1928 else /* set the "last flag" bit in the reply */
1931 else /* set the "last flag" bit in the reply */
1936 if (ZonesInPacket
== ZoneCount
)
1940 /* fill up the ddp header for reply */
1942 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1943 UAS_ASSIGN(r_ddp
->checksum
, 0);
1945 NET_ASSIGN(r_ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1946 NET_NET(r_ddp
->dst_net
, ddp
->src_net
);
1948 r_ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1949 r_ddp
->dst_node
= ddp
->src_node
;
1951 r_ddp
->dst_socket
= ddp
->src_socket
;
1952 r_ddp
->src_socket
= ZIP_SOCKET
;
1953 r_ddp
->type
= DDP_ATP
;
1955 /* fill up the atp header */
1956 r_atp
->cmd
= ATP_CMD_TRESP
;
1962 UAS_UAS(r_atp
->tid
, atp
->tid
);
1963 ulongtmp
= ((last_flag
<< 24) & 0xFF000000) + ZonesInPacket
; /* # of zones and flag*/
1964 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
);
1965 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ packet_len
;
1967 DDPLEN_ASSIGN(r_ddp
, size
);
1969 /* all set to send the packet back up */
1971 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1972 ("zip_r_GLZ: send packet to %d:%d port %d atp_len =%d\n",
1973 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, ifID
->ifPort
, packet_len
));
1975 if (status
= ddp_router_output(rm
, ifID
, AT_ADDR
,
1976 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, 0)) {
1977 dPrintf(D_M_ZIP
, D_L_ERROR
,
1978 ("zip_reply_to_GLZ: ddp_router_output returns =%d\n",
1983 } /* zip_reply_to_getlocalzones */
1985 int regDefaultZone(ifID
)
1989 char data
[ETHERNET_ADDR_LEN
];
1994 zt_get_zmcast(ifID
, &ifID
->ifZoneName
, data
);
1995 if (FDDI_OR_TOKENRING(ifID
->aa_ifp
->if_type
))
1996 ddp_bit_reverse(data
);
1997 bcopy((caddr_t
)data
, (caddr_t
)&ifID
->ZoneMcastAddr
, ETHERNET_ADDR_LEN
);
1998 (void)at_reg_mcast(ifID
, (caddr_t
)&ifID
->ZoneMcastAddr
);