]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/ddp_r_rtmp.c
2 * Copyright (c) 1994, 1996-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /*--------------------------------------------------------------------------
29 * Router RTMP protocol functions:
31 * This file contains Routing specifics to handle RTMP packets and
32 * the maintenance of the routing table through....
34 * The entry point for the rtmp input in ddp is valid only when we're
35 * running in router mode.
38 * 0.01 03/22/94 Laurent Dumont Creation
39 * Modified for MP, 1996 by Tuyen Nguyen
40 * Added AURP support, April 8, 1996 by Tuyen Nguyen
41 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
43 *-------------------------------------------------------------------------
46 #include <sys/errno.h>
47 #include <sys/types.h>
48 #include <sys/param.h>
49 #include <machine/spl.h>
50 #include <sys/systm.h>
51 #include <sys/kernel.h>
53 #include <sys/filedesc.h>
54 #include <sys/fcntl.h>
56 #include <sys/ioctl.h>
57 #include <sys/malloc.h>
58 #include <kern/locks.h>
59 #include <sys/socket.h>
60 #include <sys/socketvar.h>
64 #include <netat/sysglue.h>
65 #include <netat/appletalk.h>
66 #include <netat/at_var.h>
67 #include <netat/ddp.h>
68 #include <netat/rtmp.h>
69 #include <netat/at_pcb.h>
70 #include <netat/zip.h>
71 #include <netat/routing_tables.h>
72 #include <netat/aurp.h>
73 #include <netat/debug.h>
75 #include <sys/kern_event.h>
77 extern void (*ddp_AURPsendx
)();
78 extern at_ifaddr_t
*aurp_ifID
;
79 extern at_ifaddr_t
*ifID_table
[];
80 extern at_ifaddr_t
*ifID_home
;
83 static int dump_counter
=0;
86 static at_kern_err_t ke
;
87 /* Used to record error discovered in rtmp_update() */
88 gbuf_t
*rtmp_prep_new_packet();
91 void rtmp_send_port();
92 void rtmp_send_port_locked();
93 void rtmp_dropper(void *);
95 static void rtmp_update();
96 static void rtmp_request();
97 extern int elap_online3();
99 extern pktsIn
, pktsOut
, pktsDropped
, pktsHome
;
100 extern short ErrorRTMPoverflow
, ErrorZIPoverflow
;
101 extern atlock_t ddpinp_lock
;
102 extern lck_mtx_t
* atalk_mutex
;
105 * rtmp_router_input: function called by DDP (in router mode) to handle
106 * all incoming RTMP packets. Listen to the RTMP socket
107 * for all the connected ports.
108 * Switch to the relevant rtmp functions.
111 void rtmp_router_input(mp
, ifID
)
113 register at_ifaddr_t
*ifID
;
115 register at_ddp_t
*ddp
= (at_ddp_t
*)gbuf_rptr(mp
);
116 /* NOTE: there is an assumption here that the
117 * DATA follows the header. */
119 register at_net_al OurNet
;
120 register at_node OurNode
;
121 register at_net_al DstNet
;
122 register at_node DstNode
;
126 if (!ifID
|| (ifID
->ifRoutingState
< PORT_ACTIVATING
)) {
132 OurNet
= ifID
->ifThisNode
.s_net
;
133 OurNode
= ifID
->ifThisNode
.s_node
;
136 if (gbuf_type(mp
) != MSG_DATA
) {
138 /* If this is a M_ERROR message, DDP is shutting down,
139 * nothing to do here...If it's something else, we don't
140 * understand what it is
142 dPrintf(D_M_RTMP
, D_L_WARNING
,
143 ("rtmp_router_input: Not an M_DATA type\n"));
148 DstNet
= NET_VALUE(ddp
->dst_net
);
149 DstNode
= ddp
->dst_node
;
151 /* check the kind of RTMP packet we received */
157 tuples
= gbuf_len(mp
) - DDP_X_HDR_SIZE
- RTMP_IDLENGTH
;
159 * we need to make sure that the size of 'tuples' is
160 * not less than or equal to 0 due to a bad packet
167 if (tuples
% 3) {/* not a valid RTMP data packet */
169 dPrintf(D_M_RTMP
, D_L_WARNING
,
170 ("rtmp_input: bad number of tuple in RTMP packet\n"));
176 rtmp_update(ifID
, (at_rtmp
*)ddp
->data
, tuples
);
183 /* we should treat requests a bit differently.
184 * - if the request if not for the port, route it and also respond
185 * for this port if not locally connected.
186 * - if the request for this port, then just respond to it.
193 if (DstNode
== 255) {
194 if (((DstNet
>= CableStart
) && (DstNet
<= CableStop
)) ||
196 rtmp_request(ifID
, ddp
);
201 /* check if directly connected port */
202 if ((Entry
= rt_blookup(DstNet
)) &&
203 (Entry
->NetDist
== 0)) {
204 dPrintf(D_M_RTMP
, D_L_WARNING
,
205 ("rtmp_router_input: request for %d.%d, port %d\n",
206 DstNet
, DstNode
, Entry
->NetPort
));
207 rtmp_request(ifID_table
[Entry
->NetPort
], ddp
);
212 dPrintf(D_M_RTMP
, D_L_WARNING
,
213 ("rtmp_router_input: RTMP packet received for %d.%d, also forward\n",
214 NET_VALUE(ddp
->dst_net
),ddp
->dst_node
));
215 routing_needed(mp
, ifID
, TRUE
);
222 if ((DstNode
== OurNode
) && (DstNet
== OurNet
)) {
223 rtmp_request(ifID
, ddp
);
228 dPrintf(D_M_RTMP
, D_L_WARNING
,
229 ("rtmp_router_input: RTMP packet received for %d.%d, forward\n",
230 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
));
231 routing_needed(mp
, ifID
, TRUE
);
239 dPrintf(D_M_RTMP
, D_L_WARNING
,
240 ("rtmp_input: RTMP packet type=%d, route it\n", ddp
->type
));
241 routing_needed(mp
, ifID
, TRUE
);
245 } /* rtmp_router_input */
252 static void rtmp_update(ifID
, rtmp
, tuple_nb
)
253 register at_ifaddr_t
*ifID
;
254 register at_rtmp
*rtmp
;
255 register short tuple_nb
;
257 register int PortFlags
= ifID
->ifFlags
;
258 register at_rtmp_tuple
*FirstTuple
= (at_rtmp_tuple
*)&rtmp
->at_rtmp_id
[1];
259 register at_rtmp_tuple
*SecondTuple
= (at_rtmp_tuple
*)&rtmp
->at_rtmp_id
[4];
260 RT_entry NewRoute
, *CurrentRoute
;
262 register u_char SenderNodeID
= rtmp
->at_rtmp_id
[0];
267 /* Make sure this an AppleTalk node sending us the RTMP packet */
269 if (rtmp
->at_rtmp_id_length
!= 8) {
270 dPrintf(D_M_RTMP
, D_L_WARNING
,
271 ("rtmp_update : RTMP ID not as expected Net=%d L=x%x\n",
272 NET_VALUE(rtmp
->at_rtmp_this_net
), rtmp
->at_rtmp_id_length
));
277 * If the port is activating, only take the Network range from the
278 * the RTMP packet received.
279 * Check if there is a conflict with our seed infos.
282 if (ifID
->ifRoutingState
== PORT_ACTIVATING
) {
283 if (PortFlags
& RTR_XNET_PORT
) {
284 if ((PortFlags
& RTR_SEED_PORT
) &&
285 ((CableStart
!= TUPLENET(FirstTuple
)) ||
286 (CableStop
!= TUPLENET(SecondTuple
)))) {
287 ifID
->ifRoutingState
= PORT_ERR_SEED
;
288 ke
.error
= KE_CONF_SEED_RNG
;
289 ke
.port1
= ifID
->ifPort
;
290 strlcpy(ke
.name1
, ifID
->ifName
, sizeof(ke
.name1
));
291 ke
.net
= NET_VALUE(rtmp
->at_rtmp_this_net
);
292 ke
.node
= SenderNodeID
;
293 ke
.netr1b
= TUPLENET(FirstTuple
);
294 ke
.netr1e
= TUPLENET(SecondTuple
);
295 ke
.netr2b
= CableStart
;
296 ke
.netr2e
= CableStop
;
297 RouterError(ifID
->ifPort
, ERTR_SEED_CONFLICT
);
300 CableStart
= TUPLENET(FirstTuple
);
301 CableStop
= TUPLENET(SecondTuple
);
303 dPrintf(D_M_RTMP, D_L_INFO,
304 ("rtmp_update: Port #%d activating, set Cable %d-%d\n",
305 ifID->ifPort, CableStart, CableStop));
308 else { /* non extended cable */
309 if ((PortFlags
& RTR_SEED_PORT
) &&
310 (ifID
->ifThisCableEnd
!= NET_VALUE(rtmp
->at_rtmp_this_net
))) {
311 ke
.error
= KE_CONF_SEED1
;
312 ke
.port1
= ifID
->ifPort
;
313 strlcpy(ke
.name1
, ifID
->ifName
,sizeof(ke
.name1
));
314 ke
.net
= NET_VALUE(rtmp
->at_rtmp_this_net
);
315 ke
.node
= SenderNodeID
;
316 ke
.netr1e
= ifID
->ifThisCableEnd
;
317 ifID
->ifRoutingState
= PORT_ERR_SEED
;
318 RouterError(ifID
->ifPort
, ERTR_SEED_CONFLICT
);
321 CableStop
= NET_VALUE(rtmp
->at_rtmp_this_net
);
323 dPrintf(D_M_RTMP
, D_L_INFO
,
324 ("rtmp_update: Port #%d NONX activating, set Cable %d-%d\n",
325 ifID
->ifPort
, CableStart
, CableStop
));
330 * Perform a few sanity checks on the received RTMP data packet
333 if ((PortFlags
& RTR_XNET_PORT
) && (tuple_nb
>= 2)) {
335 /* The first tuple must be extended */
337 if (! TUPLERANGE(FirstTuple
)) {
338 dPrintf(D_M_RTMP
, D_L_WARNING
,
339 ("rtmp_update: bad range value in 1st tuple =%d\n",
340 TUPLERANGE(FirstTuple
)));
344 if (PortFlags
& RTR_SEED_PORT
)
345 if ((TUPLENET(FirstTuple
) != CableStart
) ||
346 (TUPLENET(SecondTuple
) != CableStop
)) {
347 dPrintf(D_M_RTMP
, D_L_WARNING
, ("rtmp_update: conflict on Seed Port\n"));
348 ifID
->ifRoutingState
= PORT_ERR_CABLER
;
349 ke
.error
= KE_CONF_SEED_NODE
;
350 ke
.port1
= ifID
->ifPort
;
351 strlcpy(ke
.name1
, ifID
->ifName
,sizeof(ke
.name1
));
352 ke
.net
= NET_VALUE(rtmp
->at_rtmp_this_net
);
353 ke
.node
= SenderNodeID
;
354 ke
.netr1b
= TUPLENET(FirstTuple
);
355 ke
.netr1e
= TUPLENET(SecondTuple
);
356 ke
.netr2b
= CableStart
;
357 ke
.netr2e
= CableStop
;
358 RouterError(ifID
->ifPort
, ERTR_CABLE_CONFLICT
);
362 /* check that the tuple matches the range */
364 if ((TUPLENET(SecondTuple
) < TUPLENET(FirstTuple
)) ||
365 (TUPLENET(FirstTuple
) == 0) ||
366 (TUPLENET(FirstTuple
) >= DDP_STARTUP_LOW
) ||
367 (TUPLENET(SecondTuple
) == 0) ||
368 (TUPLENET(SecondTuple
) >= DDP_STARTUP_LOW
)) {
371 * IS THIS NON-FATAL?????
373 dPrintf(D_M_RTMP
, D_L_WARNING
,
374 ("rtmp_update: STARTUP RANGE!!! 1st %d-%d\n",
375 TUPLENET(FirstTuple
), TUPLENET(SecondTuple
)));
376 ifID
->ifRoutingState
= PORT_ERR_STARTUP
;
377 ke
.error
= KE_SEED_STARTUP
;
378 ke
.port1
= ifID
->ifPort
;
379 strlcpy(ke
.name1
, ifID
->ifName
,sizeof(ke
.name1
));
380 ke
.net
= NET_VALUE(rtmp
->at_rtmp_this_net
);
381 ke
.node
= SenderNodeID
;
382 RouterError(ifID
->ifPort
, ERTR_CABLE_STARTUP
);
386 if (TUPLEDIST(FirstTuple
) != 0) {
387 dPrintf(D_M_RTMP
, D_L_WARNING
,
388 ("rtmp_update: Invalid distance in 1st tuple\n"));
392 if (rtmp
->at_rtmp_id
[6] != RTMP_VERSION_NUMBER
) {
393 dPrintf(D_M_RTMP
, D_L_WARNING
,
394 ("rtmp_update: Invalid RTMP version = x%x\n",
395 rtmp
->at_rtmp_id
[6]));
400 else { /* non extended interface or problem in tuple*/
402 if (PortFlags
& RTR_XNET_PORT
) {
403 dPrintf(D_M_RTMP
, D_L_WARNING
,
404 ("rtmp_update: invalid number of tuple for X-net\n"));
408 if (TUPLENET(FirstTuple
) == 0) { /* non extended RTMP data */
410 if (rtmp
->at_rtmp_id
[3] > RTMP_VERSION_NUMBER
) {
411 dPrintf(D_M_RTMP
, D_L_WARNING
,
412 ("rtmp_update: Invalid non extended RTMP version\n"));
418 dPrintf(D_M_RTMP
, D_L_WARNING
,
419 ("rtmp_update: version 1.0 non Xtended net not supported\n"));
420 ifID
->ifRoutingState
= PORT_ERR_BADRTMP
;
421 ke
.error
= KE_BAD_VER
;
422 ke
.rtmp_id
= rtmp
->at_rtmp_id
[6];
423 ke
.net
= NET_VALUE(rtmp
->at_rtmp_this_net
);
424 ke
.node
= SenderNodeID
;
425 RouterError(ifID
->ifPort
, ERTR_RTMP_BAD_VERSION
);
430 NewRoute
.NextIRNet
= NET_VALUE(rtmp
->at_rtmp_this_net
);
431 NewRoute
.NextIRNode
= SenderNodeID
;
432 NewRoute
.NetPort
= ifID
->ifPort
;
435 * Process the case where a non-seed port needs to acquire the right
439 if (!(PortFlags
& RTR_SEED_PORT
) && (ifID
->ifRoutingState
== PORT_ACTIVATING
)) {
440 dPrintf(D_M_RTMP_LOW
, D_L_INFO
,
441 ("rtmp_update: Port# %d, set non seed cable %d-%d\n",
442 ifID
->ifPort
, TUPLENET(FirstTuple
), TUPLENET(SecondTuple
)));
444 if (PortFlags
& RTR_XNET_PORT
) {
445 NewRoute
.NetStart
= TUPLENET(FirstTuple
);
446 NewRoute
.NetStop
= TUPLENET(SecondTuple
);
447 ifID
->ifThisCableStart
= TUPLENET(FirstTuple
);
448 ifID
->ifThisCableEnd
= TUPLENET(SecondTuple
);
453 NewRoute
.NetStart
= 0;
454 NewRoute
.NetStop
= NET_VALUE(rtmp
->at_rtmp_this_net
);
455 ifID
->ifThisCableStart
= NET_VALUE(rtmp
->at_rtmp_this_net
);
456 ifID
->ifThisCableEnd
= NET_VALUE(rtmp
->at_rtmp_this_net
);
459 * Now, check if we already know this route, or we need to add it
460 * (or modify it in the table accordingly)
463 if ((CurrentRoute
= rt_blookup(NewRoute
.NetStop
)) &&
464 (CurrentRoute
->NetStop
== NewRoute
.NetStop
) &&
465 (CurrentRoute
->NetStart
== NewRoute
.NetStart
)) {
466 /*LD 7/31/95 tempo########*/
467 if (NewRoute
.NetPort
!= CurrentRoute
->NetPort
) {
468 dPrintf(D_M_RTMP
, D_L_WARNING
,
469 ("rtmp_update: port# %d, not the port we waited for %d\n",
470 ifID
->ifPort
, CurrentRoute
->NetPort
));
471 /* propose to age the entry we know... */
473 state
= CurrentRoute
->EntryState
& 0x0F;
474 /* if entry has been updated recently, just clear the UPDATED
475 bit. if bit not set, then we can age the entry */
477 if (CurrentRoute
->EntryState
& RTE_STATE_UPDATED
) {
478 CurrentRoute
->EntryState
&= ~RTE_STATE_UPDATED
;
481 state
= state
>> 1 ; /* decrement state */
484 CurrentRoute
->EntryState
= (CurrentRoute
->EntryState
& 0xF0) | state
;
488 else { /* add the new route */
490 dPrintf(D_M_RTMP
, D_L_INFO
,
491 ("rtmp_update: P# %d, 1st tuple route not known, add %d-%d\n",
492 ifID
->ifPort
, NewRoute
.NetStart
, NewRoute
.NetStop
));
494 NewRoute
.EntryState
= RTE_STATE_GOOD
|RTE_STATE_UPDATED
;
495 NewRoute
.NetDist
= 0;
497 if (rt_insert(NewRoute
.NetStop
, NewRoute
.NetStart
, 0,
498 0, NewRoute
.NetDist
, NewRoute
.NetPort
,
499 NewRoute
.EntryState
) == (RT_entry
*)NULL
)
501 ErrorRTMPoverflow
= 1;
506 if (ifID
->ifRoutingState
== PORT_ACTIVATING
) {
507 dPrintf(D_M_RTMP
, D_L_INFO
,
508 ("rtmp_update: port activating, ignoring remaining tuples\n"));
513 * Process all the tuples against our routing table
516 TuplePtr
= (char *)FirstTuple
;
518 while (tuple_nb
-- > 0) {
520 if (TUPLEDIST(TuplePtr
) == NOTIFY_N_DIST
) {
521 dPrintf(D_M_RTMP
, D_L_INFO
,
522 ("rtmp_update: Port# %d, Tuple with Notify Neighbour\n",
524 NewRoute
.NetDist
= NOTIFY_N_DIST
;
525 NewRoute
.EntryState
= RTE_STATE_BAD
;
528 NewRoute
.NetDist
= TUPLEDIST(TuplePtr
) + 1;
529 NewRoute
.EntryState
= RTE_STATE_GOOD
;
530 NewRoute
.EntryState
= RTE_STATE_GOOD
|RTE_STATE_UPDATED
;
534 if (TUPLERANGE(TuplePtr
)) { /* Extended Tuple */
537 NewRoute
.NetStart
= TUPLENET(TuplePtr
);
539 NewRoute
.NetStop
= TUPLENET((TuplePtr
));
543 if ((NewRoute
.NetDist
== 0) ||
544 (NewRoute
.NetStart
== 0) ||
545 (NewRoute
.NetStop
== 0) ||
546 (NewRoute
.NetStop
< NewRoute
.NetStart
) ||
547 (NewRoute
.NetStart
>= DDP_STARTUP_LOW
) ||
548 (NewRoute
.NetStop
>= DDP_STARTUP_LOW
)) {
550 dPrintf(D_M_RTMP
, D_L_WARNING
,
551 ("rtmp_update: P# %d, non valid xtuple received [%d-%d]\n",
552 ifID
->ifPort
, NewRoute
.NetStart
, NewRoute
.NetStop
));
558 else { /* Non Extended Tuple */
560 NewRoute
.NetStart
= 0;
561 NewRoute
.NetStop
= TUPLENET(TuplePtr
);
565 if ((NewRoute
.NetDist
== 0) ||
566 (NewRoute
.NetStop
== 0) ||
567 (NewRoute
.NetStop
>= DDP_STARTUP_LOW
)) {
569 dPrintf(D_M_RTMP
, D_L_WARNING
,
570 ("rtmp_update: P# %d, non valid tuple received [%d]\n",
571 ifID
->ifPort
, NewRoute
.NetStop
));
577 if ((CurrentRoute
= rt_blookup(NewRoute
.NetStop
))) {
578 /* found something... */
580 if (NewRoute
.NetDist
< 16 ||
581 NewRoute
.NetDist
== NOTIFY_N_DIST
) {
584 * Check if the definition of the route changed
587 if (NewRoute
.NetStop
!= CurrentRoute
->NetStop
||
588 NewRoute
.NetStart
!= CurrentRoute
->NetStart
) {
590 if (NewRoute
.NetStop
== CurrentRoute
->NetStop
&&
591 NewRoute
.NetStop
== CurrentRoute
->NetStart
&&
592 NewRoute
.NetStart
== 0)
594 NewRoute
.NetStart
= NewRoute
.NetStop
;
596 else if (NewRoute
.NetStop
== CurrentRoute
->NetStop
&&
597 NewRoute
.NetStart
== NewRoute
.NetStop
&&
598 CurrentRoute
->NetStart
== 0) {
599 dPrintf(D_M_RTMP
, D_L_WARNING
,
600 ("rtmp_update: Range %d-%d has changed to %d-%d Dist=%d\n",
601 CurrentRoute
->NetStart
, CurrentRoute
->NetStop
,
602 NewRoute
.NetStart
, NewRoute
.NetStop
, NewRoute
.NetDist
));
603 NewRoute
.NetStart
= 0;
607 dPrintf(D_M_RTMP
, D_L_WARNING
,
608 ("rtmp_update: Net Conflict Cur=%d, New=%d\n",
609 CurrentRoute
->NetStop
, NewRoute
.NetStop
));
610 CurrentRoute
->EntryState
=
611 (CurrentRoute
->EntryState
& 0xF0) | RTE_STATE_BAD
;
618 * If we don't know the associated zones
621 if (!RT_ALL_ZONES_KNOWN(CurrentRoute
)) {
623 dPrintf(D_M_RTMP_LOW
, D_L_INFO
,
624 ("rtmp_update: Zone unknown for %d-%d state=0x%x\n",
625 CurrentRoute
->NetStart
, CurrentRoute
->NetStop
,
626 CurrentRoute
->EntryState
));
628 /* set the flag in the ifID structure telling
629 * that a scheduling of Zip Query is needed.
632 ifID
->ifZipNeedQueries
= 1;
636 if (((CurrentRoute
->EntryState
& 0x0F) <= RTE_STATE_SUSPECT
) &&
637 NewRoute
.NetDist
!= NOTIFY_N_DIST
) {
639 dPrintf(D_M_RTMP
, D_L_INFO
,
640 ("rtmp_update: update suspect entry %d-%d State=%d\n",
641 NewRoute
.NetStart
, NewRoute
.NetStop
,
642 (CurrentRoute
->EntryState
& 0x0F)));
644 if (NewRoute
.NetDist
<= CurrentRoute
->NetDist
) {
645 CurrentRoute
->NetDist
= NewRoute
.NetDist
;
646 CurrentRoute
->NetPort
= NewRoute
.NetPort
;
647 CurrentRoute
->NextIRNode
= NewRoute
.NextIRNode
;
648 CurrentRoute
->NextIRNet
= NewRoute
.NextIRNet
;
649 CurrentRoute
->EntryState
=
650 (CurrentRoute
->EntryState
& 0xF0) |
651 (RTE_STATE_GOOD
|RTE_STATE_UPDATED
);
657 if (NewRoute
.NetDist
== NOTIFY_N_DIST
) {
659 CurrentRoute
->EntryState
=
660 (CurrentRoute
->EntryState
& 0xF0) | RTE_STATE_SUSPECT
;
661 CurrentRoute
->NetDist
= NOTIFY_N_DIST
;
669 if ((NewRoute
.NetDist
<= CurrentRoute
->NetDist
) && (NewRoute
.NetDist
<16)) {
671 /* Found a shorter or more recent Route,
672 * Replace with the New entryi
675 CurrentRoute
->NetDist
= NewRoute
.NetDist
;
676 CurrentRoute
->NetPort
= NewRoute
.NetPort
;
677 CurrentRoute
->NextIRNode
= NewRoute
.NextIRNode
;
678 CurrentRoute
->NextIRNet
= NewRoute
.NextIRNet
;
679 CurrentRoute
->EntryState
|= RTE_STATE_UPDATED
;
681 /* Can we consider now that the entry is updated? */
682 dPrintf(D_M_RTMP_LOW
, D_L_INFO
,
683 ("rtmp_update: Shorter route found %d-%d, update\n",
684 NewRoute
.NetStart
, NewRoute
.NetStop
));
686 if (ddp_AURPsendx
&& (aurp_ifID
->ifFlags
& AT_IFF_AURP
))
687 ddp_AURPsendx(AURPCODE_RTUPDATE
,
688 (void *)&NewRoute
, AURPEV_NetDistChange
);
691 else { /* no entry found */
693 if (NewRoute
.NetDist
< 16 && NewRoute
.NetDist
!= NOTIFY_N_DIST
&&
694 NewRoute
.NextIRNet
>= ifID
->ifThisCableStart
&&
695 NewRoute
.NextIRNet
<= ifID
->ifThisCableEnd
) {
697 NewRoute
.EntryState
= (RTE_STATE_GOOD
|RTE_STATE_UPDATED
);
699 dPrintf(D_M_RTMP_LOW
, D_L_INFO
,
700 ("rtmp_update: NewRoute %d-%d Tuple #%d\n",
701 NewRoute
.NetStart
, NewRoute
.NetStop
, tuple_nb
));
703 ifID
->ifZipNeedQueries
= 1;
705 if (rt_insert(NewRoute
.NetStop
, NewRoute
.NetStart
, NewRoute
.NextIRNet
,
706 NewRoute
.NextIRNode
, NewRoute
.NetDist
, NewRoute
.NetPort
,
707 NewRoute
.EntryState
) == (RT_entry
*)NULL
)
708 ErrorRTMPoverflow
= 1;
710 else if (ddp_AURPsendx
&& (aurp_ifID
->ifFlags
& AT_IFF_AURP
))
711 ddp_AURPsendx(AURPCODE_RTUPDATE
,
712 (void *)&NewRoute
, AURPEV_NetAdded
);
716 } /* end of main while */
717 ifID
->ifRouterState
= ROUTER_UPDATED
;
718 if (ifID
->ifZipNeedQueries
)
719 zip_send_queries(ifID
, 0, 0xFF);
722 timeout(rtmp_timeout, (caddr_t) ifID, 20*SYS_HZ);
726 /* The RTMP validity timer expired, we need to update the
727 * state of each routing entry in the table
728 * because there is only one validity timer and it is always running,
729 * we can't just age all the entries automatically, as we might be
730 * aging entries that were just updated. So, when an entry is updated,
731 * the RTE_STATE_UPDATED bit is set and when the aging routine is called
732 * it just resets this bit if it is set, only if it is not set will the
733 * route actually be aged.
734 * Note there are 4 states for an entry, the state is decremented until
735 * it reaches the bad state. At this point, the entry is removed
737 * RTE_STATE_GOOD : The entry was valid (will be SUSPECT)
738 * RTE_STATE_SUSPECT: The entry was suspect (can still be used for routing)
739 * RTE_STATE_BAD : The entry was bad and is now deleted
740 * RTE_STATE_UNUSED : Unused or removed entry in the table
743 void rtmp_timeout(ifID
)
744 register at_ifaddr_t
*ifID
;
746 register u_char state
;
747 register unsigned int s
;
749 RT_entry
*en
= &RT_table
[0];
753 if (ifID
->ifRoutingState
< PORT_ONLINE
) {
758 /* for multihoming mode, we use ifRouterState to tell if there
759 is a router out there, so we know when to use cable multicast */
760 if (ifID
->ifRouterState
> NO_ROUTER
)
761 ifID
->ifRouterState
--;
763 ATDISABLE(s
, ddpinp_lock
);
764 for (i
= 0 ; i
< RT_maxentry
; i
++,en
++) {
766 /* we want to age "learned" nets, not directly connected ones */
767 state
= en
->EntryState
& 0x0F;
770 if (state
> RTE_STATE_UNUSED
&&
771 !(en
->EntryState
& RTE_STATE_PERMANENT
) && en
->NetStop
&&
772 en
->NetDist
&& en
->NetPort
== ifID
->ifPort
) {
774 /* if entry has been updated recently, just clear the UPDATED
775 bit. if bit not set, then we can age the entry */
776 if (en
->EntryState
& RTE_STATE_UPDATED
) {
777 en
->EntryState
&= ~RTE_STATE_UPDATED
;
781 state
= state
>> 1 ; /* decrement state */
783 if (state
== RTE_STATE_UNUSED
) {/* was BAD, needs to delete */
784 dPrintf(D_M_RTMP
, D_L_INFO
,
785 ("rtmp_timeout: Bad State for %d-%d (e#%d): remove\n",
786 en
->NetStart
, en
->NetStop
, i
));
788 if (ddp_AURPsendx
&& (aurp_ifID
->ifFlags
& AT_IFF_AURP
))
789 ddp_AURPsendx(AURPCODE_RTUPDATE
,
790 (void *)en
, AURPEV_NetDeleted
);
792 /* then clear the bit in the table concerning this entry.
793 If the zone Count reaches zero, remove the entry */
795 zt_remove_zones(en
->ZoneBitMap
);
797 RT_DELETE(en
->NetStop
, en
->NetStart
);
800 en
->EntryState
= (en
->EntryState
& 0xF0) | state
;
801 dPrintf(D_M_RTMP
, D_L_INFO
, ("Change State for %d-%d to %d (e#%d)\n",
802 en
->NetStart
, en
->NetStop
, state
, i
));
806 ATENABLE(s
, ddpinp_lock
);
807 timeout(rtmp_timeout
, (caddr_t
) ifID
, 20*SYS_HZ
);
813 * rtmp_prep_new_packet: allocate a ddp packet for RTMP use (reply to a RTMP request or
814 * Route Data Request, or generation of RTMP data packets.
815 * The ddp header is filled with relevant information, as well as
816 * the beginning of the rtmp packet with the following info:
817 * Router's net number (2bytes)
818 * ID Length = 8 (1byte)
819 * Router's node ID (1byte)
820 * Extended Range Start (2bytes)
821 * Range + dist (0x80) (1byte)
822 * Extended Range End (2bytes)
823 * Rtmp version (0x82) (1byte)
827 gbuf_t
*rtmp_prep_new_packet (ifID
, DstNet
, DstNode
, socket
)
828 register at_ifaddr_t
*ifID
;
829 register at_net DstNet
;
830 register u_char DstNode
;
831 register char socket
;
835 register at_ddp_t
*ddp
;
836 register char * rtmp_data
;
838 if ((m
= gbuf_alloc(AT_WR_OFFSET
+1024, PRI_HI
)) == NULL
) {
839 dPrintf(D_M_RTMP
, D_L_WARNING
, ("rtmp_new_packet: Can't allocate mblock\n"));
840 return ((gbuf_t
*)NULL
);
843 gbuf_rinc(m
,AT_WR_OFFSET
);
844 gbuf_wset(m
,DDP_X_HDR_SIZE
+ 10);
845 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
848 * Prepare the DDP header of the new packet
852 ddp
->unused
= ddp
->hopcount
= 0;
854 UAS_ASSIGN(ddp
->checksum
, 0);
856 NET_NET(ddp
->dst_net
, DstNet
);
857 ddp
->dst_node
= DstNode
;
858 ddp
->dst_socket
= socket
;
860 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
861 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
862 ddp
->src_socket
= RTMP_SOCKET
;
863 ddp
->type
= DDP_RTMP
;
866 * Prepare the RTMP header (Router Net, ID, Node and Net Tuple
867 * (this works only if we are on an extended net)
870 rtmp_data
= ddp
->data
;
872 *rtmp_data
++ = (ifID
->ifThisNode
.s_net
& 0xff00) >> 8;
873 *rtmp_data
++ = ifID
->ifThisNode
.s_net
& 0x00ff ;
875 *rtmp_data
++ = (u_char
)ifID
->ifThisNode
.s_node
;
876 *rtmp_data
++ = (CableStart
& 0xff00) >> 8;
877 *rtmp_data
++ = CableStart
& 0x00ff ;
878 *rtmp_data
++ = 0x80; /* first tuple, so distance is always zero */
879 *rtmp_data
++ = (CableStop
& 0xff00) >> 8;
880 *rtmp_data
++ = CableStop
& 0x00ff ;
881 *rtmp_data
++ = RTMP_VERSION_NUMBER
;
887 int rtmp_r_find_bridge(ifID
, orig_ddp
)
888 register at_ifaddr_t
*ifID
;
889 register at_ddp_t
*orig_ddp
;
893 register int size
, status
;
894 register at_ddp_t
*ddp
;
895 register char * rtmp_data
;
899 /* find the bridge for the querried net */
901 Entry
= rt_blookup(NET_VALUE(orig_ddp
->dst_net
));
904 dPrintf(D_M_RTMP
, D_L_WARNING
, ("rtmp_r_find_bridge: no info for net %d\n",
905 NET_VALUE(orig_ddp
->dst_net
)));
910 size
= DDP_X_HDR_SIZE
+ 10 ;
911 if ((m
= gbuf_alloc(AT_WR_OFFSET
+size
, PRI_HI
)) == NULL
) {
912 dPrintf(D_M_RTMP
, D_L_WARNING
,
913 ("rtmp_r_find_bridge: Can't allocate mblock\n"));
917 gbuf_rinc(m
,AT_WR_OFFSET
);
919 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
922 * Prepare the DDP header of the new packet
925 ddp
->unused
= ddp
->hopcount
= 0;
927 DDPLEN_ASSIGN(ddp
, size
);
928 UAS_ASSIGN(ddp
->checksum
, 0);
930 NET_NET(ddp
->dst_net
, orig_ddp
->src_net
);
931 ddp
->dst_node
= orig_ddp
->src_node
;
932 ddp
->dst_socket
= orig_ddp
->src_socket
;
934 NET_ASSIGN(ddp
->src_net
, Entry
->NextIRNet
);
935 ddp
->src_node
= Entry
->NextIRNode
;
936 ddp
->src_socket
= RTMP_SOCKET
;
937 ddp
->type
= DDP_RTMP
;
940 * Prepare the RTMP header (Router Net, ID, Node and Net Tuple
941 * (this works only if we are on an extended net)
944 rtmp_data
= ddp
->data
;
946 *rtmp_data
++ = (Entry
->NextIRNet
& 0xff00) >> 8;
947 *rtmp_data
++ = Entry
->NextIRNet
& 0x00ff ;
949 *rtmp_data
++ = (u_char
)Entry
->NextIRNode
;
950 *rtmp_data
++ = (Entry
->NetStart
& 0xff00) >> 8;
951 *rtmp_data
++ = Entry
->NetStart
& 0x00ff ;
952 *rtmp_data
++ = 0x80; /* first tuple, so distance is always zero */
953 *rtmp_data
++ = (Entry
->NetStop
& 0xff00) >> 8;
954 *rtmp_data
++ = Entry
->NetStop
& 0x00ff ;
955 *rtmp_data
++ = RTMP_VERSION_NUMBER
;
958 dPrintf(D_M_RTMP
, D_L_INFO
, ("rtmp_r_find_bridge: for net %d send back router %d.%d\n",
959 NET_VALUE(orig_ddp
->dst_net
), Entry
->NextIRNet
, Entry
->NextIRNode
));
960 if (status
= ddp_router_output(m
, ifID
, AT_ADDR
, NET_VALUE(orig_ddp
->src_net
),
961 orig_ddp
->src_node
, 0)){
962 dPrintf(D_M_RTMP
, D_L_WARNING
,
963 ("rtmp_r_find_bridge: ddp_router_output failed status=%d\n", status
));
971 * Send the routing table entries in RTMP data packets.
972 * Use split horizon if specified. The Data packets are sent
973 * as full DDP packets, if the last packet is full an empty
974 * packet is sent to tell the recipients that this is the end of
978 static int rtmp_send_table(ifID
, DestNet
, DestNode
, split_hz
, socket
,
980 register at_ifaddr_t
*ifID
; /* interface/port params */
981 register at_net DestNet
; /* net where to send the table */
982 register u_char DestNode
; /* node where to send to table */
983 short split_hz
; /* use split horizon */
984 char socket
; /* the destination socket to send to */
985 short n_neighbors
; /* used to send packets telling we are going down */
993 register at_ddp_t
*ddp
;
994 register short EntNb
= 0, sent_tuple
= 0;
995 register unsigned int s
;
997 if (ifID
->ifRoutingState
< PORT_ONLINE
) {
998 dPrintf(D_M_RTMP
, D_L_INFO
,
999 ("rtmp_send_table: port %d activating, we don't send anything!\n",
1004 /* prerare tuples and packets for DDP*/
1005 /* if split horizon, do not send tuples we can reach on the port we
1009 Entry
= &RT_table
[0];
1011 if (!(m
= rtmp_prep_new_packet(ifID
, DestNet
, DestNode
, socket
))) {
1012 dPrintf(D_M_RTMP
, D_L_WARNING
,
1013 ("rtmp_send_table: rtmp_prep_new_packet failed\n"));
1017 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
1018 Buff_ptr
= (char *)((char *)ddp
+ DDP_X_HDR_SIZE
+ 10);
1020 ATDISABLE(s
, ddpinp_lock
);
1021 while (EntNb
< RT_maxentry
) {
1023 if (Entry
->NetStop
&& ((Entry
->EntryState
& 0x0F) >= RTE_STATE_SUSPECT
)) {
1024 if (!(split_hz
&& ifID
->ifPort
== Entry
->NetPort
)) {
1027 if (((Entry
->EntryState
& 0x0F) < RTE_STATE_SUSPECT
) || n_neighbors
)
1028 NewDist
= NOTIFY_N_DIST
;
1030 NewDist
= Entry
->NetDist
& 0x1F;
1032 if (Entry
->NetStart
) { /* Extended */
1033 *Buff_ptr
++ = (Entry
->NetStart
& 0xFF00) >> 8;
1034 *Buff_ptr
++ = (Entry
->NetStart
& 0x00FF);
1035 *Buff_ptr
++ = 0x80 | NewDist
;
1036 *Buff_ptr
++ = (Entry
->NetStop
& 0xFF00) >> 8;
1037 *Buff_ptr
++ = (Entry
->NetStop
& 0x00FF);
1038 *Buff_ptr
++ = RTMP_VERSION_NUMBER
;
1041 else { /* non extended tuple */
1042 *Buff_ptr
++ = (Entry
->NetStop
& 0xFF00) >> 8;
1043 *Buff_ptr
++ = (Entry
->NetStop
& 0x00FF);
1044 *Buff_ptr
++ = NewDist
;
1050 if (size
> (DDP_DATA_SIZE
-20)) {
1051 DDPLEN_ASSIGN(ddp
, size
+ DDP_X_HDR_SIZE
+ 10);
1053 ATENABLE(s
, ddpinp_lock
);
1054 if (status
= ddp_router_output(m
, ifID
, AT_ADDR
,
1055 NET_VALUE(DestNet
),DestNode
, 0)){
1056 dPrintf(D_M_RTMP
, D_L_WARNING
,
1057 ("rtmp_send_table: ddp_router_output failed status=%d\n",
1061 if ((m
= rtmp_prep_new_packet (ifID
, DestNet
, DestNode
, socket
)) == NULL
){
1062 dPrintf(D_M_RTMP
, D_L_WARNING
,
1063 ("rtmp_send_table: rtmp_prep_new_poacket failed status=%d\n",
1067 ddp
= (at_ddp_t
*)(gbuf_rptr(m
));
1068 Buff_ptr
= (char *)((char *)ddp
+ DDP_X_HDR_SIZE
+ 10);
1070 dPrintf(D_M_RTMP_LOW
, D_L_OUTPUT
,
1071 ("rtmp_s_tble: Send %d tuples on port %d\n",
1072 sent_tuple
, ifID
->ifPort
));
1075 ATDISABLE(s
, ddpinp_lock
);
1081 ATENABLE(s
, ddpinp_lock
);
1084 * If we have some remaining entries to send, send them now.
1085 * otherwise, the last packet we sent was full, we need to send an empty one
1088 DDPLEN_ASSIGN(ddp
, size
+ DDP_X_HDR_SIZE
+ 10);
1091 ddp_router_output(m
, ifID
, AT_ADDR
, NET_VALUE(DestNet
),DestNode
, 0))){
1092 dPrintf(D_M_RTMP
, D_L_WARNING
,
1093 ("rtmp_send_table: ddp_router_output failed status=%d\n", status
));
1096 dPrintf(D_M_RTMP_LOW
, D_L_OUTPUT
,
1097 ("rtmp_s_tble: LAST Packet split=%d with %d tuples sent on port %d\n",
1098 split_hz
, sent_tuple
, ifID
->ifPort
));
1104 * rtmp_request: respond to the 3 types of RTMP requests RTMP may receive
1105 * RTMP func =1 : respond with an RTMP Reponse Packet
1106 * RTMP func =2 : respond with the routing table RTMP packet with split horizon
1107 * RTMP func =3 : respond with the routing table RTMP packet no split horizon
1109 * see Inside AppleTalk around page 5-18 for "details"
1112 static void rtmp_request(ifID
, ddp
)
1113 register at_ifaddr_t
*ifID
;
1114 register at_ddp_t
*ddp
;
1117 short split_horizon
= FALSE
;
1121 /* We ignore the request if we're activating on that port */
1123 if (ifID
->ifRoutingState
< PORT_ONLINE
)
1126 /* check RTMP function code */
1128 code
= ddp
->data
[0];
1132 case RTMP_REQ_FUNC1
: /* RTMP Find Bridge */
1134 /* RTMP Request Packet: we send a response with the next IRrange */
1135 dPrintf(D_M_RTMP
, D_L_INPUT
,
1136 ( "rtmp_request: find bridge for net %d port %d node %d.%d\n",
1137 NET_VALUE(ddp
->dst_net
), ifID
->ifPort
,
1138 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
1140 if ((error
= rtmp_r_find_bridge (ifID
, ddp
))) {
1141 dPrintf(D_M_RTMP
, D_L_WARNING
,
1142 ("rtmp_request: Code 1 ddp_r_output failed error=%d\n",
1149 case RTMP_REQ_FUNC2
:
1151 split_horizon
= TRUE
;
1153 case RTMP_REQ_FUNC3
:
1155 /* RTMP Route Request Packet */
1157 dPrintf(D_M_RTMP
, D_L_INPUT
,
1158 ("rtmp_request: received code=%d from %d.%d for %d.%d\n",
1159 code
, NET_VALUE(ddp
->src_net
), ddp
->src_node
,
1160 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
));
1162 rtmp_send_table(ifID
, ddp
->src_net
, ddp
->src_node
,
1163 split_horizon
, ddp
->src_socket
, 0);
1169 /* unknown type of request */
1170 dPrintf(D_M_RTMP
, D_L_WARNING
,
1171 ("rtmp_request : invalid type of request =%d\n",
1178 /* locked version of rtmp_send_port */
1179 void rtmp_send_port_locked(ifID
)
1180 register at_ifaddr_t
*ifID
;
1183 rtmp_send_port(ifID
);
1189 * rtmp_send_all_ports : send the routing table on all connected ports
1190 * check for the port status and if ok, send the
1191 * rtmp tuples to the broadcast address for the port
1192 * usually called on timeout every 10 seconds.
1195 void rtmp_send_port(ifID
)
1196 register at_ifaddr_t
*ifID
;
1200 NET_ASSIGN(DestNet
, 0);
1202 if (ifID
&& ifID
->ifRoutingState
== PORT_ONLINE
) {
1203 dPrintf(D_M_RTMP_LOW
, D_L_OUTPUT
,
1204 ("rtmp_send_port: do stuff for port=%d\n",
1206 if (ifID
->ifZipNeedQueries
)
1207 zip_send_queries(ifID
, 0, 0xFF);
1208 if (!ROUTING_MODE
) {
1211 rtmp_send_table(ifID
, DestNet
, 0xFF, 1, RTMP_SOCKET
, 0);
1214 if (ifID
== ifID_home
)
1215 dPrintf(D_M_RTMP_LOW
, D_L_VERBOSE
,
1216 ("I:%5d O:%5d H:%5d dropped:%d\n",
1217 pktsIn
, pktsOut
, pktsHome
, pktsDropped
));
1219 dPrintf(D_M_RTMP_LOW
, D_L_TRACE
,
1220 ("rtmp_send_port: func=0x%x, ifID=0x%x\n",
1221 (u_int
) rtmp_send_port
, (u_int
) ifID
));
1222 timeout (rtmp_send_port_locked
, (caddr_t
)ifID
, 10 * SYS_HZ
);
1226 /* rtmp_dropper: check the number of packet received every x secondes.
1227 * the actual packet dropping is done in ddp_input
1230 void rtmp_dropper(void *arg
)
1235 pktsIn
= pktsOut
= pktsHome
= pktsDropped
= 0;
1236 timeout(rtmp_dropper
, NULL
, 2*SYS_HZ
);
1242 * rtmp_router_start: perform the sanity checks before declaring the router up
1243 * and running. This function looks for discrepency between the net infos
1244 * for the different ports and seed problems.
1245 * If everything is fine, the state of each port is brought to PORT_ONLINE.\
1246 * ### LD 01/09/95 Changed to correct Zone problem on non seed ports.
1249 int rtmp_router_start(keP
)
1250 at_kern_err_t
*keP
; /* used to report errors (if any) */
1253 register at_ifaddr_t
*ifID
, *ifID2
;
1254 register short Index
, router_starting_timer
= 0;
1255 register RT_entry
*Entry
;
1256 register at_net_al netStart
, netStop
;
1260 /* clear the static structure used to record routing errors */
1261 bzero(&ke
, sizeof(ke
));
1263 TAILQ_FOREACH(ifID
, &at_ifQueueHd
, aa_link
) {
1265 /* if non seed, need to acquire the right node address */
1267 if ((ifID
->ifFlags
& RTR_SEED_PORT
) == 0) {
1268 if ((ifID
->ifThisCableStart
== 0 && ifID
->ifThisCableEnd
== 0) ||
1269 (ifID
->ifThisCableStart
>= DDP_STARTUP_LOW
&&
1270 ifID
->ifThisCableEnd
<= DDP_STARTUP_HIGH
)) {
1272 if (ifID
->ifThisCableEnd
== 0) {
1273 keP
->error
= KE_NO_SEED
;
1274 keP
->port1
= ifID
->ifPort
;
1275 strlcpy(keP
->name1
, ifID
->ifName
,sizeof(keP
->name1
));
1278 keP
->error
= KE_INVAL_RANGE
;
1279 keP
->port1
= ifID
->ifPort
;
1280 strlcpy(keP
->name1
, ifID
->ifName
,sizeof(keP
->name1
));
1281 keP
->netr1b
= ifID
->ifThisCableStart
;
1282 keP
->netr1e
= ifID
->ifThisCableEnd
;
1284 ifID
->ifRoutingState
= PORT_ERR_STARTUP
;
1285 RouterError(ifID
->ifPort
, ERTR_CABLE_STARTUP
);
1290 /* we are non seed, so try to acquire the zones for that guy */
1291 ifID
->ifZipNeedQueries
= 1;
1293 dPrintf(D_M_RTMP
, D_L_STARTUP
,
1294 ("rtmp_router_start: call elap_online for Non Seed port #%d cable =%d-%d\n",
1295 ifID
->ifPort
, CableStart
, CableStop
));
1296 if ((err
= elap_online3(ifID
)))
1301 /* Check if we have a problem with the routing table size */
1303 if (ErrorRTMPoverflow
) {
1304 keP
->error
= KE_RTMP_OVERFLOW
;
1309 /* Now, check that we don't have a conflict in between our interfaces */
1310 TAILQ_FOREACH(ifID
, &at_ifQueueHd
, aa_link
) {
1312 /* check if the RoutingState != PORT_ONERROR */
1313 if (ifID
->ifRoutingState
< PORT_ACTIVATING
) {
1317 if ((ifID
->ifThisCableStart
== 0 && ifID
->ifThisCableEnd
== 0) ||
1318 (ifID
->ifThisCableStart
>= DDP_STARTUP_LOW
&&
1319 ifID
->ifThisCableEnd
<= DDP_STARTUP_HIGH
)) {
1321 if (ifID
->ifThisCableEnd
== 0) {
1322 keP
->error
= KE_NO_SEED
;
1323 keP
->port1
= ifID
->ifPort
;
1324 strlcpy(keP
->name1
, ifID
->ifName
,sizeof(keP
->name1
));
1327 keP
->error
= KE_INVAL_RANGE
;
1328 keP
->port1
= ifID
->ifPort
;
1329 strlcpy(keP
->name1
, ifID
->ifName
,sizeof(keP
->name1
));
1330 keP
->netr1b
= ifID
->ifThisCableStart
;
1331 keP
->netr1e
= ifID
->ifThisCableEnd
;
1334 ifID
->ifRoutingState
= PORT_ERR_STARTUP
;
1335 RouterError(ifID
->ifPort
, ERTR_CABLE_STARTUP
);
1340 /* check the interface address against all other ifs */
1342 netStart
= ifID
->ifThisCableStart
;
1343 netStop
= ifID
->ifThisCableEnd
;
1345 for (ifID2
= TAILQ_NEXT(ifID
, aa_link
); ifID2
;
1346 ifID2
= TAILQ_NEXT(ifID2
, aa_link
)) {
1348 if (((netStart
>= ifID2
->ifThisCableStart
) &&
1349 (netStart
<= ifID2
->ifThisCableEnd
)) ||
1350 ((netStop
>= ifID2
->ifThisCableStart
) &&
1351 (netStop
<= ifID2
->ifThisCableEnd
)) ||
1352 ((ifID2
->ifThisCableStart
>= netStart
) &&
1353 (ifID2
->ifThisCableStart
<= netStop
)) ||
1354 ((ifID2
->ifThisCableEnd
>= netStart
) &&
1355 (ifID2
->ifThisCableEnd
<= netStop
)) ) {
1357 keP
->error
= KE_CONF_RANGE
;
1358 keP
->port1
= ifID
->ifPort
;
1359 strlcpy(keP
->name1
, ifID
->ifName
,sizeof(keP
->name1
));
1360 keP
->port2
= ifID2
->ifPort
;
1361 strlcpy(keP
->name2
, ifID2
->ifName
,sizeof(keP
->name2
));
1362 keP
->netr1b
= ifID
->ifThisCableStart
;
1363 keP
->netr1e
= ifID
->ifThisCableEnd
;
1364 ifID
->ifRoutingState
= PORT_ERR_CABLER
;
1365 RouterError(ifID
->ifPort
, ERTR_CABLE_CONFLICT
);
1371 /* ### LD 01/04/94: We need to fill in the next IR info in the routing table */
1372 Entry
= rt_blookup(ifID
->ifThisCableEnd
);
1374 if (Entry
== NULL
) {
1375 dPrintf(D_M_RTMP
, D_L_ERROR
,
1376 ("rtmp_router_start: we don't know our cable range port=%d\n",
1383 * Note: At this point, non seed ports may not be aware of their Default zone
1386 if (!(ifID
->ifFlags
& RTR_SEED_PORT
)) {
1387 ifID
->ifDefZone
= 0;
1388 Entry
->EntryState
|= (RTE_STATE_GOOD
|RTE_STATE_UPDATED
);
1391 ifID
->ifRoutingState
= PORT_ONLINE
;
1392 ifID
->ifState
= LAP_ONLINE
;
1394 /* set the right net and node for each port */
1395 Entry
->NextIRNet
= ifID
->ifThisNode
.s_net
;
1396 Entry
->NextIRNode
= ifID
->ifThisNode
.s_node
;
1398 dPrintf(D_M_RTMP
, D_L_STARTUP
,
1399 ("rtmp_router_start: bring port=%d [%d.%d]... on line\n",
1400 ifID
->ifPort
, ifID
->ifThisNode
.s_net
,
1401 ifID
->ifThisNode
.s_node
));
1406 * Everything is fine, we can begin to babble on the net...
1409 TAILQ_FOREACH(ifID
, &at_ifQueueHd
, aa_link
) {
1410 if (ifID
->ifRoutingState
== PORT_ONLINE
) {
1411 rtmp_send_port(ifID
);
1412 timeout(rtmp_timeout
, (caddr_t
)ifID
, (50+ifID
->ifPort
) * SYS_HZ
);
1413 if (ifID
->ifRoutingState
< PORT_ACTIVATING
) {
1419 /* Check if we have a problem with the routing or zip table size */
1421 if (ErrorRTMPoverflow
) {
1422 keP
->error
= KE_RTMP_OVERFLOW
;
1425 if (ErrorZIPoverflow
) {
1426 keP
->error
= KE_ZIP_OVERFLOW
;
1430 /* sleep for 11 seconds */
1434 /* *** eventually this will be the ifID for the interface
1435 being brought up in router mode *** */
1436 /* *** router sends rtmp packets every 10 seconds *** */
1437 msleep(&ifID_home
->startup_inprogress
, atalk_mutex
,
1438 PSOCK
| PCATCH
, "router_start1", &ts
))
1443 /* Is the stack still up ? */
1444 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
1451 TAILQ_FOREACH(ifID
, &at_ifQueueHd
, aa_link
) {
1453 if (ifID
->ifRoutingState
< PORT_ACTIVATING
) {
1457 if ((ifID
->ifZipNeedQueries
)
1458 && (ifID
->ifFlags
& RTR_SEED_PORT
) == 0) {
1459 dPrintf(D_M_RTMP
, D_L_STARTUP
,
1460 ("rtmp_router_start: send Zip Queries for Port %d\n",
1462 zip_send_queries(ifID
, 0, 0xFF);
1464 if (router_starting_timer
>= 10) {
1465 dPrintf(D_M_RTMP
, D_L_WARNING
,
1466 ("rtmp_router_start: no received response to ZipNeedQueries\n"));
1467 keP
->error
= KE_NO_ZONES_FOUND
;
1468 keP
->port1
= ifID
->ifPort
;
1469 strlcpy(keP
->name1
, ifID
->ifName
,sizeof(keP
->name1
));
1470 keP
->netr1b
= ifID
->ifThisCableStart
;
1471 keP
->netr1e
= ifID
->ifThisCableEnd
;
1472 ifID
->ifRoutingState
= PORT_ERR_CABLER
;
1473 RouterError(ifID
->ifPort
, ERTR_CABLE_CONFLICT
);
1477 dPrintf(D_M_RTMP
, D_L_STARTUP
,
1478 ("rtmp_router_start: waiting for zone info to complete\n"));
1479 /* sleep for 10 seconds */
1483 /* *** eventually this will be the ifID for the
1484 interface being brought up in router mode *** */
1485 msleep(&ifID_home
->startup_inprogress
, atalk_mutex
,
1486 PSOCK
| PCATCH
, "router_start2", &ts
))
1491 /* Is the stack still up ? */
1492 if (!(at_state
.flags
& AT_ST_STARTED
) || !ifID_home
) {
1498 router_starting_timer
++;
1504 /* At This Point, check if we know the default zones for non seed port */
1506 TAILQ_FOREACH(ifID
, &at_ifQueueHd
, aa_link
) {
1508 if (ifID
->ifRoutingState
< PORT_ACTIVATING
)
1511 if (!(ifID
->ifFlags
& RTR_SEED_PORT
)) {
1512 Entry
= rt_blookup(ifID
->ifThisCableEnd
);
1514 if (Entry
== NULL
) {
1515 dPrintf(D_M_RTMP
, D_L_ERROR
,
1516 ("rtmp_router_start: (2)we don't know our cable range port=%d\n",
1521 dPrintf(D_M_RTMP
, D_L_STARTUP
,
1522 ("rtmp_router_start: if %s set to permanent\n",
1524 Entry
->NetDist
= 0; /* added 4-29-96 jjs, prevent direct
1525 nets from showing non-zero
1527 /* upgrade the non seed ports. */
1528 Entry
->EntryState
|= RTE_STATE_PERMANENT
;
1530 Index
= zt_ent_zindex(Entry
->ZoneBitMap
);
1532 dPrintf(D_M_RTMP
, D_L_ERROR
,
1533 ("rtmp_router_start: still don't know default zone for port %d\n",
1536 ifID
->ifDefZone
= Index
;
1537 if ((ifID
== ifID_home
) || MULTIHOME_MODE
) {
1538 ifID
->ifZoneName
= ZT_table
[Index
-1].Zone
;
1539 (void)regDefaultZone(ifID
);
1541 /* Send zone change event */
1542 atalk_post_msg(ifID
->aa_ifp
, KEV_ATALK_ZONEUPDATED
, 0, &(ifID
->ifZoneName
));
1548 /* Check if we have a problem with the routing or zip table size */
1550 if (ErrorRTMPoverflow
) {
1551 keP
->error
= KE_RTMP_OVERFLOW
;
1554 if (ErrorZIPoverflow
) {
1555 keP
->error
= KE_ZIP_OVERFLOW
;
1560 * Handle the Home Port specifics
1563 /* set the router address as being us no matter what*/
1564 ifID_home
->ifARouter
= ifID_home
->ifThisNode
;
1565 ifID_home
->ifRouterState
= ROUTER_UPDATED
;
1567 /* prepare the packet dropper timer */
1568 timeout (rtmp_dropper
, NULL
, 1*SYS_HZ
);
1573 dPrintf(D_M_RTMP
,D_L_ERROR
,
1574 ("rtmp_router_start: error type=%d occurred on port %d\n",
1575 ifID
->ifRoutingState
, ifID
->ifPort
));
1577 /* if there's no keP->error, copy the local ke structure,
1578 since the error occurred asyncronously */
1579 if ((!keP
->error
) && ke
.error
)
1580 bcopy(&ke
, keP
, sizeof(ke
));
1583 /* to return the error in keP, the ioctl has to return 0 */
1585 return((keP
->error
)? 0: err
);
1586 } /* rtmp_router_start */
1589 void rtmp_shutdown()
1591 register at_ifaddr_t
*ifID
;
1595 NET_ASSIGN(DestNet
, 0);
1597 dPrintf(D_M_RTMP
, D_L_SHUTDN
,
1598 ("rtmp_shutdown:stop sending to all ports\n"));
1600 untimeout(rtmp_dropper
, (caddr_t
)0);
1601 untimeout(rtmp_router_start
, 1); /* added for 2225395 */
1602 untimeout(rtmp_router_start
, 3); /* added for 2225395 */
1604 TAILQ_FOREACH(ifID
, &at_ifQueueHd
, aa_link
) {
1605 if (ifID
->ifRoutingState
> PORT_OFFLINE
) {
1606 if (ifID
->ifRoutingState
== PORT_ONLINE
) {
1607 untimeout(rtmp_send_port_locked
, (caddr_t
)ifID
);
1608 untimeout(rtmp_timeout
, (caddr_t
) ifID
);
1611 * it's better to notify the neighbour routers that we are going down
1614 rtmp_send_table(ifID
, DestNet
, 0xFF, TRUE
,
1617 ifID
->ifRoutingState
= PORT_OFFLINE
;
1619 dPrintf(D_M_RTMP
, D_L_SHUTDN
,
1620 ("rtmp_shutdown: routing on port=%d... off line\nStats:\n",
1622 dPrintf(D_M_RTMP
, D_L_SHUTDN
,
1623 ("fwdBytes : %ld\nfwdPackets : %ld\ndroppedBytes : %ld\ndroppedPkts : %ld\n",
1624 ifID
->ifStatistics
.fwdBytes
, ifID
->ifStatistics
.fwdPkts
,
1625 ifID
->ifStatistics
.droppedBytes
, ifID
->ifStatistics
.droppedPkts
));
1633 * Remove all entries associated with the specified port.
1635 void rtmp_purge(ifID
)
1640 RT_entry
*en
= &RT_table
[0];
1642 ATDISABLE(s
, ddpinp_lock
);
1643 for (i
=0; i
< RT_maxentry
; i
++) {
1644 state
= en
->EntryState
& 0x0F;
1645 if ((state
> RTE_STATE_UNUSED
) && (state
!= RTE_STATE_PERMANENT
)
1646 && en
->NetStop
&& en
->NetDist
&& (en
->NetPort
== ifID
->ifPort
)) {
1647 zt_remove_zones(en
->ZoneBitMap
);
1648 RT_DELETE(en
->NetStop
, en
->NetStart
);
1652 ATENABLE(s
, ddpinp_lock
);