2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1988-1998 Apple Computer, Inc.
29 * 0.01 05/12/94 Laurent Dumont Creation
31 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
35 * Router ZIP protocol functions:
37 * This file contains Routing specifics to handle ZIP requests and responses
38 * sent and received by a router node.
40 * The entry point for the zip input in ddp is valid only when we're
41 * running in router mode.
45 #include <sys/errno.h>
46 #include <sys/types.h>
47 #include <sys/param.h>
48 #include <machine/spl.h>
49 #include <sys/systm.h>
50 #include <sys/kernel.h>
52 #include <sys/filedesc.h>
53 #include <sys/fcntl.h>
55 #include <sys/ioctl.h>
56 #include <sys/malloc.h>
57 #include <sys/socket.h>
58 #include <sys/socketvar.h>
61 #include <net/if_types.h>
63 #include <netat/sysglue.h>
64 #include <netat/appletalk.h>
65 #include <netat/at_var.h>
66 #include <netat/ddp.h>
67 #include <netat/nbp.h>
68 #include <netat/zip.h>
69 #include <netat/at_pcb.h>
70 #include <netat/atp.h>
71 #include <netat/routing_tables.h>
72 #include <netat/debug.h>
74 #include <sys/kern_event.h>
76 static void zip_reply_to_getmyzone();
77 extern int at_reg_mcast(), at_unreg_mcast();
80 extern at_ifaddr_t
*ifID_table
[], *ifID_home
;
81 extern short ErrorZIPoverflow
;
83 /**********************************************************************
85 * ZIP is implemented as a "peer" of DDP, so the packets coming in
86 * to ZIP have the same headers as those coming in to DDP {ddp...}.
87 * Same applies to outgoing packets. Also, unlike DDP, ZIP assumes
88 * that an incoming packet is in a contiguous gbuf_t.
90 **********************************************************************/
92 static int netinfo_reply_pending
;
93 static void zip_netinfo_reply(at_x_zip_t
*, at_ifaddr_t
*);
94 static void zip_getnetinfo(at_ifaddr_t
*);
95 static void zip_getnetinfo_funnel(void *);
96 static void send_phony_reply(void *);
99 * zip_send_getnetinfo_reply: we received a GetNetInfo packet, we need to reply
100 * with the right information for the port.
102 static void zip_send_getnetinfo_reply(m
, ifID
)
104 register at_ifaddr_t
*ifID
;
108 at_ddp_t
*ddp
, *ddp_sent
;
109 short ZoneNameProvided
= FALSE
;
110 short RequestIsBroadcasted
= FALSE
;
111 u_short znumber
, len
, packet_length
, size
, status
;
115 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
117 /* access the Zone Name info part of the GetNetInfo Request */
119 zname
= (at_nvestr_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
+ 6);
121 if (zname
->len
> ZIP_MAX_ZONE_LENGTH
) {
122 dPrintf(D_M_ZIP
, D_L_WARNING
,
123 ("zip_s_gni_r: zone len too long l=%d ddplen=%d\n",
124 zname
->len
, DDPLEN_VALUE(ddp
)));
130 ZoneNameProvided
= TRUE
;
132 GNIReply
[0] = ZIP_NETINFO_REPLY
;
133 GNIReply
[1] = ZIP_ZONENAME_INVALID
;
135 /* check if we are the originator is in the cable range for this interface */
137 if ((NET_VALUE(ddp
->src_net
) < CableStart
|| NET_VALUE(ddp
->src_net
) > CableStop
) &&
138 (NET_VALUE(ddp
->dst_net
) == 0 && ddp
->dst_node
== 0xff)) {
139 RequestIsBroadcasted
= TRUE
;
141 Entry
= rt_blookup(CableStop
);
143 if (Entry
!= NULL
&& RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
145 GNIReply
[2] = (Entry
->NetStart
& 0xFF00) >> 8;
146 GNIReply
[3] = (Entry
->NetStart
& 0x00FF);
147 GNIReply
[4] = (Entry
->NetStop
& 0xFF00) >> 8;
148 GNIReply
[5] = (Entry
->NetStop
& 0x00FF);
150 /* copy the zone name found in the request */
152 GNIReply
[6] = zname
->len
;
153 bcopy(&zname
->str
, &GNIReply
[7], zname
->len
);
156 if (znumber
= zt_find_zname(zname
)) {
158 if (ZT_ISIN_ZMAP((znumber
), Entry
->ZoneBitMap
)) {
160 GNIReply
[1] = 0; /* Zone Valid */
162 if (len
= zt_get_zmcast(ifID
, zname
, &GNIReply
[8+zname
->len
]))
163 GNIReply
[7+zname
->len
] = len
;
165 GNIReply
[1] |= ZIP_USE_BROADCAST
;
166 GNIReply
[7+zname
->len
] = 0; /* multicast address length */
168 packet_length
= 8 + zname
->len
+ len
;
174 else { /* should not happen, we are supposed to know our net */
175 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_s_gni_r: Don't know about our zone infos!!!\n"));
179 if (zt_ent_zcount(Entry
) == 1)
180 GNIReply
[1] |= ZIP_ONE_ZONE
;
182 if (GNIReply
[1] & ZIP_ZONENAME_INVALID
) {
184 short Index
= ifID
->ifDefZone
;
186 if (Index
<= 0 || Index
>= ZT_MAXEDOUT
) {
187 dPrintf(D_M_ZIP
, D_L_WARNING
,
188 ("zip_s_gni_r: Invalid starting index =%d port%d\n",
189 Index
, ifID
->ifPort
));
196 if (len
= zt_get_zmcast(ifID
, &ZT_table
[Index
].Zone
, &GNIReply
[8+zname
->len
]))
197 GNIReply
[7+zname
->len
] = len
;
199 GNIReply
[1] |= ZIP_USE_BROADCAST
;
200 GNIReply
[7+zname
->len
] = 0; /* multicast address length */
203 packet_length
= 7 + zname
->len
+ len
;
205 /* in the case the zone name asked for in the request was invalid, we need
206 * to copy the good default zone for this net
209 GNIReply
[packet_length
+ 1] = ZT_table
[Index
].Zone
.len
;
210 bcopy(&ZT_table
[Index
].Zone
.str
, &GNIReply
[packet_length
+ 2],
211 ZT_table
[Index
].Zone
.len
);
212 packet_length
= packet_length
+2 + ZT_table
[Index
].Zone
.len
;
217 * we're finally ready to send out the GetNetInfo Reply
222 size
= DDP_X_HDR_SIZE
+ packet_length
;
223 if ((m_sent
= gbuf_alloc(AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
224 return; /* was return(ENOBUFS); */
227 gbuf_rinc(m_sent
,AT_WR_OFFSET
);
228 gbuf_wset(m_sent
,size
);
229 ddp_sent
= (at_ddp_t
*)(gbuf_rptr(m_sent
));
231 /* Prepare the DDP header */
233 ddp_sent
->unused
= ddp_sent
->hopcount
= 0;
234 UAS_ASSIGN(ddp
->checksum
, 0);
235 DDPLEN_ASSIGN(ddp_sent
, size
);
236 NET_ASSIGN(ddp_sent
->src_net
, ifID
->ifThisNode
.s_net
);
237 ddp_sent
->src_node
= ifID
->ifThisNode
.s_node
;
238 ddp_sent
->src_socket
= ZIP_SOCKET
;
239 ddp_sent
->dst_socket
= ddp
->src_socket
;
241 if (RequestIsBroadcasted
) { /* if this was a broadcast, must respond from that */
243 NET_ASSIGN(ddp_sent
->dst_net
, 0);
244 ddp_sent
->dst_node
= 0xFF;
248 NET_NET(ddp_sent
->dst_net
, ddp
->src_net
);
249 ddp_sent
->dst_node
= ddp
->src_node
;
251 ddp_sent
->type
= DDP_ZIP
;
253 bcopy(&GNIReply
, &ddp_sent
->data
, packet_length
);
255 dPrintf(D_M_ZIP_LOW
, D_L_ROUTING
,
256 ("zip_s_gni_r: send to %d:%d port#%d pack_len=%d\n",
257 NET_VALUE(ddp_sent
->dst_net
), ddp_sent
->dst_node
,
258 ifID
->ifPort
, packet_length
));
260 ddp_router_output(m_sent
, ifID
, AT_ADDR
,
261 NET_VALUE(ddp_sent
->dst_net
), ddp_sent
->dst_node
, 0))) {
262 dPrintf(D_M_ZIP
, D_L_ERROR
,
263 ("zip_s_gni_r: ddp_router_output returns =%d\n", status
));
264 return; /* was return(status); */
266 } /* zip_send_getnetinfo_reply */
270 * build_ZIP_reply_packet: is used to create and send a DDP packet and use the
271 * provided buffer as a ZIP reply. This is used by zip_send_ext_reply_to_query
272 * and zip_send_reply_to_query for sending their replies to ZIP queries.
274 gbuf_t
*prep_ZIP_reply_packet(m
, ifID
)
275 register gbuf_t
*m
; /* this is the original zip query */
276 register at_ifaddr_t
*ifID
;
278 register gbuf_t
*m_sent
;
279 register at_ddp_t
*ddp
, *src_ddp
;
281 /* access the source Net and Node informations */
283 src_ddp
= (at_ddp_t
*)gbuf_rptr(m
);
285 if ((m_sent
= gbuf_alloc (AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
286 return((gbuf_t
*)NULL
);
288 gbuf_rinc(m_sent
,AT_WR_OFFSET
);
289 gbuf_wset(m_sent
,DDP_X_HDR_SIZE
);
290 ddp
= (at_ddp_t
*)(gbuf_rptr(m_sent
));
292 /* Prepare the DDP header */
294 ddp
->unused
= ddp
->hopcount
= 0;
295 UAS_ASSIGN(ddp
->checksum
, 0);
297 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
298 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
299 ddp
->src_socket
= ZIP_SOCKET
;
301 ddp
->dst_socket
= src_ddp
->src_socket
;
302 NET_NET(ddp
->dst_net
, src_ddp
->src_net
);
303 ddp
->dst_node
= src_ddp
->src_node
;
310 * zip_send_ext_reply_to_query: this function deals with ZIP Queries for extended nets.
311 * When we recognize an extended net (that might have several zone name associated with
312 * it), we send A SEPARATE ZIP reply for that network. This is called from the
313 * regular zip_send_reply_to_query, that just deals with non-ext nets.
316 static void zip_send_ext_reply_to_query(mreceived
, ifID
, Entry
, NetAsked
)
317 register gbuf_t
*mreceived
;
318 register at_ifaddr_t
*ifID
;
319 RT_entry
*Entry
; /* info about the network we're looking for */
323 register at_ddp_t
*ddp
;
324 short i
, j
, reply_length
, Index
, zone_count
, status
;
326 char *ReplyBuff
, *ZonesInPacket
;
328 zone_count
= zt_ent_zcount(Entry
);
329 zmap
= Entry
->ZoneBitMap
;
335 if (!(m
= prep_ZIP_reply_packet (mreceived
, ifID
))) {
336 return; /* was return(ENOBUFS); */
339 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
340 ReplyBuff
= (char *)(ddp
->data
);
343 *ReplyBuff
++ = 8; /* ZIP function = 8 [extended reply] */
345 ZonesInPacket
= ReplyBuff
;
348 reply_length
= 2; /* 1st byte is ZIP reply code, 2nd is network count */
351 /* For all zones, we check if they belong to the map for that Network */
353 for (; i
>= 0; i
--) {
355 /* find the zones defined in this entry bitmap */
359 if (zmap
[i
] << j
& 0x80) { /* bingo */
361 Index
= i
*8 + j
; /* zone index in zone table */
363 if (reply_length
+ 3 + ZT_table
[Index
].Zone
.len
> DDP_DATA_SIZE
) {
365 /* we need to send the packet before, this won't fit... */
367 zone_count
-= *ZonesInPacket
;
369 DDPLEN_ASSIGN(ddp
, reply_length
+ DDP_X_HDR_SIZE
);
370 gbuf_winc(m
,reply_length
);
372 ddp_router_output(m
, ifID
, AT_ADDR
,
373 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, 0))) {
374 dPrintf(D_M_ZIP
, D_L_ERROR
,
375 ("zip_s_ext_repl: ddp_router_output returns =%d\n",
377 return; /* was return (status); */
383 /* this should fit in this packet, build the NetNumber, ZoneLen,
387 if (ZT_table
[Index
].Zone
.len
) {
388 *ZonesInPacket
+= 1; /* bump NetCount field */
389 *ReplyBuff
++ = (NetAsked
& 0xFF00) >> 8;
390 *ReplyBuff
++ = (NetAsked
& 0x00FF) ;
391 *ReplyBuff
++ = ZT_table
[Index
].Zone
.len
;
393 bcopy(&ZT_table
[Index
].Zone
.str
, ReplyBuff
,
394 ZT_table
[Index
].Zone
.len
);
396 ReplyBuff
+= ZT_table
[Index
].Zone
.len
;
397 reply_length
+= ZT_table
[Index
].Zone
.len
+3;
402 j
= 0; /* reset the bit count */
405 /* if we have some zone info in a half-empty packet, send it now.
406 * Remember, for extended nets we send *at least* one Reply
410 DDPLEN_ASSIGN(ddp
, reply_length
+ DDP_X_HDR_SIZE
);
411 gbuf_winc(m
,reply_length
);
413 ddp_router_output(m
, ifID
, AT_ADDR
,
414 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, 0))) {
415 dPrintf(D_M_ZIP
, D_L_ERROR
,
416 ("zip_s_ext_reply: ddp_router_output returns =%d\n", status
));
417 return; /* was return (status); */
420 else /* free the buffer not used */
423 } /* zip_send_ext_reply_to_query */
426 * zip_send_reply_to_query: we received a ZIPQuery packet, we need to reply
427 * with the right information for the nets requested (if we have
428 * the right information.
430 static void zip_send_reply_to_query(mreceived
, ifID
)
431 register gbuf_t
*mreceived
;
432 register at_ifaddr_t
*ifID
;
435 register at_ddp_t
*ddp
, *ddp_received
;
437 short i
, reply_length
, Index
, status
;
438 u_char network_count
;
440 char *ReplyBuff
, *ZonesInPacket
;
442 ddp_received
= (at_ddp_t
*)gbuf_rptr(mreceived
);
444 /* access the number of nets requested in the Query */
445 network_count
= *((char *)(ddp_received
->data
) + 1);
446 NetAsked
= (u_short
*)(ddp_received
->data
+ 2);
448 /* check the validity of the Query packet */
450 if (DDPLEN_VALUE(ddp_received
) !=
451 (2 + network_count
* 2 + DDP_X_HDR_SIZE
)) {
453 dPrintf(D_M_ZIP
, D_L_WARNING
,
454 ("zip_s_reply_to_q: bad length netcount=%d len=%d\n",
455 network_count
, DDPLEN_VALUE(ddp
)));
456 return; /* was return(1); */
459 /* walk the Query Network list */
460 /* we want to build a response with the network number followed by the zone name
461 * length and the zone name. If there is more than one zone per network asked,
462 * we repeat the network number and stick the zone length and zone name.
463 * We need to be carefull with the max DDP size for data. If we see that a new
464 * NetNum, ZoneLen, ZoneName sequence won't fit, we send the previous packet and
465 * begin to build a new one.
470 if (!(m
= prep_ZIP_reply_packet (mreceived
, ifID
))) {
471 return; /* was return(ENOBUFS); */
474 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
475 ReplyBuff
= (char *)(ddp
->data
);
477 *ReplyBuff
++ = 2; /* ZIP function = 2 [Non extended reply] */
478 ZonesInPacket
= ReplyBuff
;
481 reply_length
= 2; /* 1st byte is ZIP reply code, 2nd is network count */
483 for (i
= 0 ; i
< network_count
; i
++, NetAsked
++) {
484 Entry
= rt_blookup(*NetAsked
);
486 if (Entry
!= NULL
&& ((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
487 RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
489 if (Entry
->NetStart
== 0) { /* asking for a NON EXTENDED network */
491 if ( (Index
= zt_ent_zindex(Entry
->ZoneBitMap
)) == 0)
496 if (reply_length
+ 3 + ZT_table
[Index
].Zone
.len
> DDP_DATA_SIZE
) {
498 /* we need to send the packet before, this won't fit... */
500 DDPLEN_ASSIGN(ddp
, reply_length
+ DDP_X_HDR_SIZE
);
501 gbuf_winc(m
,reply_length
);
504 ddp_router_output(m
, ifID
, AT_ADDR
,
505 NET_VALUE(ddp
->dst_net
),
506 ddp
->dst_node
, 0))) {
507 dPrintf(D_M_ZIP
, D_L_ERROR
,
508 ("zip_s_reply: ddp_router_output returns =%d\n",
510 return; /* was return (status); */
513 /* this is not nice, I know, but we reenter the loop with
514 * a packet is sent with the next network field in the Query
522 /* this should fit in this packet, build the NetNumber, ZoneLen,
526 if (ZT_table
[Index
].Zone
.len
) {
527 ZonesInPacket
+= 1; /* bump NetCount field */
528 *ReplyBuff
++ = (*NetAsked
& 0xFF00) >> 8;
529 *ReplyBuff
++ = (*NetAsked
& 0x00FF) ;
530 *ReplyBuff
++ = ZT_table
[Index
].Zone
.len
;
531 bcopy(&ZT_table
[Index
].Zone
.str
, ReplyBuff
,
532 ZT_table
[Index
].Zone
.len
);
534 ReplyBuff
+= ZT_table
[Index
].Zone
.len
;
536 reply_length
+= ZT_table
[Index
].Zone
.len
+ 3;
543 else { /* extended network, check for multiple zone name attached
544 * and build a separate packet for each extended network requested
547 zip_send_ext_reply_to_query(mreceived
, ifID
, Entry
, *NetAsked
);
553 /* If we have a non extended packet (code 2) with some stuff in it,
554 * we need to send it now
557 if ( reply_length
> 2) {
558 DDPLEN_ASSIGN(ddp
, reply_length
+ DDP_X_HDR_SIZE
);
559 gbuf_winc(m
,reply_length
);
561 ddp_router_output(m
, ifID
, AT_ADDR
,
562 NET_VALUE(ddp
->dst_net
),
563 ddp
->dst_node
, 0))) {
564 dPrintf(D_M_ZIP
, D_L_ERROR
,
565 ("zip_send_reply: ddp_router_output returns =%d\n", status
));
566 return; /* was return (status); */
569 else /* free the buffer not used */
571 } /* zip_send_reply_to_query */
573 /***********************************************************************
576 **********************************************************************/
578 void zip_router_input (m
, ifID
)
580 register at_ifaddr_t
*ifID
;
582 register at_ddp_t
*ddp
;
583 register at_atp_t
*atp
;
584 register at_zip_t
*zip
;
585 register u_long user_bytes
;
586 register u_short user_byte
;
588 /* variables for ZipNotify processing */
589 register char old_zone_len
;
590 register char new_zone_len
;
591 register char *old_zone
;
593 void zip_sched_getnetinfo(); /* forward reference */
595 if (gbuf_type(m
) != MSG_DATA
) {
596 /* If this is a M_ERROR message, DDP is shutting down,
597 * nothing to do here...If it's something else, we don't
598 * understand what it is
600 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_router_input: not an M_DATA message\n"));
606 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_router_input: BAD ifID\n"));
612 * The ZIP listener receives two types of requests:
614 * ATP requests: GetZoneList, GetLocalZone, or GetMyZone
615 * ZIP requests: Netinfo, Query, Reply, takedown, bringup
618 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
620 if (ddp
->type
== DDP_ZIP
) {
621 zip
= (at_zip_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
622 dPrintf(D_M_ZIP_LOW
, D_L_INPUT
,
623 ("zip_input: received a ZIP_DDP command=%d\n",
625 switch (zip
->command
) {
626 case ZIP_QUERY
: /* we received a Zip Query request */
627 dPrintf(D_M_ZIP
, D_L_INPUT
,
628 ("zip_input: Received a Zip Query in from %d.%d\n",
629 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
631 if (!RT_LOOKUP_OKAY(ifID
, ddp
)) {
632 dPrintf(D_M_ZIP
, D_L_INPUT
,
633 ("zip_input:: refused ZIP_QUERY from %d:%d\n",
634 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
637 zip_send_reply_to_query(m
, ifID
);
641 case ZIP_REPLY
: /* we received a Zip Query Reply packet */
642 case ZIP_EXTENDED_REPLY
:
643 if (ifID
->ifRoutingState
== PORT_OFFLINE
) {
644 dPrintf(D_M_ZIP
, D_L_INPUT
,
645 ("zip_input: Received a Zip Reply in user mode\n"));
648 zip_reply_received(m
, ifID
, zip
->command
);
653 /* we received a Zip Takedown packet */
654 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_input: Received a Zip takedown!!!\n"));
659 /* we received a Zip BringUp packet */
660 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_input: Received a Zip BringUp!!!\n"));
664 case ZIP_GETNETINFO
: /* we received a GetNetInfo request */
665 dPrintf(D_M_ZIP
, D_L_INPUT
,
666 ("zip_input: Received a GetNetInfo Req in from %d.%d\n",
667 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
668 if (RT_LOOKUP_OKAY(ifID
, ddp
)) {
669 dPrintf(D_M_ZIP
, D_L_OUTPUT
,
670 ("zip_input: we, as node %d:%d send GNI reply to %d:%d\n",
671 ifID
->ifThisNode
.s_net
, ifID
->ifThisNode
.s_node
,
672 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
673 zip_send_getnetinfo_reply(m
, ifID
);
679 case ZIP_NETINFO_REPLY
:
681 /* If we are not waiting for a GetNetInfo reply
682 * to arrive, this must be a broadcast
683 * message for someone else on the zone, so
684 * no need to even look at it!
687 ((NET_VALUE(ddp
->src_net
) != ifID
->ifThisNode
.s_net
) ||
688 (ddp
->src_node
!= ifID
->ifThisNode
.s_node
)) && netinfo_reply_pending
)
690 extern void trackrouter();
691 dPrintf(D_M_ZIP
, D_L_INPUT
,
692 ("zip_input: Received a GetNetInfo Reply from %d.%d\n",
693 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
694 trackrouter(ifID
, NET_VALUE(ddp
->src_net
), ddp
->src_node
);
695 zip_netinfo_reply((at_x_zip_t
*)zip
, ifID
);
702 /* processing of ZipNotify message : first, change
703 * our zone name, then if NIS is open, let NBP demon
704 process know of this change...(just forward the
707 /* First, check if this is really a packet for us */
708 old_zone
= &zip
->data
[4];
709 if (!zonename_equal(&ifID
->ifZoneName
,
710 (at_nvestr_t
*)old_zone
)) {
711 /* the old zone name in the packet is not the
712 * same as ours, so this packet couldn't be
719 old_zone_len
= *old_zone
;
720 new_zone_len
= zip
->data
[4 + old_zone_len
+ 1];
721 new_zone
= old_zone
+ old_zone_len
;
723 /* Reset the zone multicast address */
724 (void)at_unreg_mcast(ifID
, (caddr_t
)&ifID
->ZoneMcastAddr
);
725 bzero((caddr_t
)&ifID
->ZoneMcastAddr
, ETHERNET_ADDR_LEN
);
727 /* change the zone name - copy both the length and the string */
728 bcopy((caddr_t
)new_zone
, (caddr_t
)&ifID
->ifZoneName
,
731 /* Send network zone change event and new zone for this interface. */
732 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONEUPDATED
, 0, &(ifID
->ifZoneName
));
733 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONELISTCHANGED
, 0, 0);
735 /* add the new zone to the list of local zones */
736 if (!MULTIPORT_MODE
&& !DEFAULT_ZONE(&ifID
->ifZoneName
))
737 (void)setLocalZones(&ifID
->ifZoneName
,
738 (ifID
->ifZoneName
.len
+1));
740 /* Before trying to request our new multicast address,
741 * wait a while... someone might have alredy requested
742 * it, so we may see some broadcast messages flying
743 * by... Set up the structures so that it appears that
744 * we have already requested the NetInfo.
746 ifID
->ifNumRetries
= ZIP_NETINFO_RETRIES
;
747 netinfo_reply_pending
= 1;
748 timeout(zip_sched_getnetinfo
, (caddr_t
) ifID
,
754 routing_needed(m
, ifID
, TRUE
);
758 else if (ddp
->type
== DDP_ATP
&&
759 RT_LOOKUP_OKAY(ifID
, ddp
)) {
760 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
761 atp
= (at_atp_t
*)(gbuf_rptr(m
)+DDP_X_HDR_SIZE
);
763 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
765 /* Get the user bytes in network order */
767 user_bytes
= UAL_VALUE(atp
->user_bytes
);
768 user_byte
= user_bytes
>> 24; /* Get the zeroth byte */
770 dPrintf(D_M_ZIP
, D_L_INPUT
,
771 ("zip_input: received a ZIP_ATP command=%d\n", user_byte
));
775 zip_reply_to_getmyzone(ifID
, m
);
779 case ZIP_GETZONELIST
:
780 zip_reply_to_getzonelist(ifID
, m
);
784 case ZIP_GETLOCALZONES
:
785 zip_reply_to_getlocalzones(ifID
, m
);
790 dPrintf(D_M_ZIP
, D_L_WARNING
,
791 ("zip_input: received unknown ZIP_ATP command=%d\n", user_byte
));
792 routing_needed(m
, ifID
, TRUE
);
799 } /* zip_router_input */
801 /***********************************************************************
806 **********************************************************************/
807 int zonename_equal (zone1
, zone2
)
808 register at_nvestr_t
*zone1
, *zone2
;
810 register char c1
, c2
;
814 if (zone1
->len
!= zone2
->len
)
817 for (i
=0; i
< (int) zone1
->len
; i
++) {
820 if (c1
>= 'a' && c1
<= 'z')
822 if (c2
>= 'a' && c2
<= 'z')
840 static unsigned char lower_case
[] =
841 {0x8a, 0x8c, 0x8d, 0x8e, 0x96, 0x9a, 0x9f, 0xbe,
842 0xbf, 0xcf, 0x9b, 0x8b, 0x88, 0};
843 static unsigned char upper_case
[] =
844 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0xae,
845 0xaf, 0xce, 0xcd, 0xcc, 0xcb, 0};
847 for (i
=0; lower_case
[i
]; i
++)
848 if (ch
== lower_case
[i
])
849 return (upper_case
[i
]);
855 /***********************************************************************
856 * zip_netinfo_reply ()
860 **********************************************************************/
861 static void zip_netinfo_reply (netinfo
, ifID
)
862 register at_x_zip_t
*netinfo
;
863 register at_ifaddr_t
*ifID
;
866 void zip_sched_getnetinfo(); /* forward reference */
867 register at_net_al this_net
;
869 register u_char zone_name_len
;
871 /* There may be multiple zones on the cable.... we need to
872 * worry about whether or not this packet is addressed
875 /* *** Do we really need to check this? *** */
876 if (!zonename_equal((at_nvestr_t
*)netinfo
->data
, &ifID
->ifZoneName
)) {
877 dPrintf(D_M_ZIP
, D_L_INFO
, ("zip_netinfo_reply, !zonename_equal!!!"));
881 ifID
->ifThisCableStart
= NET_VALUE(netinfo
->cable_range_start
);
882 ifID
->ifThisCableEnd
= NET_VALUE(netinfo
->cable_range_end
);
883 dPrintf(D_M_ZIP
, D_L_OUTPUT
, ("Zip_netinfo_reply: Set cable to %d-%d\n",
884 ifID
->ifThisCableStart
, ifID
->ifThisCableEnd
));
886 /* The packet is in response to our request */
887 untimeout (zip_sched_getnetinfo
, (caddr_t
) ifID
);
888 netinfo_reply_pending
= 0;
889 zone_name_len
= netinfo
->data
[0];
890 mcast_len
= netinfo
->data
[zone_name_len
+ 1];
892 if (netinfo
->flags
& ZIP_ZONENAME_INVALID
) {
893 /* copy out the default zone name from packet */
894 default_zone
= (char *)&netinfo
->data
[zone_name_len
+1+mcast_len
+1];
895 bcopy((caddr_t
)default_zone
, (caddr_t
)&ifID
->ifZoneName
,
899 /* add the new zone to the list of local zones */
900 if (!MULTIPORT_MODE
&& !DEFAULT_ZONE(&ifID
->ifZoneName
))
901 (void)setLocalZones(&ifID
->ifZoneName
, (ifID
->ifZoneName
.len
+1));
903 /* get the multicast address out of the GetNetInfo reply, if there is one */
904 if (!(netinfo
->flags
& ZIP_USE_BROADCAST
)) {
905 /* If ZIP_USE_BROADCAST is set, we will use the cable
906 broadcast address as the multicast address, however
907 the cable multicast address has already been registered.
909 /* This packet contains a multicast address, so
910 * send to elap to register it.
912 if (FDDI_OR_TOKENRING(ifID
->aa_ifp
->if_type
))
913 ddp_bit_reverse(&netinfo
->data
[zone_name_len
+ 2]);
915 bcopy((caddr_t
)&netinfo
->data
[zone_name_len
+ 2],
916 (caddr_t
)&ifID
->ZoneMcastAddr
, ETHERNET_ADDR_LEN
);
917 (void)at_reg_mcast(ifID
, (caddr_t
)&ifID
->ZoneMcastAddr
);
920 this_net
= ifID
->ifThisNode
.s_net
;
921 if ((this_net
>= ifID
->ifThisCableStart
) &&
922 (this_net
<= ifID
->ifThisCableEnd
)) {
923 /* ThisNet is in the range of valid network numbers
924 * for the cable. Do nothing.
927 /* ThisNet is not in the range of valid network
928 * numbers for the cable. This may be either because
929 * the chosen number was from start-up range, or
930 * because the user has a misconception of where the
931 * machine is!! Since ThisCableRange is set up, next
932 * time aarp is invoked, it would select address in
936 /* to reset initial_net and initial_node to zero, so
937 * that aarp is forced to choose new values
939 ifID
->initial_addr
.s_net
= 0;
940 ifID
->initial_addr
.s_node
= 0;
942 /* Wake up elap_online sleeping on this interface. */
943 ZIPwakeup(ifID
, ZIP_RE_AARP
);
947 if (!ifID
->startup_inprogress
) {
948 /* Send event with zone info. This covers case where we get zone info
949 after startup. During startup this event is sent from ZIPwakeup. */
950 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONEUPDATED
, 0, &(ifID
->ifZoneName
));
953 ZIPwakeup(ifID
, 0); /* no error */
955 } /* zip_netinfo_reply */
958 /**********************************************************************
961 **********************************************************************/
962 int zip_control (ifID
, control
)
963 register at_ifaddr_t
*ifID
;
966 dPrintf(D_M_ZIP
, D_L_INFO
, ("zip_control called port=%d control=%d\n",
967 ifID
->ifPort
, control
));
970 case ZIP_LATE_ROUTER
:
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
);
980 ifID
->ifZoneName
.len
= 1;
981 ifID
->ifZoneName
.str
[0] = '*';
982 ifID
->ifZoneName
.str
[1] = '\0';
984 /* Send event with zone info. */
985 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONEUPDATED
, 0, &(ifID
->ifZoneName
));
994 /* funnel version of zip_getnetinfo */
995 static void zip_getnetinfo_funnel(arg
)
998 at_ifaddr_t
*ifID
= (at_ifaddr_t
*)arg
;
999 thread_funnel_set(network_flock
, TRUE
);
1000 zip_getnetinfo(ifID
);
1001 thread_funnel_set(network_flock
, FALSE
);
1005 /**********************************************************************
1008 **********************************************************************/
1009 static void zip_getnetinfo (ifID
)
1010 register at_ifaddr_t
*ifID
;
1012 register at_x_zip_t
*zip
;
1014 register at_ddp_t
*ddp
;
1015 void zip_sched_getnetinfo();
1016 register struct atalk_addr
*at_dest
;
1019 size
= DDP_X_HDR_SIZE
+ ZIP_X_HDR_SIZE
+ ifID
->ifZoneName
.len
+ 1
1020 + sizeof(struct atalk_addr
) + 1;
1021 if ((m
= gbuf_alloc (AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
1022 /* This time, we're unable to allocate buffer to
1023 * send a packet out, so schedule to send a packet
1024 * out later, and exit.
1026 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_getnetinfo: no buffer, call later port=%d\n",
1028 timeout (zip_getnetinfo_funnel
, (caddr_t
) ifID
, ZIP_TIMER_INT
/10);
1032 gbuf_rinc(m
,AT_WR_OFFSET
);
1034 *(u_char
*)gbuf_rptr(m
) = AT_ADDR
;
1035 at_dest
= (struct atalk_addr
*)(gbuf_rptr(m
) + 1);
1036 ddp
= (at_ddp_t
*)(gbuf_rptr(m
) + sizeof(struct atalk_addr
) + 1);
1037 zip
= (at_x_zip_t
*)ddp
->data
;
1040 zip
->command
= ZIP_GETNETINFO
;
1042 NET_ASSIGN(zip
->cable_range_start
, 0);
1043 NET_ASSIGN(zip
->cable_range_end
, 0);
1044 if (ifID
->ifZoneName
.len
) /* has to match reply exactly */
1045 bcopy((caddr_t
)&ifID
->ifZoneName
, (caddr_t
)zip
->data
,
1046 ifID
->ifZoneName
.len
+ 1);
1048 zip
->data
[0] = 0; /* No zone name is availbale */
1050 /* let the lap fields be uninitialized, 'cause it doesn't
1053 DDPLEN_ASSIGN(ddp
, size
- (sizeof(struct atalk_addr
) + 1));
1054 UAS_ASSIGN(ddp
->checksum
, 0);
1055 ddp
->hopcount
= ddp
->unused
= 0;
1056 NET_ASSIGN(ddp
->dst_net
, 0); /* cable-wide broadcast */
1057 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1058 /* By this time, AARP is done */
1060 ddp
->dst_node
= 0xff;
1061 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1062 ddp
->dst_socket
= ZIP_SOCKET
;
1063 ddp
->src_socket
= ZIP_SOCKET
;
1064 ddp
->type
= DDP_ZIP
;
1066 at_dest
->atalk_unused
= 0;
1067 NET_NET(at_dest
->atalk_net
, ddp
->dst_net
);
1068 at_dest
->atalk_node
= ddp
->dst_node
;
1070 dPrintf(D_M_ZIP
, D_L_INPUT
, ("zip_getnetinfo: called for port=%d\n",
1073 if (elap_dataput(m
, ifID
, 0, NULL
)) {
1074 dPrintf(D_M_ZIP
, D_L_ERROR
,
1075 ("zip_getnetinfo: error sending zip_getnetinfo\n"));
1079 ifID
->ifNumRetries
++;
1080 netinfo_reply_pending
= 1;
1082 timeout (zip_sched_getnetinfo
, (caddr_t
) ifID
, ZIP_TIMER_INT
);
1083 } /* zip_getnetinfo */
1086 /**********************************************************************
1087 * zip_sched_getnetinfo()
1089 **********************************************************************/
1091 void zip_sched_getnetinfo (ifID
)
1092 register at_ifaddr_t
*ifID
;
1094 boolean_t funnel_state
;
1096 funnel_state
= thread_funnel_set(network_flock
, TRUE
);
1098 if (ifID
->ifNumRetries
>= ZIP_NETINFO_RETRIES
) {
1099 /* enough packets sent.... give up! */
1100 /* we didn't get any response from the net, so
1101 * assume there's no router around and the given
1102 * zone name, if any, is not valid. Change the
1105 ifID
->ifZoneName
.len
= 1;
1106 ifID
->ifZoneName
.str
[0] = '*';
1107 ifID
->ifZoneName
.str
[1] = '\0';
1108 /* Should NBP be notified of this "new" zone name?? */
1109 netinfo_reply_pending
= 0;
1111 ifID
->ifRouterState
= NO_ROUTER
;
1112 ifID
->ifARouter
.s_net
= 0;
1113 ifID
->ifARouter
.s_node
= 0;
1115 dPrintf(D_M_ZIP
, D_L_INFO
, ("zip_sched_getnetinfo: Reset Cable Range\n"));
1117 ifID
->ifThisCableStart
= DDP_MIN_NETWORK
;
1118 ifID
->ifThisCableEnd
= DDP_MAX_NETWORK
;
1120 if (ifID
->ifState
== LAP_ONLINE_FOR_ZIP
)
1121 ZIPwakeup (ifID
, 0); /* no error */
1123 zip_getnetinfo(ifID
);
1125 (void) thread_funnel_set(network_flock
, FALSE
);
1129 /**********************************************************************
1133 * This routine checks whether or not the packet contained in "m"
1134 * is an (outgoing) ZIP packet. If not, it returns 0. If it is a
1135 * ZIP packet, it returns the ZIP packet type (ZIP command). "m"
1136 * points to a packet with extended DDP header. The rest of the
1137 * DDP data may or may not be in the first gbuf.
1139 **********************************************************************/
1140 int zip_type_packet (m
)
1143 register at_atp_t
*atp
;
1144 register at_ddp_t
*ddp
;
1145 register at_zip_t
*zip
;
1146 register u_long user_bytes
;
1147 register int user_byte
;
1149 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1150 if (ddp
->dst_socket
== ZIP_SOCKET
) {
1151 switch (ddp
->type
) {
1153 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1154 zip
= (at_zip_t
*)(gbuf_rptr(m
)
1157 zip
=(at_zip_t
*)(gbuf_rptr(gbuf_cont(m
)));
1158 return ((int)zip
->command
);
1160 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1161 atp
= (at_atp_t
*)(gbuf_rptr(m
)+DDP_X_HDR_SIZE
);
1163 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1164 /* Get the user bytes in network order */
1165 user_bytes
= UAL_VALUE(atp
->user_bytes
);
1166 user_byte
= user_bytes
>> 24; /* Get the zeroth byte */
1167 if ((user_byte
== ZIP_GETMYZONE
) ||
1168 (user_byte
== ZIP_GETZONELIST
) ||
1169 (user_byte
== ZIP_GETLOCALZONES
))
1180 /**********************************************************************
1181 * zip_handle_getmyzone()
1184 * Routine to handle ZIP GetMyZone request locally. It generates
1185 * a phony response to the outgoing ATP request and sends it up.
1187 * 07/12/94 : remark2 only called from ddp.c / ddp_output
1188 * should only be called from the home port, but
1189 * when we are a router we should know the infos for all
1190 * anyway, so reply locally with what we have in stock...
1192 **********************************************************************/
1194 int zip_handle_getmyzone(ifID
, m
)
1195 register at_ifaddr_t
*ifID
;
1199 register at_ddp_t
*ddp
;
1200 register at_ddp_t
*r_ddp
;
1201 register at_atp_t
*r_atp
;
1202 gbuf_t
*rm
; /* reply message */
1206 dPrintf(D_M_ZIP
, D_L_INFO
,
1207 ("zip_handle_getmyzone: local reply for port=%d\n",
1210 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ 1 + ifID
->ifZoneName
.len
;
1211 /* space for two headers and the zone name */
1212 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
1213 dPrintf(D_M_ZIP
, D_L_WARNING
,
1214 ("zip_handle_getmyzone: no buffer, port=%d\n",
1219 gbuf_rinc(rm
,AT_WR_OFFSET
);
1221 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1222 r_atp
= (at_atp_t
*)r_ddp
->data
;
1225 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1226 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1227 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1229 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1231 /* fill up the ddp header for reply */
1232 DDPLEN_ASSIGN(r_ddp
, size
);
1233 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1234 UAS_ASSIGN(r_ddp
->checksum
, 0);
1235 NET_ASSIGN(r_ddp
->dst_net
, ifID
->ifThisNode
.s_net
);
1236 NET_NET(r_ddp
->src_net
, ddp
->dst_net
);
1237 r_ddp
->dst_node
= ifID
->ifThisNode
.s_node
;
1238 r_ddp
->src_node
= ddp
->dst_node
;
1239 r_ddp
->dst_socket
= ddp
->src_socket
;
1240 r_ddp
->src_socket
= ZIP_SOCKET
;
1241 r_ddp
->type
= DDP_ATP
;
1243 /* fill up the atp header */
1244 r_atp
->cmd
= ATP_CMD_TRESP
;
1250 UAS_UAS(r_atp
->tid
, atp
->tid
);
1252 ulongtmp
= htonl(ulongtmp
);
1253 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
); /* no of zones */
1255 /* fill up atp data part */
1256 bcopy((caddr_t
) &ifID
->ifZoneName
, (caddr_t
) r_atp
->data
, ifID
->ifZoneName
.len
+1);
1258 /* all set to send the packet back up */
1260 timeout(send_phony_reply
, (caddr_t
) rm
, HZ
/20);
1265 send_phony_reply(arg
)
1268 gbuf_t
*rm
= (gbuf_t
*)arg
;
1269 boolean_t funnel_state
;
1271 funnel_state
= thread_funnel_set(network_flock
, TRUE
);
1273 ddp_input(rm
, ifID_home
);
1275 (void) thread_funnel_set(network_flock
, FALSE
);
1281 * zip_prep_query_packet: build the actual ddp packet for the zip query
1284 gbuf_t
*zip_prep_query_packet(ifID
, RouterNet
, RouterNode
)
1286 at_net_al RouterNet
; /* we want to send the Zip Query to that router */
1291 register at_ddp_t
*ddp
;
1293 if ((m
= gbuf_alloc (AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
1294 dPrintf(D_M_ZIP
, D_L_WARNING
,
1295 ("zip_send_query_packet: no buffer, port=%d\n",
1297 return((gbuf_t
*)NULL
);
1299 gbuf_rinc(m
,AT_WR_OFFSET
);
1302 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
1304 /* Prepare the DDP header */
1306 ddp
->unused
= ddp
->hopcount
= 0;
1307 UAS_ASSIGN(ddp
->checksum
, 0);
1308 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1309 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1310 ddp
->src_socket
= ZIP_SOCKET
;
1312 ddp
->dst_socket
= ZIP_SOCKET
;
1313 NET_ASSIGN(ddp
->dst_net
, RouterNet
);
1314 ddp
->dst_node
= RouterNode
;
1316 ddp
->type
= DDP_ZIP
;
1319 } /* zip_prep_query_packet */
1323 * zip_send_queries: this function send queries for the routing table entries that
1324 * need to know their zones. It scans the routing table for entries with unknown
1325 * zones and build Query packets accordingly.
1326 * Note: this is called on a per port basis.
1329 void zip_send_queries(ifID
, RouterNet
, RouterNode
)
1330 register at_ifaddr_t
*ifID
;
1331 at_net_al RouterNet
; /* we want to send the Zip Query to that router */
1334 RT_entry
*Entry
= &RT_table
[0];
1336 register at_ddp_t
*ddp
;
1338 short Query_index
, EntryNumber
= 0 ;
1339 register u_char port
= ifID
->ifPort
;
1340 char *QueryBuff
, *ZoneCount
;
1341 short zip_sent
= FALSE
;
1345 if (!(m
= zip_prep_query_packet(ifID
, RouterNet
, RouterNode
))) {
1346 return; /* was return (ENOBUFS); */
1349 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
1350 QueryBuff
= (char *)ddp
->data
;
1352 *QueryBuff
++ = ZIP_QUERY
;
1353 ZoneCount
= QueryBuff
; /* network count */
1359 while (EntryNumber
< RT_maxentry
) {
1361 /* scan the table, and build the packet with the right entries:
1362 * - entry in use and on the right Port
1363 * - with unknwon zones and in an active state
1364 * - talking to the right router
1367 if ((Query_index
) > 2*254 +2) {
1369 /* we need to send the packet now, but we can't have more than 256
1370 * requests for networks: the Netcount field is a 8bit in the zip query
1371 * packet format as defined in Inside Atalk
1374 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1375 ("zip_send_query: FULL query for %d nets on port#%d.(len=%d)\n",
1376 *ZoneCount
, port
, Query_index
));
1379 gbuf_winc(m
,DDP_X_HDR_SIZE
+ Query_index
);
1380 DDPLEN_ASSIGN(ddp
, DDP_X_HDR_SIZE
+ Query_index
);
1383 ddp_router_output(m
, ifID
, AT_ADDR
,
1384 RouterNet
, RouterNode
, 0))) {
1385 dPrintf(D_M_ZIP
, D_L_ERROR
,
1386 ("zip_send_query: ddp_router_output returns =%d\n", status
));
1387 return; /* was return (status); */
1394 if (((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
1395 (Entry
->NetStop
) && (Entry
->NetPort
== port
) &&
1396 (!RT_ALL_ZONES_KNOWN(Entry
))){
1398 /* we're ready to had that to our list of stuff to send */
1400 if (Entry
->NetStart
) { /* extended net*/
1402 *QueryBuff
++ = (Entry
->NetStart
& 0xFF00) >> 8;
1403 *QueryBuff
++ = (Entry
->NetStart
& 0x00FF);
1407 *QueryBuff
++ = (Entry
->NetStop
& 0xFF00) >> 8;
1408 *QueryBuff
++ = (Entry
->NetStop
& 0x00FF);
1412 *ZoneCount
+= 1;/* bump the number of network requested */
1421 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1422 ("zip_send_query: query for %d nets on port#%d.(len=%d)\n",
1423 *ZoneCount
, port
, Query_index
));
1425 if (*ZoneCount
) { /* non-full Query needs to be sent */
1427 gbuf_winc(m
,DDP_X_HDR_SIZE
+ Query_index
);
1428 DDPLEN_ASSIGN(ddp
, DDP_X_HDR_SIZE
+ Query_index
);
1431 ddp_router_output(m
, ifID
, AT_ADDR
,
1432 RouterNet
, RouterNode
, 0))) {
1433 dPrintf(D_M_ZIP
, D_L_ERROR
,
1434 ("zip_send_query: ddp_router_output returns =%d\n",
1436 return; /* was return (status); */
1442 if (!zip_sent
) /* we didn't need to send anything for that port */
1443 ifID
->ifZipNeedQueries
= 0;
1444 } /* zip_send_queries */
1446 /* zip_reply_received: we recieved the reply to one of our query, update the
1447 * zone bitmap and stuffs with was we received.
1448 * we receive two types of replies: non extended and extended.
1449 * For extended replies, the network count is the Total of zones for that net.
1452 zip_reply_received(m
, ifID
, reply_type
)
1454 register at_ifaddr_t
*ifID
;
1457 register at_nvestr_t
*zname
;
1458 RT_entry
*Entry
= &RT_table
[0];
1459 register at_ddp_t
*ddp
;
1461 u_short payload_len
, result
;
1462 u_char network_count
;
1465 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1467 /* access the number of nets provided in the ZIP Reply */
1469 network_count
= *(u_char
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
+ 1);
1471 PacketPtr
= (char *)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
+ 2);
1473 payload_len
= DDPLEN_VALUE(ddp
) - (DDP_X_HDR_SIZE
+ 2);
1475 dPrintf(D_M_ZIP_LOW
, D_L_INPUT
, ("zip_reply_received from %d:%d type=%d netcount=%d\n",
1476 NET_VALUE(ddp
->src_net
), ddp
->src_node
, reply_type
, network_count
));
1479 while (payload_len
> 0 && network_count
>0) {
1481 Network
= *(at_net_al
*)PacketPtr
;
1483 zname
= (at_nvestr_t
*)PacketPtr
;
1485 payload_len
= payload_len
-(zname
->len
+ 3);
1487 if (zname
->len
<= 0) { /* not valid, we got a problem here... */
1488 dPrintf(D_M_ZIP
, D_L_WARNING
,
1489 ("zip_reply_received: Problem zlen=0 for net=%d from %d:%d type=%d netcnt=%d\n",
1490 Network
, NET_VALUE(ddp
->src_net
), ddp
->src_node
, reply_type
, network_count
));
1496 Entry
= rt_blookup(Network
);
1498 if (Entry
!= NULL
) {
1500 if (Entry
->EntryState
>= RTE_STATE_SUSPECT
) {
1502 result
= zt_add_zonename(zname
);
1504 if (result
== ZT_MAXEDOUT
) {
1506 dPrintf(D_M_ZIP
, D_L_ERROR
,
1507 ("zip_reply_received: ZTable full from %d:%d on zone '%s'\n",
1508 NET_VALUE(ddp
->src_net
), ddp
->src_node
, zname
->str
));
1509 ErrorZIPoverflow
= 1;
1513 zt_set_zmap(result
, Entry
->ZoneBitMap
);
1515 RT_SET_ZONE_KNOWN(Entry
);
1519 dPrintf(D_M_ZIP
, D_L_INPUT
,
1520 ("zip_reply_received: entry %d-%d not updated, cause state=%d\n",
1521 Entry
->NetStart
, Entry
->NetStop
, Entry
->EntryState
));
1525 dPrintf(D_M_ZIP
, D_L_WARNING
,
1526 ("zip_reply_received: network %d not found in RT\n", Network
));
1530 /* now bump the PacketPtr pointer */
1531 PacketPtr
+= zname
->len
+ 1;
1535 if ((reply_type
== ZIP_REPLY
) && network_count
> 0) {
1537 dPrintf(D_M_ZIP
, D_L_WARNING
,
1538 ("zip_reply_received: Problem decoding zone (after net:%d-%d)\n",
1539 Entry
->NetStart
, Entry
->NetStop
));
1540 ifID
->ifZipNeedQueries
= 1;
1543 ifID
->ifZipNeedQueries
= 0;
1545 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1546 ("zip_reply_received: entry %d-%d all zones known\n",
1547 Entry
->NetStart
, Entry
->NetStop
));
1552 * zip_reply_to_getmyzone: replies to ZIP GetMyZone received from the Net
1555 static void zip_reply_to_getmyzone (ifID
, m
)
1556 register at_ifaddr_t
*ifID
;
1560 register at_ddp_t
*ddp
;
1561 register at_ddp_t
*r_ddp
;
1562 register at_atp_t
*r_atp
;
1563 register gbuf_t
*rm
; /* reply message */
1564 register int size
, Index
, status
;
1569 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ 1 + ifID
->ifZoneName
.len
;
1570 /* space for two headers and the zone name */
1571 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
1572 dPrintf(D_M_ZIP
, D_L_WARNING
,
1573 ("zip_reply_to_getmyzone: no buffer, port=%d\n", ifID
->ifPort
));
1574 return; /* was return (ENOBUFS); */
1576 gbuf_rinc(rm
,AT_WR_OFFSET
);
1578 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1579 r_atp
= (at_atp_t
*)r_ddp
->data
;
1581 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1582 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1583 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1585 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1587 /* fill up the ddp header for reply */
1588 DDPLEN_ASSIGN(r_ddp
, size
);
1589 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1590 UAS_ASSIGN(r_ddp
->checksum
, 0);
1592 NET_ASSIGN(r_ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1593 NET_NET(r_ddp
->dst_net
, ddp
->src_net
);
1595 r_ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1596 r_ddp
->dst_node
= ddp
->src_node
;
1598 r_ddp
->dst_socket
= ddp
->src_socket
;
1599 r_ddp
->src_socket
= ZIP_SOCKET
;
1600 r_ddp
->type
= DDP_ATP
;
1602 /* fill up the atp header */
1603 r_atp
->cmd
= ATP_CMD_TRESP
;
1609 UAS_UAS(r_atp
->tid
, atp
->tid
);
1611 ulongtmp
= htonl(ulongtmp
);
1612 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
); /* no of zones */
1614 data_ptr
= (char *)r_atp
->data
;
1617 * fill up atp data part with the zone name if we can find it...
1620 Entry
= rt_blookup(NET_VALUE(ddp
->src_net
));
1621 if (Entry
!= NULL
&& ((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
1622 RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
1624 Index
= zt_ent_zindex(Entry
->ZoneBitMap
) -1;
1626 *data_ptr
= ZT_table
[Index
].Zone
.len
;
1627 bcopy((caddr_t
) &ZT_table
[Index
].Zone
.str
, (caddr_t
) ++data_ptr
,
1628 ZT_table
[Index
].Zone
.len
);
1630 /* all set to send the packet back up */
1631 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1632 ("zip_reply_to_GMZ: ddp_router_output to %d:%d port %d\n",
1633 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, ifID
->ifPort
));
1636 ddp_router_output(rm
, ifID
, AT_ADDR
,
1637 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, 0))) {
1638 dPrintf(D_M_ZIP
, D_L_ERROR
,
1639 ("zip_reply_to_GMZ: ddp_r_output returns =%d\n", status
));
1640 return; /* was return (status); */
1648 * zip_reply_to_getzonelist: replies to ZIP GetZoneList requested from the Net
1651 zip_reply_to_getzonelist (ifID
, m
)
1652 register at_ifaddr_t
*ifID
;
1656 register at_ddp_t
*ddp
;
1657 register at_ddp_t
*r_ddp
;
1658 register at_atp_t
*r_atp
;
1659 register gbuf_t
*rm
; /* reply message */
1660 register int size
, status
;
1661 register short Index
=0, StartPoint
, ZLength
, PacketLen
=0;
1665 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1666 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1667 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1669 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1672 /* space for two headers and the zone name */
1674 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
1678 gbuf_rinc(rm
,AT_WR_OFFSET
);
1680 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1681 r_atp
= (at_atp_t
*)r_ddp
->data
;
1683 /* fill up the ddp header for reply */
1685 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1686 UAS_ASSIGN(r_ddp
->checksum
, 0);
1687 NET_ASSIGN(r_ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1688 NET_NET(r_ddp
->dst_net
, ddp
->src_net
);
1689 r_ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1690 r_ddp
->dst_node
= ddp
->src_node
;
1691 r_ddp
->dst_socket
= ddp
->src_socket
;
1692 r_ddp
->src_socket
= ZIP_SOCKET
;
1693 r_ddp
->type
= DDP_ATP
;
1695 /* fill up the atp header */
1697 r_atp
->cmd
= ATP_CMD_TRESP
;
1703 UAS_UAS(r_atp
->tid
, atp
->tid
);
1705 Reply
= (char *)r_atp
->data
;
1707 /* get the start index from the ATP request */
1709 StartPoint
= (UAL_VALUE(atp
->user_bytes
) & 0xffff) -1;
1711 /* find the next zone to send */
1713 while ((Index
< ZT_maxentry
) && StartPoint
> 0) {
1714 if (ZT_table
[Index
].Zone
.len
)
1720 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
, ("zip_reply_to_GZL: Index=%d\n", Index
));
1722 * fill up atp data part with the zone name if we can find it...
1725 while (Index
< ZT_maxentry
) {
1727 ZLength
= ZT_table
[Index
].Zone
.len
;
1729 if (ZT_table
[Index
].ZoneCount
&& ZLength
) {
1732 if (PacketLen
+ 8 + ZLength
+1 > DDP_DATA_SIZE
) /* packet full */
1736 bcopy((caddr_t
) &ZT_table
[Index
].Zone
.str
,
1739 PacketLen
+= ZLength
+ 1;
1745 if (Index
>= ZT_maxentry
) /* this is the end of the list */
1747 ulongtmp
+= 0x01000000;
1750 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
); /* # of zones and flag*/
1752 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ PacketLen
;
1754 DDPLEN_ASSIGN(r_ddp
, size
);
1756 /* all set to send the packet back up */
1758 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1759 ("zip_r_GZL: send packet to %d:%d port %d atp_len =%d\n",
1760 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, ifID
->ifPort
, PacketLen
));
1763 if (status
= ddp_router_output(rm
, ifID
, AT_ADDR
,
1764 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, 0)) {
1765 dPrintf(D_M_ZIP
, D_L_ERROR
, ("zip_reply_to_GZL: ddp_router_output returns=%d\n",
1774 * zip_reply_to_getlocalzones: replies to ZIP GetLocalZones requested from the Net
1777 int zip_reply_to_getlocalzones (ifID
, m
)
1778 register at_ifaddr_t
*ifID
;
1782 register at_ddp_t
*ddp
;
1783 register at_ddp_t
*r_ddp
;
1784 register at_atp_t
*r_atp
;
1785 register gbuf_t
*rm
; /* reply message */
1787 short Index
, Index_wanted
, ZLength
;
1788 short i
,j
, packet_len
;
1789 short zCount
, ZoneCount
, ZonesInPacket
;
1790 char *zmap
, last_flag
= 0;
1794 u_long ulongtmp
= 0;
1796 Index
= Index_wanted
= ZLength
= i
= j
= packet_len
= zCount
= ZoneCount
=
1799 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1800 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1801 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1803 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1805 /* space for two headers and the zone name */
1807 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
1811 gbuf_rinc(rm
,AT_WR_OFFSET
);
1813 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1814 r_atp
= (at_atp_t
*)r_ddp
->data
;
1816 Reply
= (char *)r_atp
->data
;
1819 /* get the start index from the ATP request */
1821 Index_wanted
= (UAL_VALUE(atp
->user_bytes
) & 0xffff) -1;
1823 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1824 ("zip_r_GLZ: for station %d:%d Index_wanted = %d\n",
1825 NET_VALUE(ddp
->src_net
), ddp
->src_node
, Index_wanted
));
1827 Entry
= rt_blookup(NET_VALUE(ddp
->src_net
));
1829 if (Entry
!= NULL
&& ((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
1830 RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
1832 ZoneCount
= zt_ent_zcount(Entry
) ;
1834 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1835 ("zip_reply_GLZ: for %d:%d ZoneCount=%d\n",
1836 NET_VALUE(ddp
->src_net
), ddp
->src_node
, ZoneCount
));
1838 zmap
= &Entry
->ZoneBitMap
[0];
1841 * first of all, we want to find the "first next zone" in the bitmap,
1842 * to do so, we need to scan the bitmap and add the number of valid
1843 * zones we find until we reach the next zone to be sent in the reply
1846 if (ZoneCount
> Index_wanted
) {
1848 ZoneCount
-= Index_wanted
;
1850 /* find the starting point in the bitmap according to index */
1852 for (i
= 0; Index_wanted
>= 0 && i
< ZT_BYTES
; i
++)
1854 if (Index_wanted
< 8) {
1855 /* how many zones in the bitmap byte */
1856 for (j
= 0, zCount
=0; j
< 8 ; j
++)
1857 if ((zmap
[i
] << j
) & 0x80)
1859 if (Index_wanted
< zCount
) {
1860 for (j
= 0 ; Index_wanted
> 0 && j
< 8 ; j
++)
1861 if ((zmap
[i
] << j
) & 0x80)
1866 Index_wanted
-= zCount
;
1869 for (j
= 0 ; j
< 8 ; j
++)
1870 if ((zmap
[i
] << j
) & 0x80)
1875 * now, we point to the begining of our next zones in the bitmap
1878 while (i
< ZT_BYTES
) {
1882 if ((zmap
[i
] << j
) & 0x80) {
1883 Index
= i
*8 + j
; /* get the index in ZT */
1885 ZLength
= ZT_table
[Index
].Zone
.len
;
1887 if (ZT_table
[Index
].ZoneCount
&& ZLength
) {
1888 if (packet_len
+ ATP_HDR_SIZE
+ ZLength
+ 1 >
1893 bcopy((caddr_t
) &ZT_table
[Index
].Zone
.str
,
1896 packet_len
+= ZLength
+ 1;
1898 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1899 ("zip_reply_GLZ: add z#%d to packet (l=%d)\n",
1900 Index
, packet_len
));
1903 dPrintf(D_M_ZIP
, D_L_WARNING
,
1904 ("zip_reply_GLZ: no len for index=%d\n",
1913 else /* set the "last flag" bit in the reply */
1916 else /* set the "last flag" bit in the reply */
1921 if (ZonesInPacket
== ZoneCount
)
1925 /* fill up the ddp header for reply */
1927 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1928 UAS_ASSIGN(r_ddp
->checksum
, 0);
1930 NET_ASSIGN(r_ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1931 NET_NET(r_ddp
->dst_net
, ddp
->src_net
);
1933 r_ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1934 r_ddp
->dst_node
= ddp
->src_node
;
1936 r_ddp
->dst_socket
= ddp
->src_socket
;
1937 r_ddp
->src_socket
= ZIP_SOCKET
;
1938 r_ddp
->type
= DDP_ATP
;
1940 /* fill up the atp header */
1941 r_atp
->cmd
= ATP_CMD_TRESP
;
1947 UAS_UAS(r_atp
->tid
, atp
->tid
);
1948 ulongtmp
= ((last_flag
<< 24) & 0xFF000000) + ZonesInPacket
; /* # of zones and flag*/
1949 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
);
1950 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ packet_len
;
1952 DDPLEN_ASSIGN(r_ddp
, size
);
1954 /* all set to send the packet back up */
1956 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1957 ("zip_r_GLZ: send packet to %d:%d port %d atp_len =%d\n",
1958 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, ifID
->ifPort
, packet_len
));
1960 if (status
= ddp_router_output(rm
, ifID
, AT_ADDR
,
1961 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, 0)) {
1962 dPrintf(D_M_ZIP
, D_L_ERROR
,
1963 ("zip_reply_to_GLZ: ddp_router_output returns =%d\n",
1968 } /* zip_reply_to_getlocalzones */
1970 int regDefaultZone(ifID
)
1974 char data
[ETHERNET_ADDR_LEN
];
1979 zt_get_zmcast(ifID
, &ifID
->ifZoneName
, data
);
1980 if (FDDI_OR_TOKENRING(ifID
->aa_ifp
->if_type
))
1981 ddp_bit_reverse(data
);
1982 bcopy((caddr_t
)data
, (caddr_t
)&ifID
->ZoneMcastAddr
, ETHERNET_ADDR_LEN
);
1983 (void)at_reg_mcast(ifID
, (caddr_t
)&ifID
->ZoneMcastAddr
);