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(at_ifaddr_t
*);
96 static void send_phony_reply(gbuf_t
*);
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(ifID
)
996 register at_ifaddr_t
*ifID
;
998 thread_funnel_set(network_flock
, TRUE
);
999 zip_getnetinfo(ifID
);
1000 thread_funnel_set(network_flock
, FALSE
);
1004 /**********************************************************************
1007 **********************************************************************/
1008 static void zip_getnetinfo (ifID
)
1009 register at_ifaddr_t
*ifID
;
1011 register at_x_zip_t
*zip
;
1013 register at_ddp_t
*ddp
;
1014 void zip_sched_getnetinfo();
1015 register struct atalk_addr
*at_dest
;
1018 size
= DDP_X_HDR_SIZE
+ ZIP_X_HDR_SIZE
+ ifID
->ifZoneName
.len
+ 1
1019 + sizeof(struct atalk_addr
) + 1;
1020 if ((m
= gbuf_alloc (AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
1021 /* This time, we're unable to allocate buffer to
1022 * send a packet out, so schedule to send a packet
1023 * out later, and exit.
1025 dPrintf(D_M_ZIP
, D_L_WARNING
, ("zip_getnetinfo: no buffer, call later port=%d\n",
1027 timeout (zip_getnetinfo_funnel
, (caddr_t
) ifID
, ZIP_TIMER_INT
/10);
1031 gbuf_rinc(m
,AT_WR_OFFSET
);
1033 *(u_char
*)gbuf_rptr(m
) = AT_ADDR
;
1034 at_dest
= (struct atalk_addr
*)(gbuf_rptr(m
) + 1);
1035 ddp
= (at_ddp_t
*)(gbuf_rptr(m
) + sizeof(struct atalk_addr
) + 1);
1036 zip
= (at_x_zip_t
*)ddp
->data
;
1039 zip
->command
= ZIP_GETNETINFO
;
1041 NET_ASSIGN(zip
->cable_range_start
, 0);
1042 NET_ASSIGN(zip
->cable_range_end
, 0);
1043 if (ifID
->ifZoneName
.len
) /* has to match reply exactly */
1044 bcopy((caddr_t
)&ifID
->ifZoneName
, (caddr_t
)zip
->data
,
1045 ifID
->ifZoneName
.len
+ 1);
1047 zip
->data
[0] = 0; /* No zone name is availbale */
1049 /* let the lap fields be uninitialized, 'cause it doesn't
1052 DDPLEN_ASSIGN(ddp
, size
- (sizeof(struct atalk_addr
) + 1));
1053 UAS_ASSIGN(ddp
->checksum
, 0);
1054 ddp
->hopcount
= ddp
->unused
= 0;
1055 NET_ASSIGN(ddp
->dst_net
, 0); /* cable-wide broadcast */
1056 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1057 /* By this time, AARP is done */
1059 ddp
->dst_node
= 0xff;
1060 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1061 ddp
->dst_socket
= ZIP_SOCKET
;
1062 ddp
->src_socket
= ZIP_SOCKET
;
1063 ddp
->type
= DDP_ZIP
;
1065 at_dest
->atalk_unused
= 0;
1066 NET_NET(at_dest
->atalk_net
, ddp
->dst_net
);
1067 at_dest
->atalk_node
= ddp
->dst_node
;
1069 dPrintf(D_M_ZIP
, D_L_INPUT
, ("zip_getnetinfo: called for port=%d\n",
1072 if (elap_dataput(m
, ifID
, 0, NULL
)) {
1073 dPrintf(D_M_ZIP
, D_L_ERROR
,
1074 ("zip_getnetinfo: error sending zip_getnetinfo\n"));
1078 ifID
->ifNumRetries
++;
1079 netinfo_reply_pending
= 1;
1081 timeout (zip_sched_getnetinfo
, (caddr_t
) ifID
, ZIP_TIMER_INT
);
1082 } /* zip_getnetinfo */
1085 /**********************************************************************
1086 * zip_sched_getnetinfo()
1088 **********************************************************************/
1090 void zip_sched_getnetinfo (ifID
)
1091 register at_ifaddr_t
*ifID
;
1093 boolean_t funnel_state
;
1095 funnel_state
= thread_funnel_set(network_flock
, TRUE
);
1097 if (ifID
->ifNumRetries
>= ZIP_NETINFO_RETRIES
) {
1098 /* enough packets sent.... give up! */
1099 /* we didn't get any response from the net, so
1100 * assume there's no router around and the given
1101 * zone name, if any, is not valid. Change the
1104 ifID
->ifZoneName
.len
= 1;
1105 ifID
->ifZoneName
.str
[0] = '*';
1106 ifID
->ifZoneName
.str
[1] = '\0';
1107 /* Should NBP be notified of this "new" zone name?? */
1108 netinfo_reply_pending
= 0;
1110 ifID
->ifRouterState
= NO_ROUTER
;
1111 ifID
->ifARouter
.s_net
= 0;
1112 ifID
->ifARouter
.s_node
= 0;
1114 dPrintf(D_M_ZIP
, D_L_INFO
, ("zip_sched_getnetinfo: Reset Cable Range\n"));
1116 ifID
->ifThisCableStart
= DDP_MIN_NETWORK
;
1117 ifID
->ifThisCableEnd
= DDP_MAX_NETWORK
;
1119 if (ifID
->ifState
== LAP_ONLINE_FOR_ZIP
)
1120 ZIPwakeup (ifID
, 0); /* no error */
1122 zip_getnetinfo(ifID
);
1124 (void) thread_funnel_set(network_flock
, FALSE
);
1128 /**********************************************************************
1132 * This routine checks whether or not the packet contained in "m"
1133 * is an (outgoing) ZIP packet. If not, it returns 0. If it is a
1134 * ZIP packet, it returns the ZIP packet type (ZIP command). "m"
1135 * points to a packet with extended DDP header. The rest of the
1136 * DDP data may or may not be in the first gbuf.
1138 **********************************************************************/
1139 int zip_type_packet (m
)
1142 register at_atp_t
*atp
;
1143 register at_ddp_t
*ddp
;
1144 register at_zip_t
*zip
;
1145 register u_long user_bytes
;
1146 register int user_byte
;
1148 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1149 if (ddp
->dst_socket
== ZIP_SOCKET
) {
1150 switch (ddp
->type
) {
1152 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1153 zip
= (at_zip_t
*)(gbuf_rptr(m
)
1156 zip
=(at_zip_t
*)(gbuf_rptr(gbuf_cont(m
)));
1157 return ((int)zip
->command
);
1159 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1160 atp
= (at_atp_t
*)(gbuf_rptr(m
)+DDP_X_HDR_SIZE
);
1162 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1163 /* Get the user bytes in network order */
1164 user_bytes
= UAL_VALUE(atp
->user_bytes
);
1165 user_byte
= user_bytes
>> 24; /* Get the zeroth byte */
1166 if ((user_byte
== ZIP_GETMYZONE
) ||
1167 (user_byte
== ZIP_GETZONELIST
) ||
1168 (user_byte
== ZIP_GETLOCALZONES
))
1179 /**********************************************************************
1180 * zip_handle_getmyzone()
1183 * Routine to handle ZIP GetMyZone request locally. It generates
1184 * a phony response to the outgoing ATP request and sends it up.
1186 * 07/12/94 : remark2 only called from ddp.c / ddp_output
1187 * should only be called from the home port, but
1188 * when we are a router we should know the infos for all
1189 * anyway, so reply locally with what we have in stock...
1191 **********************************************************************/
1193 int zip_handle_getmyzone(ifID
, m
)
1194 register at_ifaddr_t
*ifID
;
1198 register at_ddp_t
*ddp
;
1199 register at_ddp_t
*r_ddp
;
1200 register at_atp_t
*r_atp
;
1201 gbuf_t
*rm
; /* reply message */
1205 dPrintf(D_M_ZIP
, D_L_INFO
,
1206 ("zip_handle_getmyzone: local reply for port=%d\n",
1209 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ 1 + ifID
->ifZoneName
.len
;
1210 /* space for two headers and the zone name */
1211 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
1212 dPrintf(D_M_ZIP
, D_L_WARNING
,
1213 ("zip_handle_getmyzone: no buffer, port=%d\n",
1218 gbuf_rinc(rm
,AT_WR_OFFSET
);
1220 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1221 r_atp
= (at_atp_t
*)r_ddp
->data
;
1224 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1225 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1226 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1228 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1230 /* fill up the ddp header for reply */
1231 DDPLEN_ASSIGN(r_ddp
, size
);
1232 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1233 UAS_ASSIGN(r_ddp
->checksum
, 0);
1234 NET_ASSIGN(r_ddp
->dst_net
, ifID
->ifThisNode
.s_net
);
1235 NET_NET(r_ddp
->src_net
, ddp
->dst_net
);
1236 r_ddp
->dst_node
= ifID
->ifThisNode
.s_node
;
1237 r_ddp
->src_node
= ddp
->dst_node
;
1238 r_ddp
->dst_socket
= ddp
->src_socket
;
1239 r_ddp
->src_socket
= ZIP_SOCKET
;
1240 r_ddp
->type
= DDP_ATP
;
1242 /* fill up the atp header */
1243 r_atp
->cmd
= ATP_CMD_TRESP
;
1249 UAS_UAS(r_atp
->tid
, atp
->tid
);
1251 ulongtmp
= htonl(ulongtmp
);
1252 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
); /* no of zones */
1254 /* fill up atp data part */
1255 bcopy((caddr_t
) &ifID
->ifZoneName
, (caddr_t
) r_atp
->data
, ifID
->ifZoneName
.len
+1);
1257 /* all set to send the packet back up */
1259 timeout(send_phony_reply
, (caddr_t
) rm
, HZ
/20);
1264 send_phony_reply(rm
)
1267 boolean_t funnel_state
;
1269 funnel_state
= thread_funnel_set(network_flock
, TRUE
);
1271 ddp_input(rm
, ifID_home
);
1273 (void) thread_funnel_set(network_flock
, FALSE
);
1279 * zip_prep_query_packet: build the actual ddp packet for the zip query
1282 gbuf_t
*zip_prep_query_packet(ifID
, RouterNet
, RouterNode
)
1284 at_net_al RouterNet
; /* we want to send the Zip Query to that router */
1289 register at_ddp_t
*ddp
;
1291 if ((m
= gbuf_alloc (AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
1292 dPrintf(D_M_ZIP
, D_L_WARNING
,
1293 ("zip_send_query_packet: no buffer, port=%d\n",
1295 return((gbuf_t
*)NULL
);
1297 gbuf_rinc(m
,AT_WR_OFFSET
);
1300 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
1302 /* Prepare the DDP header */
1304 ddp
->unused
= ddp
->hopcount
= 0;
1305 UAS_ASSIGN(ddp
->checksum
, 0);
1306 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1307 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1308 ddp
->src_socket
= ZIP_SOCKET
;
1310 ddp
->dst_socket
= ZIP_SOCKET
;
1311 NET_ASSIGN(ddp
->dst_net
, RouterNet
);
1312 ddp
->dst_node
= RouterNode
;
1314 ddp
->type
= DDP_ZIP
;
1317 } /* zip_prep_query_packet */
1321 * zip_send_queries: this function send queries for the routing table entries that
1322 * need to know their zones. It scans the routing table for entries with unknown
1323 * zones and build Query packets accordingly.
1324 * Note: this is called on a per port basis.
1327 void zip_send_queries(ifID
, RouterNet
, RouterNode
)
1328 register at_ifaddr_t
*ifID
;
1329 at_net_al RouterNet
; /* we want to send the Zip Query to that router */
1332 RT_entry
*Entry
= &RT_table
[0];
1334 register at_ddp_t
*ddp
;
1336 short Query_index
, EntryNumber
= 0 ;
1337 register u_char port
= ifID
->ifPort
;
1338 char *QueryBuff
, *ZoneCount
;
1339 short zip_sent
= FALSE
;
1343 if (!(m
= zip_prep_query_packet(ifID
, RouterNet
, RouterNode
))) {
1344 return; /* was return (ENOBUFS); */
1347 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
1348 QueryBuff
= (char *)ddp
->data
;
1350 *QueryBuff
++ = ZIP_QUERY
;
1351 ZoneCount
= QueryBuff
; /* network count */
1357 while (EntryNumber
< RT_maxentry
) {
1359 /* scan the table, and build the packet with the right entries:
1360 * - entry in use and on the right Port
1361 * - with unknwon zones and in an active state
1362 * - talking to the right router
1365 if ((Query_index
) > 2*254 +2) {
1367 /* we need to send the packet now, but we can't have more than 256
1368 * requests for networks: the Netcount field is a 8bit in the zip query
1369 * packet format as defined in Inside Atalk
1372 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1373 ("zip_send_query: FULL query for %d nets on port#%d.(len=%d)\n",
1374 *ZoneCount
, port
, Query_index
));
1377 gbuf_winc(m
,DDP_X_HDR_SIZE
+ Query_index
);
1378 DDPLEN_ASSIGN(ddp
, DDP_X_HDR_SIZE
+ Query_index
);
1381 ddp_router_output(m
, ifID
, AT_ADDR
,
1382 RouterNet
, RouterNode
, 0))) {
1383 dPrintf(D_M_ZIP
, D_L_ERROR
,
1384 ("zip_send_query: ddp_router_output returns =%d\n", status
));
1385 return; /* was return (status); */
1392 if (((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
1393 (Entry
->NetStop
) && (Entry
->NetPort
== port
) &&
1394 (!RT_ALL_ZONES_KNOWN(Entry
))){
1396 /* we're ready to had that to our list of stuff to send */
1398 if (Entry
->NetStart
) { /* extended net*/
1400 *QueryBuff
++ = (Entry
->NetStart
& 0xFF00) >> 8;
1401 *QueryBuff
++ = (Entry
->NetStart
& 0x00FF);
1405 *QueryBuff
++ = (Entry
->NetStop
& 0xFF00) >> 8;
1406 *QueryBuff
++ = (Entry
->NetStop
& 0x00FF);
1410 *ZoneCount
+= 1;/* bump the number of network requested */
1419 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1420 ("zip_send_query: query for %d nets on port#%d.(len=%d)\n",
1421 *ZoneCount
, port
, Query_index
));
1423 if (*ZoneCount
) { /* non-full Query needs to be sent */
1425 gbuf_winc(m
,DDP_X_HDR_SIZE
+ Query_index
);
1426 DDPLEN_ASSIGN(ddp
, DDP_X_HDR_SIZE
+ Query_index
);
1429 ddp_router_output(m
, ifID
, AT_ADDR
,
1430 RouterNet
, RouterNode
, 0))) {
1431 dPrintf(D_M_ZIP
, D_L_ERROR
,
1432 ("zip_send_query: ddp_router_output returns =%d\n",
1434 return; /* was return (status); */
1440 if (!zip_sent
) /* we didn't need to send anything for that port */
1441 ifID
->ifZipNeedQueries
= 0;
1442 } /* zip_send_queries */
1444 /* zip_reply_received: we recieved the reply to one of our query, update the
1445 * zone bitmap and stuffs with was we received.
1446 * we receive two types of replies: non extended and extended.
1447 * For extended replies, the network count is the Total of zones for that net.
1450 zip_reply_received(m
, ifID
, reply_type
)
1452 register at_ifaddr_t
*ifID
;
1455 register at_nvestr_t
*zname
;
1456 RT_entry
*Entry
= &RT_table
[0];
1457 register at_ddp_t
*ddp
;
1459 u_short payload_len
, result
;
1460 u_char network_count
;
1463 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1465 /* access the number of nets provided in the ZIP Reply */
1467 network_count
= *(u_char
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
+ 1);
1469 PacketPtr
= (char *)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
+ 2);
1471 payload_len
= DDPLEN_VALUE(ddp
) - (DDP_X_HDR_SIZE
+ 2);
1473 dPrintf(D_M_ZIP_LOW
, D_L_INPUT
, ("zip_reply_received from %d:%d type=%d netcount=%d\n",
1474 NET_VALUE(ddp
->src_net
), ddp
->src_node
, reply_type
, network_count
));
1477 while (payload_len
> 0 && network_count
>0) {
1479 Network
= *(at_net_al
*)PacketPtr
;
1481 zname
= (at_nvestr_t
*)PacketPtr
;
1483 payload_len
= payload_len
-(zname
->len
+ 3);
1485 if (zname
->len
<= 0) { /* not valid, we got a problem here... */
1486 dPrintf(D_M_ZIP
, D_L_WARNING
,
1487 ("zip_reply_received: Problem zlen=0 for net=%d from %d:%d type=%d netcnt=%d\n",
1488 Network
, NET_VALUE(ddp
->src_net
), ddp
->src_node
, reply_type
, network_count
));
1494 Entry
= rt_blookup(Network
);
1496 if (Entry
!= NULL
) {
1498 if (Entry
->EntryState
>= RTE_STATE_SUSPECT
) {
1500 result
= zt_add_zonename(zname
);
1502 if (result
== ZT_MAXEDOUT
) {
1504 dPrintf(D_M_ZIP
, D_L_ERROR
,
1505 ("zip_reply_received: ZTable full from %d:%d on zone '%s'\n",
1506 NET_VALUE(ddp
->src_net
), ddp
->src_node
, zname
->str
));
1507 ErrorZIPoverflow
= 1;
1511 zt_set_zmap(result
, Entry
->ZoneBitMap
);
1513 RT_SET_ZONE_KNOWN(Entry
);
1517 dPrintf(D_M_ZIP
, D_L_INPUT
,
1518 ("zip_reply_received: entry %d-%d not updated, cause state=%d\n",
1519 Entry
->NetStart
, Entry
->NetStop
, Entry
->EntryState
));
1523 dPrintf(D_M_ZIP
, D_L_WARNING
,
1524 ("zip_reply_received: network %d not found in RT\n", Network
));
1528 /* now bump the PacketPtr pointer */
1529 PacketPtr
+= zname
->len
+ 1;
1533 if ((reply_type
== ZIP_REPLY
) && network_count
> 0) {
1535 dPrintf(D_M_ZIP
, D_L_WARNING
,
1536 ("zip_reply_received: Problem decoding zone (after net:%d-%d)\n",
1537 Entry
->NetStart
, Entry
->NetStop
));
1538 ifID
->ifZipNeedQueries
= 1;
1541 ifID
->ifZipNeedQueries
= 0;
1543 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1544 ("zip_reply_received: entry %d-%d all zones known\n",
1545 Entry
->NetStart
, Entry
->NetStop
));
1550 * zip_reply_to_getmyzone: replies to ZIP GetMyZone received from the Net
1553 static void zip_reply_to_getmyzone (ifID
, m
)
1554 register at_ifaddr_t
*ifID
;
1558 register at_ddp_t
*ddp
;
1559 register at_ddp_t
*r_ddp
;
1560 register at_atp_t
*r_atp
;
1561 register gbuf_t
*rm
; /* reply message */
1562 register int size
, Index
, status
;
1567 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ 1 + ifID
->ifZoneName
.len
;
1568 /* space for two headers and the zone name */
1569 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
1570 dPrintf(D_M_ZIP
, D_L_WARNING
,
1571 ("zip_reply_to_getmyzone: no buffer, port=%d\n", ifID
->ifPort
));
1572 return; /* was return (ENOBUFS); */
1574 gbuf_rinc(rm
,AT_WR_OFFSET
);
1576 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1577 r_atp
= (at_atp_t
*)r_ddp
->data
;
1579 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1580 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1581 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1583 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1585 /* fill up the ddp header for reply */
1586 DDPLEN_ASSIGN(r_ddp
, size
);
1587 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1588 UAS_ASSIGN(r_ddp
->checksum
, 0);
1590 NET_ASSIGN(r_ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1591 NET_NET(r_ddp
->dst_net
, ddp
->src_net
);
1593 r_ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1594 r_ddp
->dst_node
= ddp
->src_node
;
1596 r_ddp
->dst_socket
= ddp
->src_socket
;
1597 r_ddp
->src_socket
= ZIP_SOCKET
;
1598 r_ddp
->type
= DDP_ATP
;
1600 /* fill up the atp header */
1601 r_atp
->cmd
= ATP_CMD_TRESP
;
1607 UAS_UAS(r_atp
->tid
, atp
->tid
);
1609 ulongtmp
= htonl(ulongtmp
);
1610 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
); /* no of zones */
1612 data_ptr
= (char *)r_atp
->data
;
1615 * fill up atp data part with the zone name if we can find it...
1618 Entry
= rt_blookup(NET_VALUE(ddp
->src_net
));
1619 if (Entry
!= NULL
&& ((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
1620 RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
1622 Index
= zt_ent_zindex(Entry
->ZoneBitMap
) -1;
1624 *data_ptr
= ZT_table
[Index
].Zone
.len
;
1625 bcopy((caddr_t
) &ZT_table
[Index
].Zone
.str
, (caddr_t
) ++data_ptr
,
1626 ZT_table
[Index
].Zone
.len
);
1628 /* all set to send the packet back up */
1629 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1630 ("zip_reply_to_GMZ: ddp_router_output to %d:%d port %d\n",
1631 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, ifID
->ifPort
));
1634 ddp_router_output(rm
, ifID
, AT_ADDR
,
1635 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, 0))) {
1636 dPrintf(D_M_ZIP
, D_L_ERROR
,
1637 ("zip_reply_to_GMZ: ddp_r_output returns =%d\n", status
));
1638 return; /* was return (status); */
1646 * zip_reply_to_getzonelist: replies to ZIP GetZoneList requested from the Net
1649 zip_reply_to_getzonelist (ifID
, m
)
1650 register at_ifaddr_t
*ifID
;
1654 register at_ddp_t
*ddp
;
1655 register at_ddp_t
*r_ddp
;
1656 register at_atp_t
*r_atp
;
1657 register gbuf_t
*rm
; /* reply message */
1658 register int size
, status
;
1659 register short Index
=0, StartPoint
, ZLength
, PacketLen
=0;
1663 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1664 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1665 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1667 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1670 /* space for two headers and the zone name */
1672 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
1676 gbuf_rinc(rm
,AT_WR_OFFSET
);
1678 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1679 r_atp
= (at_atp_t
*)r_ddp
->data
;
1681 /* fill up the ddp header for reply */
1683 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1684 UAS_ASSIGN(r_ddp
->checksum
, 0);
1685 NET_ASSIGN(r_ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1686 NET_NET(r_ddp
->dst_net
, ddp
->src_net
);
1687 r_ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1688 r_ddp
->dst_node
= ddp
->src_node
;
1689 r_ddp
->dst_socket
= ddp
->src_socket
;
1690 r_ddp
->src_socket
= ZIP_SOCKET
;
1691 r_ddp
->type
= DDP_ATP
;
1693 /* fill up the atp header */
1695 r_atp
->cmd
= ATP_CMD_TRESP
;
1701 UAS_UAS(r_atp
->tid
, atp
->tid
);
1703 Reply
= (char *)r_atp
->data
;
1705 /* get the start index from the ATP request */
1707 StartPoint
= (UAL_VALUE(atp
->user_bytes
) & 0xffff) -1;
1709 /* find the next zone to send */
1711 while ((Index
< ZT_maxentry
) && StartPoint
> 0) {
1712 if (ZT_table
[Index
].Zone
.len
)
1718 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
, ("zip_reply_to_GZL: Index=%d\n", Index
));
1720 * fill up atp data part with the zone name if we can find it...
1723 while (Index
< ZT_maxentry
) {
1725 ZLength
= ZT_table
[Index
].Zone
.len
;
1727 if (ZT_table
[Index
].ZoneCount
&& ZLength
) {
1730 if (PacketLen
+ 8 + ZLength
+1 > DDP_DATA_SIZE
) /* packet full */
1734 bcopy((caddr_t
) &ZT_table
[Index
].Zone
.str
,
1737 PacketLen
+= ZLength
+ 1;
1743 if (Index
>= ZT_maxentry
) /* this is the end of the list */
1745 ulongtmp
+= 0x01000000;
1748 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
); /* # of zones and flag*/
1750 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ PacketLen
;
1752 DDPLEN_ASSIGN(r_ddp
, size
);
1754 /* all set to send the packet back up */
1756 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1757 ("zip_r_GZL: send packet to %d:%d port %d atp_len =%d\n",
1758 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, ifID
->ifPort
, PacketLen
));
1761 if (status
= ddp_router_output(rm
, ifID
, AT_ADDR
,
1762 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, 0)) {
1763 dPrintf(D_M_ZIP
, D_L_ERROR
, ("zip_reply_to_GZL: ddp_router_output returns=%d\n",
1772 * zip_reply_to_getlocalzones: replies to ZIP GetLocalZones requested from the Net
1775 int zip_reply_to_getlocalzones (ifID
, m
)
1776 register at_ifaddr_t
*ifID
;
1780 register at_ddp_t
*ddp
;
1781 register at_ddp_t
*r_ddp
;
1782 register at_atp_t
*r_atp
;
1783 register gbuf_t
*rm
; /* reply message */
1785 short Index
, Index_wanted
, ZLength
;
1786 short i
,j
, packet_len
;
1787 short zCount
, ZoneCount
, ZonesInPacket
;
1788 char *zmap
, last_flag
= 0;
1792 u_long ulongtmp
= 0;
1794 Index
= Index_wanted
= ZLength
= i
= j
= packet_len
= zCount
= ZoneCount
=
1797 ddp
= (at_ddp_t
*)gbuf_rptr(m
);
1798 if (gbuf_len(m
) > DDP_X_HDR_SIZE
)
1799 atp
= (at_atp_t
*)(gbuf_rptr(m
) + DDP_X_HDR_SIZE
);
1801 atp
= (at_atp_t
*)(gbuf_rptr(gbuf_cont(m
)));
1803 /* space for two headers and the zone name */
1805 if ((rm
= gbuf_alloc(AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
1809 gbuf_rinc(rm
,AT_WR_OFFSET
);
1811 r_ddp
= (at_ddp_t
*)(gbuf_rptr(rm
));
1812 r_atp
= (at_atp_t
*)r_ddp
->data
;
1814 Reply
= (char *)r_atp
->data
;
1817 /* get the start index from the ATP request */
1819 Index_wanted
= (UAL_VALUE(atp
->user_bytes
) & 0xffff) -1;
1821 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1822 ("zip_r_GLZ: for station %d:%d Index_wanted = %d\n",
1823 NET_VALUE(ddp
->src_net
), ddp
->src_node
, Index_wanted
));
1825 Entry
= rt_blookup(NET_VALUE(ddp
->src_net
));
1827 if (Entry
!= NULL
&& ((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
) &&
1828 RT_ALL_ZONES_KNOWN(Entry
)) { /* this net is well known... */
1830 ZoneCount
= zt_ent_zcount(Entry
) ;
1832 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1833 ("zip_reply_GLZ: for %d:%d ZoneCount=%d\n",
1834 NET_VALUE(ddp
->src_net
), ddp
->src_node
, ZoneCount
));
1836 zmap
= &Entry
->ZoneBitMap
[0];
1839 * first of all, we want to find the "first next zone" in the bitmap,
1840 * to do so, we need to scan the bitmap and add the number of valid
1841 * zones we find until we reach the next zone to be sent in the reply
1844 if (ZoneCount
> Index_wanted
) {
1846 ZoneCount
-= Index_wanted
;
1848 /* find the starting point in the bitmap according to index */
1850 for (i
= 0; Index_wanted
>= 0 && i
< ZT_BYTES
; i
++)
1852 if (Index_wanted
< 8) {
1853 /* how many zones in the bitmap byte */
1854 for (j
= 0, zCount
=0; j
< 8 ; j
++)
1855 if ((zmap
[i
] << j
) & 0x80)
1857 if (Index_wanted
< zCount
) {
1858 for (j
= 0 ; Index_wanted
> 0 && j
< 8 ; j
++)
1859 if ((zmap
[i
] << j
) & 0x80)
1864 Index_wanted
-= zCount
;
1867 for (j
= 0 ; j
< 8 ; j
++)
1868 if ((zmap
[i
] << j
) & 0x80)
1873 * now, we point to the begining of our next zones in the bitmap
1876 while (i
< ZT_BYTES
) {
1880 if ((zmap
[i
] << j
) & 0x80) {
1881 Index
= i
*8 + j
; /* get the index in ZT */
1883 ZLength
= ZT_table
[Index
].Zone
.len
;
1885 if (ZT_table
[Index
].ZoneCount
&& ZLength
) {
1886 if (packet_len
+ ATP_HDR_SIZE
+ ZLength
+ 1 >
1891 bcopy((caddr_t
) &ZT_table
[Index
].Zone
.str
,
1894 packet_len
+= ZLength
+ 1;
1896 dPrintf(D_M_ZIP_LOW
, D_L_INFO
,
1897 ("zip_reply_GLZ: add z#%d to packet (l=%d)\n",
1898 Index
, packet_len
));
1901 dPrintf(D_M_ZIP
, D_L_WARNING
,
1902 ("zip_reply_GLZ: no len for index=%d\n",
1911 else /* set the "last flag" bit in the reply */
1914 else /* set the "last flag" bit in the reply */
1919 if (ZonesInPacket
== ZoneCount
)
1923 /* fill up the ddp header for reply */
1925 r_ddp
->hopcount
= r_ddp
->unused
= 0;
1926 UAS_ASSIGN(r_ddp
->checksum
, 0);
1928 NET_ASSIGN(r_ddp
->src_net
, ifID
->ifThisNode
.s_net
);
1929 NET_NET(r_ddp
->dst_net
, ddp
->src_net
);
1931 r_ddp
->src_node
= ifID
->ifThisNode
.s_node
;
1932 r_ddp
->dst_node
= ddp
->src_node
;
1934 r_ddp
->dst_socket
= ddp
->src_socket
;
1935 r_ddp
->src_socket
= ZIP_SOCKET
;
1936 r_ddp
->type
= DDP_ATP
;
1938 /* fill up the atp header */
1939 r_atp
->cmd
= ATP_CMD_TRESP
;
1945 UAS_UAS(r_atp
->tid
, atp
->tid
);
1946 ulongtmp
= ((last_flag
<< 24) & 0xFF000000) + ZonesInPacket
; /* # of zones and flag*/
1947 UAL_ASSIGN(r_atp
->user_bytes
, ulongtmp
);
1948 size
= DDP_X_HDR_SIZE
+ ATP_HDR_SIZE
+ packet_len
;
1950 DDPLEN_ASSIGN(r_ddp
, size
);
1952 /* all set to send the packet back up */
1954 dPrintf(D_M_ZIP_LOW
, D_L_OUTPUT
,
1955 ("zip_r_GLZ: send packet to %d:%d port %d atp_len =%d\n",
1956 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, ifID
->ifPort
, packet_len
));
1958 if (status
= ddp_router_output(rm
, ifID
, AT_ADDR
,
1959 NET_VALUE(r_ddp
->dst_net
), r_ddp
->dst_node
, 0)) {
1960 dPrintf(D_M_ZIP
, D_L_ERROR
,
1961 ("zip_reply_to_GLZ: ddp_router_output returns =%d\n",
1966 } /* zip_reply_to_getlocalzones */
1968 int regDefaultZone(ifID
)
1972 char data
[ETHERNET_ADDR_LEN
];
1977 zt_get_zmcast(ifID
, &ifID
->ifZoneName
, data
);
1978 if (FDDI_OR_TOKENRING(ifID
->aa_ifp
->if_type
))
1979 ddp_bit_reverse(data
);
1980 bcopy((caddr_t
)data
, (caddr_t
)&ifID
->ZoneMcastAddr
, ETHERNET_ADDR_LEN
);
1981 (void)at_reg_mcast(ifID
, (caddr_t
)&ifID
->ZoneMcastAddr
);