2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1988-1998 Apple Computer, Inc.
26 * 0.01 05/12/94 Laurent Dumont Creation
28 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
32 * Router ZIP protocol functions:
34 * This file contains Routing specifics to handle ZIP requests and responses
35 * sent and received by a router node.
37 * The entry point for the zip input in ddp is valid only when we're
38 * running in router mode.
42 #include <sys/errno.h>
43 #include <sys/types.h>
44 #include <sys/param.h>
45 #include <machine/spl.h>
46 #include <sys/systm.h>
47 #include <sys/kernel.h>
49 #include <sys/filedesc.h>
50 #include <sys/fcntl.h>
52 #include <sys/ioctl.h>
53 #include <sys/malloc.h>
54 #include <sys/socket.h>
55 #include <sys/socketvar.h>
58 #include <net/if_types.h>
60 #include <netat/sysglue.h>
61 #include <netat/appletalk.h>
62 #include <netat/at_var.h>
63 #include <netat/ddp.h>
64 #include <netat/nbp.h>
65 #include <netat/zip.h>
66 #include <netat/at_pcb.h>
67 #include <netat/atp.h>
68 #include <netat/routing_tables.h>
69 #include <netat/debug.h>
71 #include <sys/kern_event.h>
73 static void zip_reply_to_getmyzone();
74 extern int at_reg_mcast(), at_unreg_mcast();
77 extern at_ifaddr_t
*ifID_table
[], *ifID_home
;
78 extern short ErrorZIPoverflow
;
80 /**********************************************************************
82 * ZIP is implemented as a "peer" of DDP, so the packets coming in
83 * to ZIP have the same headers as those coming in to DDP {ddp...}.
84 * Same applies to outgoing packets. Also, unlike DDP, ZIP assumes
85 * that an incoming packet is in a contiguous gbuf_t.
87 **********************************************************************/
89 static int netinfo_reply_pending
;
90 static void zip_netinfo_reply(at_x_zip_t
*, at_ifaddr_t
*);
91 static void zip_getnetinfo(at_ifaddr_t
*);
92 static void zip_getnetinfo_locked(void *);
93 static void send_phony_reply(void *);
96 * zip_send_getnetinfo_reply: we received a GetNetInfo packet, we need to reply
97 * with the right information for the port.
99 static void zip_send_getnetinfo_reply(m
, ifID
)
101 register at_ifaddr_t
*ifID
;
105 at_ddp_t
*ddp
, *ddp_sent
;
106 short ZoneNameProvided
= FALSE
;
107 short RequestIsBroadcasted
= FALSE
;
108 u_short znumber
, len
, packet_length
, size
, status
;
112 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
114 /* access the Zone Name info part of the GetNetInfo Request */
116 zname
= (at_nvestr_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
+ 6);
118 if (zname
->len
> ZIP_MAX_ZONE_LENGTH
) {
119 dPrintf(D_M_ZIP
, D_L_WARNING
,
120 ("zip_s_gni_r: zone len too long l=%d ddplen=%d\n",
121 zname
->len
, DDPLEN_VALUE(ddp
)));
127 ZoneNameProvided
= TRUE
;
129 GNIReply
[0] = ZIP_NETINFO_REPLY
;
130 GNIReply
[1] = ZIP_ZONENAME_INVALID
;
132 /* check if we are the originator is in the cable range for this interface */
134 if ((NET_VALUE(ddp
->src_net
) < CableStart
|| NET_VALUE(ddp
->src_net
) > CableStop
) &&
135 (NET_VALUE(ddp
->dst_net
) == 0 && ddp
->dst_node
== 0xff)) {
136 RequestIsBroadcasted
= TRUE
;
138 Entry
= rt_blookup(CableStop
);
140 if (Entry
!= NULL
&& RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
142 GNIReply
[2] = (Entry
->NetStart
& 0xFF00) >> 8;
143 GNIReply
[3] = (Entry
->NetStart
& 0x00FF);
144 GNIReply
[4] = (Entry
->NetStop
& 0xFF00) >> 8;
145 GNIReply
[5] = (Entry
->NetStop
& 0x00FF);
147 /* copy the zone name found in the request */
149 GNIReply
[6] = zname
->len
;
150 bcopy(&zname
->str
, &GNIReply
[7], zname
->len
);
153 if (znumber
= zt_find_zname(zname
)) {
155 if (ZT_ISIN_ZMAP((znumber
), Entry
->ZoneBitMap
)) {
157 GNIReply
[1] = 0; /* Zone Valid */
159 if (len
= zt_get_zmcast(ifID
, zname
, &GNIReply
[8+zname
->len
]))
160 GNIReply
[7+zname
->len
] = len
;
162 GNIReply
[1] |= ZIP_USE_BROADCAST
;
163 GNIReply
[7+zname
->len
] = 0; /* multicast address length */
165 packet_length
= 8 + zname
->len
+ len
;
171 else { /* should not happen, we are supposed to know our net */
172 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_s_gni_r: Don't know about our zone infos!!!\n"));
176 if (zt_ent_zcount(Entry
) == 1)
177 GNIReply
[1] |= ZIP_ONE_ZONE
;
179 if (GNIReply
[1] & ZIP_ZONENAME_INVALID
) {
181 short Index
= ifID
->ifDefZone
;
183 if (Index
<= 0 || Index
>= ZT_MAXEDOUT
) {
184 dPrintf(D_M_ZIP
, D_L_WARNING
,
185 ("zip_s_gni_r: Invalid starting index =%d port%d\n",
186 Index
, ifID
->ifPort
));
193 if (len
= zt_get_zmcast(ifID
, &ZT_table
[Index
].Zone
, &GNIReply
[8+zname
->len
]))
194 GNIReply
[7+zname
->len
] = len
;
196 GNIReply
[1] |= ZIP_USE_BROADCAST
;
197 GNIReply
[7+zname
->len
] = 0; /* multicast address length */
200 packet_length
= 7 + zname
->len
+ len
;
202 /* in the case the zone name asked for in the request was invalid, we need
203 * to copy the good default zone for this net
206 GNIReply
[packet_length
+ 1] = ZT_table
[Index
].Zone
.len
;
207 bcopy(&ZT_table
[Index
].Zone
.str
, &GNIReply
[packet_length
+ 2],
208 ZT_table
[Index
].Zone
.len
);
209 packet_length
= packet_length
+2 + ZT_table
[Index
].Zone
.len
;
214 * we're finally ready to send out the GetNetInfo Reply
219 size
= DDP_X_HDR_SIZE
+ packet_length
;
220 if ((m_sent
= gbuf_alloc(AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
221 return; /* was return(ENOBUFS); */
224 gbuf_rinc(m_sent
,AT_WR_OFFSET
);
225 gbuf_wset(m_sent
,size
);
226 ddp_sent
= (at_ddp_t
*)(gbuf_rptr(m_sent
));
228 /* Prepare the DDP header */
230 ddp_sent
->unused
= ddp_sent
->hopcount
= 0;
231 UAS_ASSIGN(ddp
->checksum
, 0);
232 DDPLEN_ASSIGN(ddp_sent
, size
);
233 NET_ASSIGN(ddp_sent
->src_net
, ifID
->ifThisNode
.s_net
);
234 ddp_sent
->src_node
= ifID
->ifThisNode
.s_node
;
235 ddp_sent
->src_socket
= ZIP_SOCKET
;
236 ddp_sent
->dst_socket
= ddp
->src_socket
;
238 if (RequestIsBroadcasted
) { /* if this was a broadcast, must respond from that */
240 NET_ASSIGN(ddp_sent
->dst_net
, 0);
241 ddp_sent
->dst_node
= 0xFF;
245 NET_NET(ddp_sent
->dst_net
, ddp
->src_net
);
246 ddp_sent
->dst_node
= ddp
->src_node
;
248 ddp_sent
->type
= DDP_ZIP
;
250 bcopy(&GNIReply
, &ddp_sent
->data
, packet_length
);
252 dPrintf(D_M_ZIP_LOW
, D_L_ROUTING
,
253 ("zip_s_gni_r: send to %d:%d port#%d pack_len=%d\n",
254 NET_VALUE(ddp_sent
->dst_net
), ddp_sent
->dst_node
,
255 ifID
->ifPort
, packet_length
));
257 ddp_router_output(m_sent
, ifID
, AT_ADDR
,
258 NET_VALUE(ddp_sent
->dst_net
), ddp_sent
->dst_node
, 0))) {
259 dPrintf(D_M_ZIP
, D_L_ERROR
,
260 ("zip_s_gni_r: ddp_router_output returns =%d\n", status
));
261 return; /* was return(status); */
263 } /* zip_send_getnetinfo_reply */
267 * build_ZIP_reply_packet: is used to create and send a DDP packet and use the
268 * provided buffer as a ZIP reply. This is used by zip_send_ext_reply_to_query
269 * and zip_send_reply_to_query for sending their replies to ZIP queries.
271 gbuf_t
*prep_ZIP_reply_packet(m
, ifID
)
272 register gbuf_t
*m
; /* this is the original zip query */
273 register at_ifaddr_t
*ifID
;
275 register gbuf_t
*m_sent
;
276 register at_ddp_t
*ddp
, *src_ddp
;
278 /* access the source Net and Node informations */
280 src_ddp
= (at_ddp_t
*)gbuf_rptr(m
);
282 if ((m_sent
= gbuf_alloc (AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
283 return((gbuf_t
*)NULL
);
285 gbuf_rinc(m_sent
,AT_WR_OFFSET
);
286 gbuf_wset(m_sent
,DDP_X_HDR_SIZE
);
287 ddp
= (at_ddp_t
*)(gbuf_rptr(m_sent
));
289 /* Prepare the DDP header */
291 ddp
->unused
= ddp
->hopcount
= 0;
292 UAS_ASSIGN(ddp
->checksum
, 0);
294 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
295 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
296 ddp
->src_socket
= ZIP_SOCKET
;
298 ddp
->dst_socket
= src_ddp
->src_socket
;
299 NET_NET(ddp
->dst_net
, src_ddp
->src_net
);
300 ddp
->dst_node
= src_ddp
->src_node
;
307 * zip_send_ext_reply_to_query: this function deals with ZIP Queries for extended nets.
308 * When we recognize an extended net (that might have several zone name associated with
309 * it), we send A SEPARATE ZIP reply for that network. This is called from the
310 * regular zip_send_reply_to_query, that just deals with non-ext nets.
313 static void zip_send_ext_reply_to_query(mreceived
, ifID
, Entry
, NetAsked
)
314 register gbuf_t
*mreceived
;
315 register at_ifaddr_t
*ifID
;
316 RT_entry
*Entry
; /* info about the network we're looking for */
320 register at_ddp_t
*ddp
;
321 short i
, j
, reply_length
, Index
, zone_count
, status
;
323 char *ReplyBuff
, *ZonesInPacket
;
325 zone_count
= zt_ent_zcount(Entry
);
326 zmap
= Entry
->ZoneBitMap
;
332 if (!(m
= prep_ZIP_reply_packet (mreceived
, ifID
))) {
333 return; /* was return(ENOBUFS); */
336 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
337 ReplyBuff
= (char *)(ddp
->data
);
340 *ReplyBuff
++ = 8; /* ZIP function = 8 [extended reply] */
342 ZonesInPacket
= ReplyBuff
;
345 reply_length
= 2; /* 1st byte is ZIP reply code, 2nd is network count */
348 /* For all zones, we check if they belong to the map for that Network */
350 for (; i
>= 0; i
--) {
352 /* find the zones defined in this entry bitmap */
356 if (zmap
[i
] << j
& 0x80) { /* bingo */
358 Index
= i
*8 + j
; /* zone index in zone table */
360 if (reply_length
+ 3 + ZT_table
[Index
].Zone
.len
> DDP_DATA_SIZE
) {
362 /* we need to send the packet before, this won't fit... */
364 zone_count
-= *ZonesInPacket
;
366 DDPLEN_ASSIGN(ddp
, reply_length
+ DDP_X_HDR_SIZE
);
367 gbuf_winc(m
,reply_length
);
369 ddp_router_output(m
, ifID
, AT_ADDR
,
370 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, 0))) {
371 dPrintf(D_M_ZIP
, D_L_ERROR
,
372 ("zip_s_ext_repl: ddp_router_output returns =%d\n",
374 return; /* was return (status); */
380 /* this should fit in this packet, build the NetNumber, ZoneLen,
384 if (ZT_table
[Index
].Zone
.len
) {
385 *ZonesInPacket
+= 1; /* bump NetCount field */
386 *ReplyBuff
++ = (NetAsked
& 0xFF00) >> 8;
387 *ReplyBuff
++ = (NetAsked
& 0x00FF) ;
388 *ReplyBuff
++ = ZT_table
[Index
].Zone
.len
;
390 bcopy(&ZT_table
[Index
].Zone
.str
, ReplyBuff
,
391 ZT_table
[Index
].Zone
.len
);
393 ReplyBuff
+= ZT_table
[Index
].Zone
.len
;
394 reply_length
+= ZT_table
[Index
].Zone
.len
+3;
399 j
= 0; /* reset the bit count */
402 /* if we have some zone info in a half-empty packet, send it now.
403 * Remember, for extended nets we send *at least* one Reply
407 DDPLEN_ASSIGN(ddp
, reply_length
+ DDP_X_HDR_SIZE
);
408 gbuf_winc(m
,reply_length
);
410 ddp_router_output(m
, ifID
, AT_ADDR
,
411 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, 0))) {
412 dPrintf(D_M_ZIP
, D_L_ERROR
,
413 ("zip_s_ext_reply: ddp_router_output returns =%d\n", status
));
414 return; /* was return (status); */
417 else /* free the buffer not used */
420 } /* zip_send_ext_reply_to_query */
423 * zip_send_reply_to_query: we received a ZIPQuery packet, we need to reply
424 * with the right information for the nets requested (if we have
425 * the right information.
427 static void zip_send_reply_to_query(mreceived
, ifID
)
428 register gbuf_t
*mreceived
;
429 register at_ifaddr_t
*ifID
;
432 register at_ddp_t
*ddp
, *ddp_received
;
434 short i
, reply_length
, Index
, status
;
435 u_char network_count
;
437 char *ReplyBuff
, *ZonesInPacket
;
439 ddp_received
= (at_ddp_t
*)gbuf_rptr(mreceived
);
441 /* access the number of nets requested in the Query */
442 network_count
= *((char *)(ddp_received
->data
) + 1);
443 NetAsked
= (u_short
*)(ddp_received
->data
+ 2);
445 /* check the validity of the Query packet */
447 if (DDPLEN_VALUE(ddp_received
) !=
448 (2 + network_count
* 2 + DDP_X_HDR_SIZE
)) {
450 dPrintf(D_M_ZIP
, D_L_WARNING
,
451 ("zip_s_reply_to_q: bad length netcount=%d len=%d\n",
452 network_count
, DDPLEN_VALUE(ddp
)));
453 return; /* was return(1); */
456 /* walk the Query Network list */
457 /* we want to build a response with the network number followed by the zone name
458 * length and the zone name. If there is more than one zone per network asked,
459 * we repeat the network number and stick the zone length and zone name.
460 * We need to be carefull with the max DDP size for data. If we see that a new
461 * NetNum, ZoneLen, ZoneName sequence won't fit, we send the previous packet and
462 * begin to build a new one.
467 if (!(m
= prep_ZIP_reply_packet (mreceived
, ifID
))) {
468 return; /* was return(ENOBUFS); */
471 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
472 ReplyBuff
= (char *)(ddp
->data
);
474 *ReplyBuff
++ = 2; /* ZIP function = 2 [Non extended reply] */
475 ZonesInPacket
= ReplyBuff
;
478 reply_length
= 2; /* 1st byte is ZIP reply code, 2nd is network count */
480 for (i
= 0 ; i
< network_count
; i
++, NetAsked
++) {
481 Entry
= rt_blookup(*NetAsked
);
483 if (Entry
!= NULL
&& ((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
484 RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
486 if (Entry
->NetStart
== 0) { /* asking for a NON EXTENDED network */
488 if ( (Index
= zt_ent_zindex(Entry
->ZoneBitMap
)) == 0)
493 if (reply_length
+ 3 + ZT_table
[Index
].Zone
.len
> DDP_DATA_SIZE
) {
495 /* we need to send the packet before, this won't fit... */
497 DDPLEN_ASSIGN(ddp
, reply_length
+ DDP_X_HDR_SIZE
);
498 gbuf_winc(m
,reply_length
);
501 ddp_router_output(m
, ifID
, AT_ADDR
,
502 NET_VALUE(ddp
->dst_net
),
503 ddp
->dst_node
, 0))) {
504 dPrintf(D_M_ZIP
, D_L_ERROR
,
505 ("zip_s_reply: ddp_router_output returns =%d\n",
507 return; /* was return (status); */
510 /* this is not nice, I know, but we reenter the loop with
511 * a packet is sent with the next network field in the Query
519 /* this should fit in this packet, build the NetNumber, ZoneLen,
523 if (ZT_table
[Index
].Zone
.len
) {
524 ZonesInPacket
+= 1; /* bump NetCount field */
525 *ReplyBuff
++ = (*NetAsked
& 0xFF00) >> 8;
526 *ReplyBuff
++ = (*NetAsked
& 0x00FF) ;
527 *ReplyBuff
++ = ZT_table
[Index
].Zone
.len
;
528 bcopy(&ZT_table
[Index
].Zone
.str
, ReplyBuff
,
529 ZT_table
[Index
].Zone
.len
);
531 ReplyBuff
+= ZT_table
[Index
].Zone
.len
;
533 reply_length
+= ZT_table
[Index
].Zone
.len
+ 3;
540 else { /* extended network, check for multiple zone name attached
541 * and build a separate packet for each extended network requested
544 zip_send_ext_reply_to_query(mreceived
, ifID
, Entry
, *NetAsked
);
550 /* If we have a non extended packet (code 2) with some stuff in it,
551 * we need to send it now
554 if ( reply_length
> 2) {
555 DDPLEN_ASSIGN(ddp
, reply_length
+ DDP_X_HDR_SIZE
);
556 gbuf_winc(m
,reply_length
);
558 ddp_router_output(m
, ifID
, AT_ADDR
,
559 NET_VALUE(ddp
->dst_net
),
560 ddp
->dst_node
, 0))) {
561 dPrintf(D_M_ZIP
, D_L_ERROR
,
562 ("zip_send_reply: ddp_router_output returns =%d\n", status
));
563 return; /* was return (status); */
566 else /* free the buffer not used */
568 } /* zip_send_reply_to_query */
570 /***********************************************************************
573 **********************************************************************/
575 void zip_router_input (m
, ifID
)
577 register at_ifaddr_t
*ifID
;
579 register at_ddp_t
*ddp
;
580 register at_atp_t
*atp
;
581 register at_zip_t
*zip
;
582 register u_long user_bytes
;
583 register u_short user_byte
;
585 /* variables for ZipNotify processing */
586 register char old_zone_len
;
587 register char new_zone_len
;
588 register char *old_zone
;
590 void zip_sched_getnetinfo(); /* forward reference */
592 if (gbuf_type(m
) != MSG_DATA
) {
593 /* If this is a M_ERROR message, DDP is shutting down,
594 * nothing to do here...If it's something else, we don't
595 * understand what it is
597 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_router_input: not an M_DATA message\n"));
603 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_router_input: BAD ifID\n"));
609 * The ZIP listener receives two types of requests:
611 * ATP requests: GetZoneList, GetLocalZone, or GetMyZone
612 * ZIP requests: Netinfo, Query, Reply, takedown, bringup
615 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
617 if (ddp
->type
== DDP_ZIP
) {
618 zip
= (at_zip_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
619 dPrintf(D_M_ZIP_LOW
, D_L_INPUT
,
620 ("zip_input: received a ZIP_DDP command=%d\n",
622 switch (zip
->command
) {
623 case ZIP_QUERY
: /* we received a Zip Query request */
624 dPrintf(D_M_ZIP
, D_L_INPUT
,
625 ("zip_input: Received a Zip Query in from %d.%d\n",
626 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
628 if (!RT_LOOKUP_OKAY(ifID
, ddp
)) {
629 dPrintf(D_M_ZIP
, D_L_INPUT
,
630 ("zip_input:: refused ZIP_QUERY from %d:%d\n",
631 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
634 zip_send_reply_to_query(m
, ifID
);
638 case ZIP_REPLY
: /* we received a Zip Query Reply packet */
639 case ZIP_EXTENDED_REPLY
:
640 if (ifID
->ifRoutingState
== PORT_OFFLINE
) {
641 dPrintf(D_M_ZIP
, D_L_INPUT
,
642 ("zip_input: Received a Zip Reply in user mode\n"));
645 zip_reply_received(m
, ifID
, zip
->command
);
650 /* we received a Zip Takedown packet */
651 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_input: Received a Zip takedown!!!\n"));
656 /* we received a Zip BringUp packet */
657 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_input: Received a Zip BringUp!!!\n"));
661 case ZIP_GETNETINFO
: /* we received a GetNetInfo request */
662 dPrintf(D_M_ZIP
, D_L_INPUT
,
663 ("zip_input: Received a GetNetInfo Req in from %d.%d\n",
664 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
665 if (RT_LOOKUP_OKAY(ifID
, ddp
)) {
666 dPrintf(D_M_ZIP
, D_L_OUTPUT
,
667 ("zip_input: we, as node %d:%d send GNI reply to %d:%d\n",
668 ifID
->ifThisNode
.s_net
, ifID
->ifThisNode
.s_node
,
669 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
670 zip_send_getnetinfo_reply(m
, ifID
);
676 case ZIP_NETINFO_REPLY
:
678 /* If we are not waiting for a GetNetInfo reply
679 * to arrive, this must be a broadcast
680 * message for someone else on the zone, so
681 * no need to even look at it!
684 ((NET_VALUE(ddp
->src_net
) != ifID
->ifThisNode
.s_net
) ||
685 (ddp
->src_node
!= ifID
->ifThisNode
.s_node
)) && netinfo_reply_pending
)
687 extern void trackrouter();
688 dPrintf(D_M_ZIP
, D_L_INPUT
,
689 ("zip_input: Received a GetNetInfo Reply from %d.%d\n",
690 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
691 trackrouter(ifID
, NET_VALUE(ddp
->src_net
), ddp
->src_node
);
692 zip_netinfo_reply((at_x_zip_t
*)zip
, ifID
);
699 /* processing of ZipNotify message : first, change
700 * our zone name, then if NIS is open, let NBP demon
701 process know of this change...(just forward the
704 /* First, check if this is really a packet for us */
705 old_zone
= &zip
->data
[4];
706 if (!zonename_equal(&ifID
->ifZoneName
,
707 (at_nvestr_t
*)old_zone
)) {
708 /* the old zone name in the packet is not the
709 * same as ours, so this packet couldn't be
716 old_zone_len
= *old_zone
;
717 new_zone_len
= zip
->data
[4 + old_zone_len
+ 1];
718 new_zone
= old_zone
+ old_zone_len
;
720 /* Reset the zone multicast address */
721 (void)at_unreg_mcast(ifID
, (caddr_t
)&ifID
->ZoneMcastAddr
);
722 bzero((caddr_t
)&ifID
->ZoneMcastAddr
, ETHERNET_ADDR_LEN
);
724 /* change the zone name - copy both the length and the string */
725 bcopy((caddr_t
)new_zone
, (caddr_t
)&ifID
->ifZoneName
,
728 /* Send network zone change event and new zone for this interface. */
729 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONEUPDATED
, 0, &(ifID
->ifZoneName
));
730 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONELISTCHANGED
, 0, 0);
732 /* add the new zone to the list of local zones */
733 if (!MULTIPORT_MODE
&& !DEFAULT_ZONE(&ifID
->ifZoneName
))
734 (void)setLocalZones(&ifID
->ifZoneName
,
735 (ifID
->ifZoneName
.len
+1));
737 /* Before trying to request our new multicast address,
738 * wait a while... someone might have alredy requested
739 * it, so we may see some broadcast messages flying
740 * by... Set up the structures so that it appears that
741 * we have already requested the NetInfo.
743 ifID
->ifNumRetries
= ZIP_NETINFO_RETRIES
;
744 netinfo_reply_pending
= 1;
745 ifID
->ifGNIScheduled
= 1;
746 timeout(zip_sched_getnetinfo
, (caddr_t
) ifID
,
752 routing_needed(m
, ifID
, TRUE
);
756 else if (ddp
->type
== DDP_ATP
&&
757 RT_LOOKUP_OKAY(ifID
, ddp
)) {
758 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
759 atp
= (at_atp_t
*)(gbuf_rptr(m
)+DDP_X_HDR_SIZE
);
761 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
763 /* Get the user bytes in network order */
765 user_bytes
= UAL_VALUE(atp
->user_bytes
);
766 user_byte
= user_bytes
>> 24; /* Get the zeroth byte */
768 dPrintf(D_M_ZIP
, D_L_INPUT
,
769 ("zip_input: received a ZIP_ATP command=%d\n", user_byte
));
773 zip_reply_to_getmyzone(ifID
, m
);
777 case ZIP_GETZONELIST
:
778 zip_reply_to_getzonelist(ifID
, m
);
782 case ZIP_GETLOCALZONES
:
783 zip_reply_to_getlocalzones(ifID
, m
);
788 dPrintf(D_M_ZIP
, D_L_WARNING
,
789 ("zip_input: received unknown ZIP_ATP command=%d\n", user_byte
));
790 routing_needed(m
, ifID
, TRUE
);
797 } /* zip_router_input */
799 /***********************************************************************
804 **********************************************************************/
805 int zonename_equal (zone1
, zone2
)
806 register at_nvestr_t
*zone1
, *zone2
;
808 register char c1
, c2
;
812 if (zone1
->len
!= zone2
->len
)
815 for (i
=0; i
< (int) zone1
->len
; i
++) {
818 if (c1
>= 'a' && c1
<= 'z')
820 if (c2
>= 'a' && c2
<= 'z')
838 static unsigned char lower_case
[] =
839 {0x8a, 0x8c, 0x8d, 0x8e, 0x96, 0x9a, 0x9f, 0xbe,
840 0xbf, 0xcf, 0x9b, 0x8b, 0x88, 0};
841 static unsigned char upper_case
[] =
842 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0xae,
843 0xaf, 0xce, 0xcd, 0xcc, 0xcb, 0};
845 for (i
=0; lower_case
[i
]; i
++)
846 if (ch
== lower_case
[i
])
847 return (upper_case
[i
]);
853 /***********************************************************************
854 * zip_netinfo_reply ()
858 **********************************************************************/
859 static void zip_netinfo_reply (netinfo
, ifID
)
860 register at_x_zip_t
*netinfo
;
861 register at_ifaddr_t
*ifID
;
864 void zip_sched_getnetinfo(); /* forward reference */
865 register at_net_al this_net
;
867 register u_char zone_name_len
;
869 /* There may be multiple zones on the cable.... we need to
870 * worry about whether or not this packet is addressed
873 /* *** Do we really need to check this? *** */
874 if (!zonename_equal((at_nvestr_t
*)netinfo
->data
, &ifID
->ifZoneName
)) {
875 dPrintf(D_M_ZIP
, D_L_INFO
, ("zip_netinfo_reply, !zonename_equal!!!"));
879 ifID
->ifThisCableStart
= NET_VALUE(netinfo
->cable_range_start
);
880 ifID
->ifThisCableEnd
= NET_VALUE(netinfo
->cable_range_end
);
881 dPrintf(D_M_ZIP
, D_L_OUTPUT
, ("Zip_netinfo_reply: Set cable to %d-%d\n",
882 ifID
->ifThisCableStart
, ifID
->ifThisCableEnd
));
884 /* The packet is in response to our request */
885 ifID
->ifGNIScheduled
= 0;
886 untimeout (zip_sched_getnetinfo
, (caddr_t
) ifID
);
887 netinfo_reply_pending
= 0;
888 zone_name_len
= netinfo
->data
[0];
889 mcast_len
= netinfo
->data
[zone_name_len
+ 1];
891 if (netinfo
->flags
& ZIP_ZONENAME_INVALID
) {
892 /* copy out the default zone name from packet */
893 default_zone
= (char *)&netinfo
->data
[zone_name_len
+1+mcast_len
+1];
894 bcopy((caddr_t
)default_zone
, (caddr_t
)&ifID
->ifZoneName
,
898 /* add the new zone to the list of local zones */
899 if (!MULTIPORT_MODE
&& !DEFAULT_ZONE(&ifID
->ifZoneName
))
900 (void)setLocalZones(&ifID
->ifZoneName
, (ifID
->ifZoneName
.len
+1));
902 /* get the multicast address out of the GetNetInfo reply, if there is one */
903 if (!(netinfo
->flags
& ZIP_USE_BROADCAST
)) {
904 /* If ZIP_USE_BROADCAST is set, we will use the cable
905 broadcast address as the multicast address, however
906 the cable multicast address has already been registered.
908 /* This packet contains a multicast address, so
909 * send to elap to register it.
911 if (FDDI_OR_TOKENRING(ifID
->aa_ifp
->if_type
))
912 ddp_bit_reverse(&netinfo
->data
[zone_name_len
+ 2]);
914 bcopy((caddr_t
)&netinfo
->data
[zone_name_len
+ 2],
915 (caddr_t
)&ifID
->ZoneMcastAddr
, ETHERNET_ADDR_LEN
);
916 (void)at_reg_mcast(ifID
, (caddr_t
)&ifID
->ZoneMcastAddr
);
919 this_net
= ifID
->ifThisNode
.s_net
;
920 if ((this_net
>= ifID
->ifThisCableStart
) &&
921 (this_net
<= ifID
->ifThisCableEnd
)) {
922 /* ThisNet is in the range of valid network numbers
923 * for the cable. Do nothing.
926 /* ThisNet is not in the range of valid network
927 * numbers for the cable. This may be either because
928 * the chosen number was from start-up range, or
929 * because the user has a misconception of where the
930 * machine is!! Since ThisCableRange is set up, next
931 * time aarp is invoked, it would select address in
935 /* to reset initial_net and initial_node to zero, so
936 * that aarp is forced to choose new values
938 ifID
->initial_addr
.s_net
= 0;
939 ifID
->initial_addr
.s_node
= 0;
941 /* Wake up elap_online sleeping on this interface. */
942 ZIPwakeup(ifID
, ZIP_RE_AARP
);
946 if (!ifID
->startup_inprogress
) {
947 /* Send event with zone info. This covers case where we get zone info
948 after startup. During startup this event is sent from ZIPwakeup. */
949 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONEUPDATED
, 0, &(ifID
->ifZoneName
));
952 ZIPwakeup(ifID
, 0); /* no error */
954 } /* zip_netinfo_reply */
957 /**********************************************************************
960 **********************************************************************/
961 int zip_control (ifID
, control
)
962 register at_ifaddr_t
*ifID
;
965 dPrintf(D_M_ZIP
, D_L_INFO
, ("zip_control called port=%d control=%d\n",
966 ifID
->ifPort
, control
));
969 case ZIP_LATE_ROUTER
:
970 if (!ifID
->ifGNIScheduled
) {
971 ifID
->ifNumRetries
= 0;
972 /* Get the desired zone name from elap and put it in
973 * ifID for zip_getnetinfo() to use.
975 if (ifID
->startup_zone
.len
)
976 ifID
->ifZoneName
= ifID
->startup_zone
;
977 zip_getnetinfo(ifID
);
981 ifID
->ifZoneName
.len
= 1;
982 ifID
->ifZoneName
.str
[0] = '*';
983 ifID
->ifZoneName
.str
[1] = '\0';
985 /* Send event with zone info. */
986 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONEUPDATED
, 0, &(ifID
->ifZoneName
));
995 /* locked version of zip_getnetinfo */
996 static void zip_getnetinfo_locked(arg
)
1002 if (ifID
!= NULL
) { // make sure it hasn't been closed
1003 ifID
= (at_ifaddr_t
*)arg
;
1004 ifID
->ifGNIScheduled
= 0;
1005 zip_getnetinfo(ifID
);
1011 /**********************************************************************
1014 **********************************************************************/
1015 static void zip_getnetinfo (ifID
)
1016 register at_ifaddr_t
*ifID
;
1018 register at_x_zip_t
*zip
;
1020 register at_ddp_t
*ddp
;
1021 void zip_sched_getnetinfo();
1022 register struct atalk_addr
*at_dest
;
1026 size
= DDP_X_HDR_SIZE
+ ZIP_X_HDR_SIZE
+ ifID
->ifZoneName
.len
+ 1
1027 + sizeof(struct atalk_addr
) + 1;
1028 if ((m
= gbuf_alloc (AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
1029 /* This time, we're unable to allocate buffer to
1030 * send a packet out, so schedule to send a packet
1031 * out later, and exit.
1033 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_getnetinfo: no buffer, call later port=%d\n",
1035 ifID
->ifGNIScheduled
= 1;
1036 timeout (zip_getnetinfo_locked
, (caddr_t
) ifID
, ZIP_TIMER_INT
/10);
1040 gbuf_rinc(m
,AT_WR_OFFSET
);
1042 *(u_char
*)gbuf_rptr(m
) = AT_ADDR
;
1043 at_dest
= (struct atalk_addr
*)(gbuf_rptr(m
) + 1);
1044 ddp
= (at_ddp_t
*)(gbuf_rptr(m
) + sizeof(struct atalk_addr
) + 1);
1045 zip
= (at_x_zip_t
*)ddp
->data
;
1048 zip
->command
= ZIP_GETNETINFO
;
1050 NET_ASSIGN(zip
->cable_range_start
, 0);
1051 NET_ASSIGN(zip
->cable_range_end
, 0);
1052 if (ifID
->ifZoneName
.len
) /* has to match reply exactly */
1053 bcopy((caddr_t
)&ifID
->ifZoneName
, (caddr_t
)zip
->data
,
1054 ifID
->ifZoneName
.len
+ 1);
1056 zip
->data
[0] = 0; /* No zone name is availbale */
1058 /* let the lap fields be uninitialized, 'cause it doesn't
1061 DDPLEN_ASSIGN(ddp
, size
- (sizeof(struct atalk_addr
) + 1));
1062 UAS_ASSIGN(ddp
->checksum
, 0);
1063 ddp
->hopcount
= ddp
->unused
= 0;
1064 NET_ASSIGN(ddp
->dst_net
, 0); /* cable-wide broadcast */
1065 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1066 /* By this time, AARP is done */
1068 ddp
->dst_node
= 0xff;
1069 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1070 ddp
->dst_socket
= ZIP_SOCKET
;
1071 ddp
->src_socket
= ZIP_SOCKET
;
1072 ddp
->type
= DDP_ZIP
;
1074 at_dest
->atalk_unused
= 0;
1075 NET_NET(at_dest
->atalk_net
, ddp
->dst_net
);
1076 at_dest
->atalk_node
= ddp
->dst_node
;
1078 dPrintf(D_M_ZIP
, D_L_INPUT
, ("zip_getnetinfo: called for port=%d\n",
1081 if (elap_dataput(m
, ifID
, 0, NULL
)) {
1082 dPrintf(D_M_ZIP
, D_L_ERROR
,
1083 ("zip_getnetinfo: error sending zip_getnetinfo\n"));
1087 ifID
->ifNumRetries
++;
1088 netinfo_reply_pending
= 1;
1089 ifID
->ifGNIScheduled
= 1;
1090 timeout (zip_sched_getnetinfo
, (caddr_t
) ifID
, ZIP_TIMER_INT
);
1091 } /* zip_getnetinfo */
1094 /**********************************************************************
1095 * zip_sched_getnetinfo()
1097 **********************************************************************/
1099 void zip_sched_getnetinfo (ifID
)
1100 register at_ifaddr_t
*ifID
;
1105 ifID
->ifGNIScheduled
= 0;
1107 if (ifID
->ifNumRetries
>= ZIP_NETINFO_RETRIES
) {
1108 /* enough packets sent.... give up! */
1109 /* we didn't get any response from the net, so
1110 * assume there's no router around and the given
1111 * zone name, if any, is not valid. Change the
1114 ifID
->ifZoneName
.len
= 1;
1115 ifID
->ifZoneName
.str
[0] = '*';
1116 ifID
->ifZoneName
.str
[1] = '\0';
1117 /* Should NBP be notified of this "new" zone name?? */
1118 netinfo_reply_pending
= 0;
1120 ifID
->ifRouterState
= NO_ROUTER
;
1121 ifID
->ifARouter
.s_net
= 0;
1122 ifID
->ifARouter
.s_node
= 0;
1124 dPrintf(D_M_ZIP
, D_L_INFO
, ("zip_sched_getnetinfo: Reset Cable Range\n"));
1126 ifID
->ifThisCableStart
= DDP_MIN_NETWORK
;
1127 ifID
->ifThisCableEnd
= DDP_MAX_NETWORK
;
1129 if (ifID
->ifState
== LAP_ONLINE_FOR_ZIP
)
1130 ZIPwakeup (ifID
, 0); /* no error */
1132 zip_getnetinfo(ifID
);
1138 /**********************************************************************
1142 * This routine checks whether or not the packet contained in "m"
1143 * is an (outgoing) ZIP packet. If not, it returns 0. If it is a
1144 * ZIP packet, it returns the ZIP packet type (ZIP command). "m"
1145 * points to a packet with extended DDP header. The rest of the
1146 * DDP data may or may not be in the first gbuf.
1148 **********************************************************************/
1149 int zip_type_packet (m
)
1152 register at_atp_t
*atp
;
1153 register at_ddp_t
*ddp
;
1154 register at_zip_t
*zip
;
1155 register u_long user_bytes
;
1156 register int user_byte
;
1158 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1159 if (ddp
->dst_socket
== ZIP_SOCKET
) {
1160 switch (ddp
->type
) {
1162 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1163 zip
= (at_zip_t
*)(gbuf_rptr(m
)
1166 zip
=(at_zip_t
*)(gbuf_rptr(gbuf_cont(m
)));
1167 return ((int)zip
->command
);
1169 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1170 atp
= (at_atp_t
*)(gbuf_rptr(m
)+DDP_X_HDR_SIZE
);
1172 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1173 /* Get the user bytes in network order */
1174 user_bytes
= UAL_VALUE(atp
->user_bytes
);
1175 user_byte
= user_bytes
>> 24; /* Get the zeroth byte */
1176 if ((user_byte
== ZIP_GETMYZONE
) ||
1177 (user_byte
== ZIP_GETZONELIST
) ||
1178 (user_byte
== ZIP_GETLOCALZONES
))
1189 /**********************************************************************
1190 * zip_handle_getmyzone()
1193 * Routine to handle ZIP GetMyZone request locally. It generates
1194 * a phony response to the outgoing ATP request and sends it up.
1196 * 07/12/94 : remark2 only called from ddp.c / ddp_output
1197 * should only be called from the home port, but
1198 * when we are a router we should know the infos for all
1199 * anyway, so reply locally with what we have in stock...
1201 **********************************************************************/
1203 int zip_handle_getmyzone(ifID
, m
)
1204 register at_ifaddr_t
*ifID
;
1208 register at_ddp_t
*ddp
;
1209 register at_ddp_t
*r_ddp
;
1210 register at_atp_t
*r_atp
;
1211 gbuf_t
*rm
; /* reply message */
1215 dPrintf(D_M_ZIP
, D_L_INFO
,
1216 ("zip_handle_getmyzone: local reply for port=%d\n",
1219 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ 1 + ifID
->ifZoneName
.len
;
1220 /* space for two headers and the zone name */
1221 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
1222 dPrintf(D_M_ZIP
, D_L_WARNING
,
1223 ("zip_handle_getmyzone: no buffer, port=%d\n",
1228 gbuf_rinc(rm
,AT_WR_OFFSET
);
1230 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1231 r_atp
= (at_atp_t
*)r_ddp
->data
;
1234 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1235 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1236 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1238 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1240 /* fill up the ddp header for reply */
1241 DDPLEN_ASSIGN(r_ddp
, size
);
1242 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1243 UAS_ASSIGN(r_ddp
->checksum
, 0);
1244 NET_ASSIGN(r_ddp
->dst_net
, ifID
->ifThisNode
.s_net
);
1245 NET_NET(r_ddp
->src_net
, ddp
->dst_net
);
1246 r_ddp
->dst_node
= ifID
->ifThisNode
.s_node
;
1247 r_ddp
->src_node
= ddp
->dst_node
;
1248 r_ddp
->dst_socket
= ddp
->src_socket
;
1249 r_ddp
->src_socket
= ZIP_SOCKET
;
1250 r_ddp
->type
= DDP_ATP
;
1252 /* fill up the atp header */
1253 r_atp
->cmd
= ATP_CMD_TRESP
;
1259 UAS_UAS(r_atp
->tid
, atp
->tid
);
1261 ulongtmp
= htonl(ulongtmp
);
1262 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
); /* no of zones */
1264 /* fill up atp data part */
1265 bcopy((caddr_t
) &ifID
->ifZoneName
, (caddr_t
) r_atp
->data
, ifID
->ifZoneName
.len
+1);
1267 /* all set to send the packet back up */
1269 timeout(send_phony_reply
, (caddr_t
) rm
, HZ
/20);
1274 send_phony_reply(arg
)
1277 gbuf_t
*rm
= (gbuf_t
*)arg
;
1280 ddp_input(rm
, ifID_home
);
1288 * zip_prep_query_packet: build the actual ddp packet for the zip query
1291 gbuf_t
*zip_prep_query_packet(ifID
, RouterNet
, RouterNode
)
1293 at_net_al RouterNet
; /* we want to send the Zip Query to that router */
1298 register at_ddp_t
*ddp
;
1300 if ((m
= gbuf_alloc (AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
1301 dPrintf(D_M_ZIP
, D_L_WARNING
,
1302 ("zip_send_query_packet: no buffer, port=%d\n",
1304 return((gbuf_t
*)NULL
);
1306 gbuf_rinc(m
,AT_WR_OFFSET
);
1309 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
1311 /* Prepare the DDP header */
1313 ddp
->unused
= ddp
->hopcount
= 0;
1314 UAS_ASSIGN(ddp
->checksum
, 0);
1315 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1316 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1317 ddp
->src_socket
= ZIP_SOCKET
;
1319 ddp
->dst_socket
= ZIP_SOCKET
;
1320 NET_ASSIGN(ddp
->dst_net
, RouterNet
);
1321 ddp
->dst_node
= RouterNode
;
1323 ddp
->type
= DDP_ZIP
;
1326 } /* zip_prep_query_packet */
1330 * zip_send_queries: this function send queries for the routing table entries that
1331 * need to know their zones. It scans the routing table for entries with unknown
1332 * zones and build Query packets accordingly.
1333 * Note: this is called on a per port basis.
1336 void zip_send_queries(ifID
, RouterNet
, RouterNode
)
1337 register at_ifaddr_t
*ifID
;
1338 at_net_al RouterNet
; /* we want to send the Zip Query to that router */
1341 RT_entry
*Entry
= &RT_table
[0];
1343 register at_ddp_t
*ddp
;
1345 short Query_index
, EntryNumber
= 0 ;
1346 register u_char port
= ifID
->ifPort
;
1347 char *QueryBuff
, *ZoneCount
;
1348 short zip_sent
= FALSE
;
1352 if (!(m
= zip_prep_query_packet(ifID
, RouterNet
, RouterNode
))) {
1353 return; /* was return (ENOBUFS); */
1356 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
1357 QueryBuff
= (char *)ddp
->data
;
1359 *QueryBuff
++ = ZIP_QUERY
;
1360 ZoneCount
= QueryBuff
; /* network count */
1366 while (EntryNumber
< RT_maxentry
) {
1368 /* scan the table, and build the packet with the right entries:
1369 * - entry in use and on the right Port
1370 * - with unknwon zones and in an active state
1371 * - talking to the right router
1374 if ((Query_index
) > 2*254 +2) {
1376 /* we need to send the packet now, but we can't have more than 256
1377 * requests for networks: the Netcount field is a 8bit in the zip query
1378 * packet format as defined in Inside Atalk
1381 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1382 ("zip_send_query: FULL query for %d nets on port#%d.(len=%d)\n",
1383 *ZoneCount
, port
, Query_index
));
1386 gbuf_winc(m
,DDP_X_HDR_SIZE
+ Query_index
);
1387 DDPLEN_ASSIGN(ddp
, DDP_X_HDR_SIZE
+ Query_index
);
1390 ddp_router_output(m
, ifID
, AT_ADDR
,
1391 RouterNet
, RouterNode
, 0))) {
1392 dPrintf(D_M_ZIP
, D_L_ERROR
,
1393 ("zip_send_query: ddp_router_output returns =%d\n", status
));
1394 return; /* was return (status); */
1401 if (((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
1402 (Entry
->NetStop
) && (Entry
->NetPort
== port
) &&
1403 (!RT_ALL_ZONES_KNOWN(Entry
))){
1405 /* we're ready to had that to our list of stuff to send */
1407 if (Entry
->NetStart
) { /* extended net*/
1409 *QueryBuff
++ = (Entry
->NetStart
& 0xFF00) >> 8;
1410 *QueryBuff
++ = (Entry
->NetStart
& 0x00FF);
1414 *QueryBuff
++ = (Entry
->NetStop
& 0xFF00) >> 8;
1415 *QueryBuff
++ = (Entry
->NetStop
& 0x00FF);
1419 *ZoneCount
+= 1;/* bump the number of network requested */
1428 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1429 ("zip_send_query: query for %d nets on port#%d.(len=%d)\n",
1430 *ZoneCount
, port
, Query_index
));
1432 if (*ZoneCount
) { /* non-full Query needs to be sent */
1434 gbuf_winc(m
,DDP_X_HDR_SIZE
+ Query_index
);
1435 DDPLEN_ASSIGN(ddp
, DDP_X_HDR_SIZE
+ Query_index
);
1438 ddp_router_output(m
, ifID
, AT_ADDR
,
1439 RouterNet
, RouterNode
, 0))) {
1440 dPrintf(D_M_ZIP
, D_L_ERROR
,
1441 ("zip_send_query: ddp_router_output returns =%d\n",
1443 return; /* was return (status); */
1449 if (!zip_sent
) /* we didn't need to send anything for that port */
1450 ifID
->ifZipNeedQueries
= 0;
1451 } /* zip_send_queries */
1453 /* zip_reply_received: we recieved the reply to one of our query, update the
1454 * zone bitmap and stuffs with was we received.
1455 * we receive two types of replies: non extended and extended.
1456 * For extended replies, the network count is the Total of zones for that net.
1459 zip_reply_received(m
, ifID
, reply_type
)
1461 register at_ifaddr_t
*ifID
;
1464 register at_nvestr_t
*zname
;
1465 RT_entry
*Entry
= &RT_table
[0];
1466 register at_ddp_t
*ddp
;
1468 u_short payload_len
, result
;
1469 u_char network_count
;
1472 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1474 /* access the number of nets provided in the ZIP Reply */
1476 network_count
= *(u_char
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
+ 1);
1478 PacketPtr
= (char *)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
+ 2);
1480 payload_len
= DDPLEN_VALUE(ddp
) - (DDP_X_HDR_SIZE
+ 2);
1482 dPrintf(D_M_ZIP_LOW
, D_L_INPUT
, ("zip_reply_received from %d:%d type=%d netcount=%d\n",
1483 NET_VALUE(ddp
->src_net
), ddp
->src_node
, reply_type
, network_count
));
1486 while (payload_len
> 0 && network_count
>0) {
1488 Network
= *(at_net_al
*)PacketPtr
;
1490 zname
= (at_nvestr_t
*)PacketPtr
;
1492 payload_len
= payload_len
-(zname
->len
+ 3);
1494 if (zname
->len
<= 0) { /* not valid, we got a problem here... */
1495 dPrintf(D_M_ZIP
, D_L_WARNING
,
1496 ("zip_reply_received: Problem zlen=0 for net=%d from %d:%d type=%d netcnt=%d\n",
1497 Network
, NET_VALUE(ddp
->src_net
), ddp
->src_node
, reply_type
, network_count
));
1503 Entry
= rt_blookup(Network
);
1505 if (Entry
!= NULL
) {
1507 if (Entry
->EntryState
>= RTE_STATE_SUSPECT
) {
1509 result
= zt_add_zonename(zname
);
1511 if (result
== ZT_MAXEDOUT
) {
1513 dPrintf(D_M_ZIP
, D_L_ERROR
,
1514 ("zip_reply_received: ZTable full from %d:%d on zone '%s'\n",
1515 NET_VALUE(ddp
->src_net
), ddp
->src_node
, zname
->str
));
1516 ErrorZIPoverflow
= 1;
1520 zt_set_zmap(result
, Entry
->ZoneBitMap
);
1522 RT_SET_ZONE_KNOWN(Entry
);
1526 dPrintf(D_M_ZIP
, D_L_INPUT
,
1527 ("zip_reply_received: entry %d-%d not updated, cause state=%d\n",
1528 Entry
->NetStart
, Entry
->NetStop
, Entry
->EntryState
));
1532 dPrintf(D_M_ZIP
, D_L_WARNING
,
1533 ("zip_reply_received: network %d not found in RT\n", Network
));
1537 /* now bump the PacketPtr pointer */
1538 PacketPtr
+= zname
->len
+ 1;
1542 if ((reply_type
== ZIP_REPLY
) && network_count
> 0) {
1544 dPrintf(D_M_ZIP
, D_L_WARNING
,
1545 ("zip_reply_received: Problem decoding zone (after net:%d-%d)\n",
1546 Entry
->NetStart
, Entry
->NetStop
));
1547 ifID
->ifZipNeedQueries
= 1;
1550 ifID
->ifZipNeedQueries
= 0;
1552 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1553 ("zip_reply_received: entry %d-%d all zones known\n",
1554 Entry
->NetStart
, Entry
->NetStop
));
1559 * zip_reply_to_getmyzone: replies to ZIP GetMyZone received from the Net
1562 static void zip_reply_to_getmyzone (ifID
, m
)
1563 register at_ifaddr_t
*ifID
;
1567 register at_ddp_t
*ddp
;
1568 register at_ddp_t
*r_ddp
;
1569 register at_atp_t
*r_atp
;
1570 register gbuf_t
*rm
; /* reply message */
1571 register int size
, Index
, status
;
1576 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ 1 + ifID
->ifZoneName
.len
;
1577 /* space for two headers and the zone name */
1578 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
1579 dPrintf(D_M_ZIP
, D_L_WARNING
,
1580 ("zip_reply_to_getmyzone: no buffer, port=%d\n", ifID
->ifPort
));
1581 return; /* was return (ENOBUFS); */
1583 gbuf_rinc(rm
,AT_WR_OFFSET
);
1585 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1586 r_atp
= (at_atp_t
*)r_ddp
->data
;
1588 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1589 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1590 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1592 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1594 /* fill up the ddp header for reply */
1595 DDPLEN_ASSIGN(r_ddp
, size
);
1596 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1597 UAS_ASSIGN(r_ddp
->checksum
, 0);
1599 NET_ASSIGN(r_ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1600 NET_NET(r_ddp
->dst_net
, ddp
->src_net
);
1602 r_ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1603 r_ddp
->dst_node
= ddp
->src_node
;
1605 r_ddp
->dst_socket
= ddp
->src_socket
;
1606 r_ddp
->src_socket
= ZIP_SOCKET
;
1607 r_ddp
->type
= DDP_ATP
;
1609 /* fill up the atp header */
1610 r_atp
->cmd
= ATP_CMD_TRESP
;
1616 UAS_UAS(r_atp
->tid
, atp
->tid
);
1618 ulongtmp
= htonl(ulongtmp
);
1619 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
); /* no of zones */
1621 data_ptr
= (char *)r_atp
->data
;
1624 * fill up atp data part with the zone name if we can find it...
1627 Entry
= rt_blookup(NET_VALUE(ddp
->src_net
));
1628 if (Entry
!= NULL
&& ((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
1629 RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
1631 Index
= zt_ent_zindex(Entry
->ZoneBitMap
) -1;
1633 *data_ptr
= ZT_table
[Index
].Zone
.len
;
1634 bcopy((caddr_t
) &ZT_table
[Index
].Zone
.str
, (caddr_t
) ++data_ptr
,
1635 ZT_table
[Index
].Zone
.len
);
1637 /* all set to send the packet back up */
1638 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1639 ("zip_reply_to_GMZ: ddp_router_output to %d:%d port %d\n",
1640 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, ifID
->ifPort
));
1643 ddp_router_output(rm
, ifID
, AT_ADDR
,
1644 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, 0))) {
1645 dPrintf(D_M_ZIP
, D_L_ERROR
,
1646 ("zip_reply_to_GMZ: ddp_r_output returns =%d\n", status
));
1647 return; /* was return (status); */
1655 * zip_reply_to_getzonelist: replies to ZIP GetZoneList requested from the Net
1658 zip_reply_to_getzonelist (ifID
, m
)
1659 register at_ifaddr_t
*ifID
;
1663 register at_ddp_t
*ddp
;
1664 register at_ddp_t
*r_ddp
;
1665 register at_atp_t
*r_atp
;
1666 register gbuf_t
*rm
; /* reply message */
1667 register int size
, status
;
1668 register short Index
=0, StartPoint
, ZLength
, PacketLen
=0;
1672 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1673 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1674 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1676 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1679 /* space for two headers and the zone name */
1681 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
1685 gbuf_rinc(rm
,AT_WR_OFFSET
);
1687 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1688 r_atp
= (at_atp_t
*)r_ddp
->data
;
1690 /* fill up the ddp header for reply */
1692 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1693 UAS_ASSIGN(r_ddp
->checksum
, 0);
1694 NET_ASSIGN(r_ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1695 NET_NET(r_ddp
->dst_net
, ddp
->src_net
);
1696 r_ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1697 r_ddp
->dst_node
= ddp
->src_node
;
1698 r_ddp
->dst_socket
= ddp
->src_socket
;
1699 r_ddp
->src_socket
= ZIP_SOCKET
;
1700 r_ddp
->type
= DDP_ATP
;
1702 /* fill up the atp header */
1704 r_atp
->cmd
= ATP_CMD_TRESP
;
1710 UAS_UAS(r_atp
->tid
, atp
->tid
);
1712 Reply
= (char *)r_atp
->data
;
1714 /* get the start index from the ATP request */
1716 StartPoint
= (UAL_VALUE(atp
->user_bytes
) & 0xffff) -1;
1718 /* find the next zone to send */
1720 while ((Index
< ZT_maxentry
) && StartPoint
> 0) {
1721 if (ZT_table
[Index
].Zone
.len
)
1727 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
, ("zip_reply_to_GZL: Index=%d\n", Index
));
1729 * fill up atp data part with the zone name if we can find it...
1732 while (Index
< ZT_maxentry
) {
1734 ZLength
= ZT_table
[Index
].Zone
.len
;
1736 if (ZT_table
[Index
].ZoneCount
&& ZLength
) {
1739 if (PacketLen
+ 8 + ZLength
+1 > DDP_DATA_SIZE
) /* packet full */
1743 bcopy((caddr_t
) &ZT_table
[Index
].Zone
.str
,
1746 PacketLen
+= ZLength
+ 1;
1752 if (Index
>= ZT_maxentry
) /* this is the end of the list */
1754 ulongtmp
+= 0x01000000;
1757 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
); /* # of zones and flag*/
1759 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ PacketLen
;
1761 DDPLEN_ASSIGN(r_ddp
, size
);
1763 /* all set to send the packet back up */
1765 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1766 ("zip_r_GZL: send packet to %d:%d port %d atp_len =%d\n",
1767 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, ifID
->ifPort
, PacketLen
));
1770 if (status
= ddp_router_output(rm
, ifID
, AT_ADDR
,
1771 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, 0)) {
1772 dPrintf(D_M_ZIP
, D_L_ERROR
, ("zip_reply_to_GZL: ddp_router_output returns=%d\n",
1781 * zip_reply_to_getlocalzones: replies to ZIP GetLocalZones requested from the Net
1784 int zip_reply_to_getlocalzones (ifID
, m
)
1785 register at_ifaddr_t
*ifID
;
1789 register at_ddp_t
*ddp
;
1790 register at_ddp_t
*r_ddp
;
1791 register at_atp_t
*r_atp
;
1792 register gbuf_t
*rm
; /* reply message */
1794 short Index
, Index_wanted
, ZLength
;
1795 short i
,j
, packet_len
;
1796 short zCount
, ZoneCount
, ZonesInPacket
;
1797 char *zmap
, last_flag
= 0;
1801 u_long ulongtmp
= 0;
1803 Index
= Index_wanted
= ZLength
= i
= j
= packet_len
= zCount
= ZoneCount
=
1806 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1807 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1808 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1810 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1812 /* space for two headers and the zone name */
1814 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
1818 gbuf_rinc(rm
,AT_WR_OFFSET
);
1820 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1821 r_atp
= (at_atp_t
*)r_ddp
->data
;
1823 Reply
= (char *)r_atp
->data
;
1826 /* get the start index from the ATP request */
1828 Index_wanted
= (UAL_VALUE(atp
->user_bytes
) & 0xffff) -1;
1830 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1831 ("zip_r_GLZ: for station %d:%d Index_wanted = %d\n",
1832 NET_VALUE(ddp
->src_net
), ddp
->src_node
, Index_wanted
));
1834 Entry
= rt_blookup(NET_VALUE(ddp
->src_net
));
1836 if (Entry
!= NULL
&& ((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
1837 RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
1839 ZoneCount
= zt_ent_zcount(Entry
) ;
1841 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1842 ("zip_reply_GLZ: for %d:%d ZoneCount=%d\n",
1843 NET_VALUE(ddp
->src_net
), ddp
->src_node
, ZoneCount
));
1845 zmap
= &Entry
->ZoneBitMap
[0];
1848 * first of all, we want to find the "first next zone" in the bitmap,
1849 * to do so, we need to scan the bitmap and add the number of valid
1850 * zones we find until we reach the next zone to be sent in the reply
1853 if (ZoneCount
> Index_wanted
) {
1855 ZoneCount
-= Index_wanted
;
1857 /* find the starting point in the bitmap according to index */
1859 for (i
= 0; Index_wanted
>= 0 && i
< ZT_BYTES
; i
++)
1861 if (Index_wanted
< 8) {
1862 /* how many zones in the bitmap byte */
1863 for (j
= 0, zCount
=0; j
< 8 ; j
++)
1864 if ((zmap
[i
] << j
) & 0x80)
1866 if (Index_wanted
< zCount
) {
1867 for (j
= 0 ; Index_wanted
> 0 && j
< 8 ; j
++)
1868 if ((zmap
[i
] << j
) & 0x80)
1873 Index_wanted
-= zCount
;
1876 for (j
= 0 ; j
< 8 ; j
++)
1877 if ((zmap
[i
] << j
) & 0x80)
1882 * now, we point to the begining of our next zones in the bitmap
1885 while (i
< ZT_BYTES
) {
1889 if ((zmap
[i
] << j
) & 0x80) {
1890 Index
= i
*8 + j
; /* get the index in ZT */
1892 ZLength
= ZT_table
[Index
].Zone
.len
;
1894 if (ZT_table
[Index
].ZoneCount
&& ZLength
) {
1895 if (packet_len
+ ATP_HDR_SIZE
+ ZLength
+ 1 >
1900 bcopy((caddr_t
) &ZT_table
[Index
].Zone
.str
,
1903 packet_len
+= ZLength
+ 1;
1905 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1906 ("zip_reply_GLZ: add z#%d to packet (l=%d)\n",
1907 Index
, packet_len
));
1910 dPrintf(D_M_ZIP
, D_L_WARNING
,
1911 ("zip_reply_GLZ: no len for index=%d\n",
1920 else /* set the "last flag" bit in the reply */
1923 else /* set the "last flag" bit in the reply */
1928 if (ZonesInPacket
== ZoneCount
)
1932 /* fill up the ddp header for reply */
1934 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1935 UAS_ASSIGN(r_ddp
->checksum
, 0);
1937 NET_ASSIGN(r_ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1938 NET_NET(r_ddp
->dst_net
, ddp
->src_net
);
1940 r_ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1941 r_ddp
->dst_node
= ddp
->src_node
;
1943 r_ddp
->dst_socket
= ddp
->src_socket
;
1944 r_ddp
->src_socket
= ZIP_SOCKET
;
1945 r_ddp
->type
= DDP_ATP
;
1947 /* fill up the atp header */
1948 r_atp
->cmd
= ATP_CMD_TRESP
;
1954 UAS_UAS(r_atp
->tid
, atp
->tid
);
1955 ulongtmp
= ((last_flag
<< 24) & 0xFF000000) + ZonesInPacket
; /* # of zones and flag*/
1956 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
);
1957 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ packet_len
;
1959 DDPLEN_ASSIGN(r_ddp
, size
);
1961 /* all set to send the packet back up */
1963 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1964 ("zip_r_GLZ: send packet to %d:%d port %d atp_len =%d\n",
1965 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, ifID
->ifPort
, packet_len
));
1967 if (status
= ddp_router_output(rm
, ifID
, AT_ADDR
,
1968 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, 0)) {
1969 dPrintf(D_M_ZIP
, D_L_ERROR
,
1970 ("zip_reply_to_GLZ: ddp_router_output returns =%d\n",
1975 } /* zip_reply_to_getlocalzones */
1977 int regDefaultZone(ifID
)
1981 char data
[ETHERNET_ADDR_LEN
];
1986 zt_get_zmcast(ifID
, &ifID
->ifZoneName
, data
);
1987 if (FDDI_OR_TOKENRING(ifID
->aa_ifp
->if_type
))
1988 ddp_bit_reverse(data
);
1989 bcopy((caddr_t
)data
, (caddr_t
)&ifID
->ZoneMcastAddr
, ETHERNET_ADDR_LEN
);
1990 (void)at_reg_mcast(ifID
, (caddr_t
)&ifID
->ZoneMcastAddr
);