]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/ddp_rtmptable.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /*----------------------------------------------------------------------------
24 * RTMP & ZIP routing tables access routines
26 * This code implement b-tree search and manipulation of
27 * of the RTMP routing table and ZIP zone table.
29 * The RTMP routing table is a data block divided in several routing
30 * entries sorted during insertion in a b-tree form. We use a table and
31 * not dynamically allocated entries because it allow us to scan the whole
32 * table when RTMP packets are generated. The routing table entries are sorted
33 * by there NetStop value (because non extended nets have a NetStart value of
34 * zero. From any point in the tree, the left side contains Network ranges
35 * smaller or equal to the current Node, and the right tree points to higher
36 * values network ranges.
39 * 0.01 3/16/94 LD Creation
40 * Modified for MP, 1996 by Tuyen Nguyen
41 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
43 *----------------------------------------------------------------------------
45 * Copyright (c) 1994, 1996, 1997, 1998 Apple Computer, Inc.
48 #include <sys/errno.h>
49 #include <sys/types.h>
50 #include <sys/param.h>
51 #include <machine/spl.h>
52 #include <sys/systm.h>
53 #include <sys/kernel.h>
55 #include <sys/filedesc.h>
56 #include <sys/fcntl.h>
58 #include <sys/ioctl.h>
59 #include <sys/malloc.h>
60 #include <sys/socket.h>
61 #include <sys/socketvar.h>
64 #include <net/if_types.h>
66 #include <netat/sysglue.h>
67 #include <netat/appletalk.h>
68 #include <netat/at_var.h>
69 #include <netat/ddp.h>
70 #include <netat/rtmp.h>
71 #include <netat/at_pcb.h>
72 #include <netat/zip.h>
73 #include <netat/routing_tables.h>
74 #include <netat/at_snmp.h>
75 #include <netat/debug.h>
77 RT_entry
*RT_table_freelist
; /* start of free entry list */
78 RT_entry RT_table_start
; /* start of the actual entry table */
79 RT_entry
*RT_table
; /* the routing table */
80 ZT_entry
*ZT_table
; /* the Zone Information Protocol table */
81 short RT_maxentry
; /* Number of entry in RTMP table */
82 short ZT_maxentry
; /* Number of entry in ZIP table */
84 char errstr
[512]; /* used to display meaningfull router errors*/
86 extern at_ifaddr_t
*ifID_table
[];
87 extern at_ifaddr_t
*ifID_home
;
88 extern snmpStats_t snmpStats
;
89 extern atlock_t ddpinp_lock
;
91 short ErrorRTMPoverflow
= 0; /* flag if RTMP table is too small for this net */
92 short ErrorZIPoverflow
= 0; /* flag if ZIP table is too small for this net */
95 void getIfUsage( int, at_ifnames_t
*);
98 * This a temporary function : just to display the router error
101 void RouterError(port
, err_number
)
102 short port
, err_number
;
105 switch (err_number
) {
107 case ERTR_SEED_CONFLICT
:
108 dPrintf(D_M_RTMP
, D_L_ERROR
,
109 ("**** RTR Error on port# %d SEED_CONFLICT\n", port
));
112 case ERTR_CABLE_CONFLICT
:
113 dPrintf(D_M_RTMP
, D_L_ERROR
,
114 ("**** RTR Error on port# %d CABLE_CONFLICT\n", port
));
117 case ERTR_RTMP_BAD_VERSION
:
118 dPrintf(D_M_RTMP
, D_L_ERROR
,
119 ("**** RTR Error on port# %d RTMP_BAD_VERSION\n", port
));
122 case ERTR_CABLE_STARTUP
:
123 dPrintf(D_M_RTMP
, D_L_ERROR
,
124 ("**** RTR Error on port# %d RTMP_CABLE_STARTUP\n",
129 dPrintf(D_M_RTMP
, D_L_ERROR
,
130 ("**** RTR Error on port# %d WHAT IN THE WORLD IS THIS ONE? code=%d\n",
134 dPrintf(D_M_RTMP
, D_L_ERROR
, ("Explanation: %s\n", errstr
));
139 * this function just look for a NetNumber in the routing table,
140 * no check is done for the validity of the entry
143 RT_entry
*rt_blookup (NetNumber
)
147 RT_entry
*ptree
= &RT_table_start
;
149 register unsigned int s
;
151 dPrintf(D_M_RTMP_LOW, D_L_ROUTING, ("%s : Lookup for Net=%d\n",
152 "rt_blookup", NetNumber));
154 ATDISABLE(s
, ddpinp_lock
);
157 if (NetNumber
> ptree
->NetStop
) {
159 dPrintf(D_M_RTMP_LOW, D_L_ROUTING, ("%s : Go Right from #%d\n",
160 "rt_blookup", ptree->NextIRNet));
162 ptree
= ptree
->right
;
167 LowEnd
= ptree
->NetStart
;
169 LowEnd
= ptree
->NetStop
;
171 if (NetNumber
< LowEnd
) {
173 dPrintf(D_M_RTMP_LOW, D_L_ROUTING, ("%s : Go Left from #%d\n",
174 "rt_blookup", ptree->NextIRNet));
179 ATENABLE(s
, ddpinp_lock
);
181 /* we're in the range (either extended or not)
182 * return the entry found.
185 /* dPrintf(D_M_RTMP_LOW, D_L_ROUTING, ("%s : found %04d-%04d Port=%d State=0x%x\n",
186 "rt_blookup", ptree->NetStart, ptree->NetStop, ptree->NetPort,
193 ATENABLE(s
, ddpinp_lock
);
195 dPrintf(D_M_RTMP_LOW
, D_L_ROUTING
, ("%s : %04d : NOT FOUND\n",
196 "rt_blookup", NetNumber
));
197 return ((RT_entry
*)NULL
);
201 /* Routing table btree insert routine
202 * Uses a RT_entry parameter as the input, the insert is sorted in
203 * the tree on the NetStop field. Provision is made for non extented
204 * net (ie NetStart = 0).
205 * The function returns the element where the new entry was inserted, or
206 * NULL if the insert didn't work. (In this cas there is a problem with
207 * the tree coherency...
212 RT_entry
*rt_binsert (NewEntry
)
215 RT_entry
*ptree
= &RT_table_start
;
217 register at_net_al NetStart
= NewEntry
->NetStart
;
218 register at_net_al NetStop
= NewEntry
->NetStop
;
220 dPrintf(D_M_RTMP_LOW
, D_L_ROUTING
, ("rt_binsert: for Net %d-%d state=x%x NextIR %d:%d\n",
221 NetStart
, NetStop
, NewEntry
->EntryState
,NewEntry
->NextIRNet
, NewEntry
->NextIRNode
));
223 if (ptree
== (RT_entry
*)NULL
) {
225 at_state
.flags
|= AT_ST_RT_CHANGED
;
232 if (NetStop
> ptree
->NetStop
) { /* walk the right sub-tree */
234 ptree
= ptree
->right
;
236 ptree
->right
= NewEntry
;
237 at_state
.flags
|= AT_ST_RT_CHANGED
;
241 else { /* walk the left sub-tree */
245 ptree
->left
= NewEntry
;
246 at_state
.flags
|= AT_ST_RT_CHANGED
;
253 dPrintf(D_M_RTMP
, D_L_WARNING
, ("%s : ERROR NOT INSERTED Net %d-%d\n",
254 "rt_binsert", NetStart
, NetStop
));
255 return ((RT_entry
*)NULL
);
258 RT_entry
*rt_insert(NStop
, NStart
, NxNet
, NxNode
, NtDist
, NtPort
, EntS
)
259 at_net_al NStop
, NStart
, NxNet
;
261 u_char NtDist
, NtPort
, EntS
;
264 if ((New
= RT_table_freelist
)) {
265 RT_table_freelist
= RT_table_freelist
->right
;
267 return ((RT_entry
*)NULL
);
269 New
->NetStop
= NStop
;
270 New
->NetStart
= NStart
;
271 New
->NextIRNet
= NxNet
;
272 New
->NextIRNode
= NxNode
;
273 New
->NetDist
= NtDist
;
274 New
->NetPort
= NtPort
;
275 New
->EntryState
= EntS
;
276 bzero(New
->ZoneBitMap
, sizeof(New
->ZoneBitMap
));
277 at_state
.flags
|= AT_ST_RT_CHANGED
;
278 return(rt_binsert(New
));
282 dPrintf(D_M_RTMP_LOW, D_L_ROUTING, ("%s : %04d : NOT FOUND\n",
283 "rt_blookup", NetNumber));
284 * Routing table btree deletion routine
288 RT_entry
*rt_bdelete (NetStop
, NetStart
)
289 at_net_al NetStop
, NetStart
;
292 RT_entry
*rt_found
, *pprevious
, *pnext
, *pnextl
, *psub
;
295 rt_found
= &RT_table_start
;
297 dPrintf(D_M_RTMP_LOW
, D_L_ROUTING
, ("%s : Delete %d-%d\n",
298 "rt_bdelete", NetStart
, NetStop
));
302 if (NetStop
> rt_found
->NetStop
) {
303 pprevious
= rt_found
;
304 rt_found
= rt_found
->right
;
309 /* non extended nets cases */
311 if (rt_found
->NetStart
)
312 LowEnd
= rt_found
->NetStart
;
314 LowEnd
= rt_found
->NetStop
;
316 if (NetStop
< LowEnd
) {
317 pprevious
= rt_found
;
318 rt_found
= rt_found
->left
;
322 /* we're in the range (either extended or not)
323 * return the entry found.
330 dPrintf(D_M_RTMP
, D_L_ROUTING
, ("%s : Delete %d-%d found to delete %d-%d\n",
331 "rt_bdelete", NetStart
, NetStop
, rt_found
->NetStart
,rt_found
->NetStop
));
337 /* we found the entry, now reorg the sub-trees
338 * spanning from our node.
341 if ((pnext
= rt_found
->right
)) {
343 /* Tree pruning: take the left branch of the current
344 * node and place it at the lowest left branch
345 * of the current right branch
350 /* walk the Right/Left sub tree from current node */
352 while ((pnextl
= psub
->left
))
355 /* plug the old left tree to the new ->Right leftmost node */
357 psub
->left
= rt_found
->left
;
360 } else { /* only left sub-tree, simple case */
362 pnext
= rt_found
->left
;
365 /* Now, plug the current node sub tree to the good pointer of
370 if (pprevious
->left
== rt_found
)
371 pprevious
->left
= pnext
;
373 pprevious
->right
= pnext
;
375 /* clean-up entry and add to the free-list */
377 at_state
.flags
|= AT_ST_RT_CHANGED
;
381 else { /* Trying to delete something that doesn't exist? */
383 dPrintf(D_M_RTMP
, D_L_WARNING
, ("%s : %d NOT Removed\n",
384 "rt_bdelete", NetStop
));
386 return ((RT_entry
*)NULL
);
393 RT_entry
*rt_sortedshow(parent
)
400 if (parent
== NULL
) {
401 me
= &RT_table_start
;
407 /* parent = parent->parent; */
413 * debug only: display the contents of the routing table
421 ptree
= &RT_table
[0];
423 while (ptree
&& i
< 600 ) {
424 if (ptree
->NetStop
) {
425 dPrintf(D_M_RTMP_LOW
, D_L_VERBOSE
,
426 ("%4d-%4d IR=%d:%d Dist=%d\n",
427 ptree
->NetStop
, ptree
->NetStart
, ptree
->NextIRNet
,
428 ptree
->NextIRNode
, (short)ptree
->NetDist
));
430 dPrintf(D_M_RTMP_LOW
, D_L_VERBOSE
,
431 ("%04d : * FREE ENTRY\n", i
));
439 * prepare the indexing of the free entries in the RTMP table
446 if ((RT_table
= (RT_entry
*)_MALLOC(sizeof(RT_entry
)*RT_maxentry
,
447 M_RTABLE
, M_WAITOK
)) == NULL
) {
448 dPrintf(D_M_RTMP
, D_L_WARNING
,
449 ("rtmptable: Can't allocate RT_table\n"));
452 if ((ZT_table
= (ZT_entry
*)_MALLOC(sizeof(ZT_entry
)*ZT_maxentry
,
453 M_RTABLE
, M_WAITOK
)) == NULL
) {
454 dPrintf(D_M_RTMP
, D_L_WARNING
,
455 ("rtmptable: Can't allocate ZT_table\n"));
458 dPrintf(D_M_RTMP
, D_L_STARTUP
, ("rt_table_init called\n"));
459 bzero(&RT_table
[0], sizeof(RT_entry
)* RT_maxentry
);
460 for (i
= 1 ; i
< RT_maxentry
; i
++) {
461 (&RT_table
[i
-1])->right
= &RT_table
[i
];
463 RT_table_freelist
= &RT_table
[0];
465 at_state
.flags
|= AT_ST_RT_CHANGED
;
466 at_state
.flags
|= AT_ST_ZT_CHANGED
;
467 bzero(&RT_table_start
, sizeof(RT_entry
));
469 /* also clean up the ZIP table */
471 bzero(&ZT_table
[0], sizeof(ZT_entry
)* ZT_maxentry
);
472 ErrorRTMPoverflow
= 0;
473 ErrorZIPoverflow
= 0;
478 * zt_add_zone: add a zone name in the zone table.
481 zt_add_zone(name
, length
)
486 bcopy(name
, &zname
.str
, length
);
488 return (zt_add_zonename(&zname
));
492 * zt_add_zonename: add a zone name in the zone table.
495 int zt_add_zonename(zname
)
498 register short res
,i
;
499 register unsigned int s
;
501 if (res
= zt_find_zname(zname
))
504 ATDISABLE(s
, ddpinp_lock
);
505 for (i
= 0; i
< ZT_maxentry
; i
++) {
506 if (ZT_table
[i
].ZoneCount
== 0 && ZT_table
[i
].Zone
.len
== 0) {/* free entry */
507 ZT_table
[i
].Zone
= *zname
;
508 dPrintf(D_M_RTMP
, D_L_VERBOSE
, ("zt_add_zonename: zone #%d %s len=%d\n",
509 i
, ZT_table
[i
].Zone
.str
, ZT_table
[i
].Zone
.len
));
510 at_state
.flags
|= AT_ST_ZT_CHANGED
;
511 ATENABLE(s
, ddpinp_lock
);
515 ATENABLE(s
, ddpinp_lock
);
517 return (ZT_MAXEDOUT
);
520 /* Adjust zone counts for a removed network entry.
521 * If the ZoneCount of a zone reaches zero, delete the zone from the zone table
523 void zt_remove_zones(zmap
)
527 register u_short i
,j
, Index
;
529 for (i
=0; i
< ZT_BYTES
; i
++) {
532 for (j
=0; j
< 8 ; j
++)
533 if ((zmap
[i
] << j
) & 0x80) {
534 Index
= i
*8 + j
; /* get the index in ZT */
535 /* 1-23-97 this routine caused a crash once, presumably
536 zmap bits beyond ZT_table size got set somehow.
539 if (Index
>= ZT_maxentry
) {
540 dPrintf(D_M_RTMP
, D_L_ERROR
,
541 ("zt_remove_zones: index (%d) GT ZT_maxentry (%d) (zmap:%d)\n",
542 Index
,ZT_maxentry
,i
));
545 dPrintf(D_M_RTMP
, D_L_VERBOSE
,
546 ("zt_remove_zones: zone #%d %s was=%d\n", Index
,
547 ZT_table
[Index
].Zone
.str
, ZT_table
[Index
].ZoneCount
));
548 if (ZT_table
[Index
].ZoneCount
> 0)
549 ZT_table
[Index
].ZoneCount
--;
550 if (ZT_table
[Index
].ZoneCount
== 0)
551 ZT_table
[Index
].Zone
.len
= 0;
552 at_state
.flags
|= AT_ST_ZT_CHANGED
;
561 * zt_compute_hash: compute hash index from the zone name string
564 short zt_compute_hash(zname
)
567 register u_short checksum
=0, i
;
570 /* apply the upper name + DDP checksum algorithm */
572 for (i
= 0 ; i
< zname
->len
; i
++) {
574 /* upperize the character */
577 if (c1
>= 'a' && c1
<= 'z')
585 checksum
= ((checksum
& 0x8000) ?
586 (checksum
<< 1 | 1) : (checksum
<< 1));
589 dPrintf(D_M_RTMP_LOW
, D_L_ROUTING
, ("zt_comphash: value computed for zone=%s h=%d\n",
590 zname
->str
, checksum
));
600 * zt_upper_zname: translate the name string into uppercase
603 void zt_upper_zname(zname
)
609 for (i
= 0 ; i
< zname
->len
; i
++) {
612 if (c1
>= 'a' && c1
<= 'z')
622 * zt_get_zmcast: calcularte the zone multicast address for a
624 * Returns the result in "buffer"
627 zt_get_zmcast(ifID
, zname
, buffer
)
628 at_ifaddr_t
*ifID
; /* we want to know the media type */
629 at_nvestr_t
*zname
; /* source name for multicast address */
630 char *buffer
; /* resulting Zone Multicast address */
634 h
= zt_compute_hash(zname
);
637 * Find a nice way to decide if it is TokenRing or Ethernet for
638 * the Multicast address computation....
641 if (ifID
->aa_ifp
->if_type
!= IFT_ISO88025
) { /* token ring */
648 /* no router, use cable multicast */
649 if (MULTIHOME_MODE
&& ifID
->ifRouterState
== NO_ROUTER
) {
650 buffer
[3] = buffer
[4] = buffer
[5] = 0xff;
655 buffer
[5] = h
% 0xFD;
657 dPrintf(D_M_RTMP_LOW
, D_L_ROUTING
, ("zt_get_multi: computed for h=%d %x %x\n",
658 h
, *(u_int
*)&buffer
[0], *(u_short
*)&buffer
[4]));
660 return(6); /* returns Multicast address length */
664 /* assume it is token ring: note for the magic number computation,
665 * first see Inside Mac Page 3-10, there is 20 multicast addresses
666 * for TLAP, and they are from 0xC000 0000 0008 00 to 0xC000 0200 0000 00
670 *(u_int
*)&buffer
[2] = 1 << ((h
% 19) + 11);
671 dPrintf(D_M_RTMP
, D_L_WARNING
,("zt_get_multi: BROAD not found forr h=%d \n",
681 * zt_ent_zindex: return the first zone index found in the zone map
682 * return the entry number+1 in the Zone Table, or zero if not found
685 int zt_ent_zindex(zmap
)
691 for (i
= 0 ; i
< ZT_BYTES
; i
++)
694 for (j
= 0 ; j
< 8 ; j
++)
695 if ((zmap
[i
] << j
) & 0x80)
701 * zt_ent_zcount: count the number of actives zone for a routing entry
707 register u_char
*zmap
;
708 register u_short i
,j
;
709 register int zone_count
= 0 ;
710 register unsigned int s
;
712 ATDISABLE(s
, ddpinp_lock
);
714 if (!RT_ALL_ZONES_KNOWN(ent
)) {
715 ATENABLE(s
, ddpinp_lock
);
718 zmap
= ent
->ZoneBitMap
;
720 for (i
= 0 ; i
< ZT_BYTES
; i
++) {
724 for (j
= 0 ; j
< 8 ; j
++)
725 if ((*zmap
<< j
) & 0x80)
730 ATENABLE(s
, ddpinp_lock
);
735 * zt_find_zname: match a zone name in the zone table and return the entry if found
740 register short i
, j
, found
;
741 register char c1
, c2
;
742 register unsigned int s
;
748 ATDISABLE(s
, ddpinp_lock
);
749 for (i
= 0 ; i
< ZT_maxentry
; i
++) {
750 if (!ZT_table
[i
].ZoneCount
|| zname
->len
!= ZT_table
[i
].Zone
.len
)
753 found
= 1; /* did we get the right one? */
755 for (j
= 0 ; j
< zname
->len
; j
++) {
757 c2
= ZT_table
[i
].Zone
.str
[j
];
758 if (c1
>= 'a' && c1
<= 'z')
760 if (c2
>= 'a' && c2
<= 'z')
773 ATENABLE(s
, ddpinp_lock
);
778 ATENABLE(s
, ddpinp_lock
);
784 * zt_set_zmap: set a bit for the corresponding zone map in an entry bitmap
786 void zt_set_zmap(znum
, zmap
)
790 register u_short num
= znum
-1;
791 register unsigned int s
;
793 ATDISABLE(s
, ddpinp_lock
);
794 if (!(zmap
[num
>> 3] & 0x80 >> (num
% 8))) {
795 zmap
[num
>> 3] |= 0x80 >> (num
% 8);
796 ZT_table
[num
].ZoneCount
++;
798 ATENABLE(s
, ddpinp_lock
);
803 * zt_clr_zmap: clear a bit for the corresponding zone map in an entry bitmap
805 void zt_clr_zmap(znum
, zmap
)
809 register u_short num
= znum
-1;
810 register unsigned int s
;
812 ATDISABLE(s
, ddpinp_lock
);
813 if (zmap
[num
>> 3] & 0x80 >> (num
% 8)) {
814 zmap
[num
>> 3] ^= 0x80 >> (num
% 8);
815 ZT_table
[num
].ZoneCount
--;
817 ATENABLE(s
, ddpinp_lock
);
823 * This function performs the actual lookup and forward of packets
824 * send to the box for routing.
826 * The destination network is looked up in our tables, and if we
827 * know the next IR to send the packet to, we forward the packet
830 * If the destination is unknown, we simply dump the packet.
833 void routing_needed(mp
, ifID
, bypass
)
836 char bypass
; /* set by special socket handlers */
839 register at_ddp_t
*ddp
;
840 register int msgsize
;
841 register RT_entry
*Entry
;
842 register gbuf_t
*tmp_m
;
844 /* first check the interface is up and forwarding */
847 dPrintf(D_M_RTMP
, D_L_WARNING
,
848 ("routing_needed: non valid IFID!\n"));
852 if ((ifID
->ifRoutingState
< PORT_ONLINE
)) {
853 dPrintf(D_M_RTMP
, D_L_WARNING
,
854 ("routing_needed: port %d not online yet\n",
860 ddp
= (at_ddp_t
*)gbuf_rptr(mp
);
861 msgsize
= DDPLEN_VALUE(ddp
);
862 for (tmp_m
= gbuf_next(mp
); tmp_m
; tmp_m
= gbuf_next(tmp_m
))
863 msgsize
+= DDPLEN_VALUE(((at_ddp_t
*)gbuf_rptr(tmp_m
)));
865 if (ddp
->hopcount
++ > 15) {
866 dPrintf(D_M_RTMP
, D_L_WARNING
,
867 ("routing_needed: drop packet for %d:%d, hopcount too high\n",
868 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
));
870 snmpStats
.dd_hopCount
++;
871 return; /* was return(1); */
874 if ((Entry
= rt_blookup(NET_VALUE(ddp
->dst_net
)))) {
876 dPrintf(D_M_RTMP_LOW
, D_L_ROUTING
,
877 ("routing_needed: FOUND for %d.%d p=%d to %d.%d \n",
878 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, ifID
->ifPort
,
879 Entry
->NextIRNet
, Entry
->NextIRNode
));
881 /* somehow, come to that point... */
883 ifID
->ifStatistics
.fwdPkts
++;
884 ifID
->ifStatistics
.fwdBytes
+= msgsize
;
886 if (Entry
->NetDist
) /* net not directly connected */
887 ddp_router_output(mp
, ifID_table
[Entry
->NetPort
], AT_ADDR
,
888 Entry
->NextIRNet
, Entry
->NextIRNode
, 0);
889 else {/* we are directly on this net */
891 /* we want to avoid duplicating broadcast packet on the same net,
892 * but special sockets handlers are ok to do that (mainly for
893 * for loopback purpose). So, if the "bypass" flag is set, we don't
894 * check for that test... [Problem was "movietalk"].
897 if (bypass
|| ifID_table
[Entry
->NetPort
] != ifID
)
898 ddp_router_output(mp
, ifID_table
[Entry
->NetPort
], AT_ADDR
,
899 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, 0);
901 dPrintf(D_M_RTMP
, D_L_ROUTING
,
902 ("routing_needed: bad loopback for add %d.%d from port %d (%d.%d)\n",
903 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, ifID
->ifPort
,
904 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
905 ifID
->ifStatistics
.droppedPkts
++;
906 ifID
->ifStatistics
.droppedBytes
+= msgsize
;
909 return; /* was return (2); */
916 dPrintf(D_M_RTMP
, D_L_ROUTING
,
917 ("routing_needed: NOT FOUND for add %d.%d from port %d our %d.%d\n",
918 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, ifID
->ifPort
,
919 ifID_home
->ifThisNode
.s_net
,
920 ifID_home
->ifThisNode
.s_node
));
922 ifID
->ifStatistics
.droppedPkts
++;
923 ifID
->ifStatistics
.droppedBytes
+= msgsize
;
924 snmpStats
.dd_noRoutes
++;
927 return; /* was return (2); */
931 } /* routing_needed */
933 ZT_entryno
*zt_getNextZone(first
)
935 /* a call made with first = TRUE returns the first valid entry in
936 the ZT_table, if first != TRUE, then then each call returns the
937 next valid entry in the table. The next call after the last
938 valid entry was read returns NULL
943 static ZT_entryno zte
;
951 for (i
=idx
; i
<ZT_maxentry
; i
++) {
952 if (ZT_table
[i
].ZoneCount
)
957 zte
.zt
= ZT_table
[i
];
965 RT_entry
*rt_getNextRoute(first
)
968 /* a call made with first = TRUE returns the first valid entry in
969 the RT_table, if first != TRUE, then then each call returns the
970 next valid entry in the table. The next call after the last
971 valid entry was read returns NULL
984 for (i
=idx
; i
<RT_maxentry
; i
++) {
985 if (RT_table
[i
].EntryState
!= RTE_STATE_UNUSED
)
990 return(&RT_table
[i
]);
1000 register RT_entry
*rt
;
1003 if(!(at_state
.flags
&AT_ST_RT_CHANGED
))
1006 for (i
=RT_maxentry
,rt
= &RT_table
[RT_maxentry
-1]; i
; i
--,rt
--)
1007 if (rt
->EntryState
!= RTE_STATE_UNUSED
) {
1017 register ZT_entry
*zt
;
1020 if (!(at_state
.flags
& AT_ST_ZT_CHANGED
))
1023 for (i
=ZT_maxentry
,zt
= &ZT_table
[ZT_maxentry
-1]; i
; i
--,zt
--)
1024 if (zt
->ZoneCount
) {
1032 RT_entry
*d
; /* destination */
1033 int s
; /* starting entry */
1034 int c
; /* # entries to copy */
1037 register RT_entry
*rt
;
1039 for(i
=s
,rt
=&RT_table
[s
]; i
<RT_maxentry
&& n
<c
; rt
++,i
++)
1040 if (rt
->EntryState
!= RTE_STATE_UNUSED
) {
1047 ZT_entry
*d
; /* destination */
1048 int s
; /* starting entry */
1049 int c
; /* # entries to copy */
1052 bcopy(&ZT_table
[s
], d
, c
*sizeof(ZT_entry
));
1055 at_nvestr_t
*getRTRLocalZone(ifz
)
1061 int zcnt
=0; /* zone we're pointing to in the list */
1062 char zonesChecked
[ZT_BYTES
];
1065 if (ifz
->zone_index
< 0) {
1066 return((at_nvestr_t
*)NULL
);
1068 bzero(zonesChecked
,sizeof(zonesChecked
));
1069 TAILQ_FOREACH(ifID
, &at_ifQueueHd
, aa_link
) {
1070 if (!(route
= rt_blookup(ifID
->ifThisNode
.s_net
))) {
1071 return((at_nvestr_t
*)NULL
);
1073 zmap
=route
->ZoneBitMap
;
1074 dPrintf(D_M_RTMP_LOW
, D_L_USR1
,
1075 ("getRTRLocal: i/f %s, net:%d\n",ifID
->ifName
,
1076 ifID
->ifThisNode
.s_net
));
1077 for (i
= 0 ; i
< ZT_BYTES
; i
++) {
1079 for (j
= 0; j
< 8 ; j
++)
1080 if ( (zmap
[i
] & (0x80 >> j
)) &&
1081 !(zonesChecked
[i
] & (0x80 >> j
))
1083 zonesChecked
[i
] |= (0x80 >> j
);
1084 if (ifz
->zone_index
== zcnt
) {
1086 getIfUsage(index
, &ifz
->zone_iflist
);
1087 ifz
->zone_name
= ZT_table
[index
].Zone
;
1088 dPrintf(D_M_RTMP_LOW
, D_L_USR1
,
1089 ("getRTRLocal:zmap:%8x zcnt:%d\n",
1090 *(int*)zmap
, zcnt
));
1091 ifz
->zone_index
= index
+1;
1092 return(&ZT_table
[index
].Zone
);
1099 dPrintf(D_M_RTMP_LOW
, D_L_USR1
,
1100 ("getRTRLocal: returning NULL last ent:%d net:%d zmap:%08x\n",
1101 (ifID
? ifID
->ifPort
: 0),
1102 (ifID
? ifID
->ifThisNode
.s_net
: 0),*(int*)zmap
));
1103 ifz
->zone_name
.len
= 0;
1104 return((at_nvestr_t
*)NULL
);
1105 } /* getRTRLocalZone */
1107 void getIfUsage(zone
, ifs_in_zone
)
1109 at_ifnames_t
*ifs_in_zone
;
1111 /* sets a "1" in each element of the char array for each I/F in the
1112 requested zone. The char array has a 1:1 correspondence with the
1113 ifID_table. Zone is assumed to be valid and local, so if we're in
1114 single port mode, we'll set the home port and thats it.
1117 u_int zmi
; /* zone map index for zone */
1118 u_char zmb
; /* zone map bit mask for zone */
1123 if (!MULTIPORT_MODE
) {
1124 strncpy(ifs_in_zone
->at_if
[cnt
], ifID_home
->ifName
,
1128 bzero(ifs_in_zone
, sizeof(at_ifnames_t
));
1130 zmb
= 0x80>>(zone
% 8);
1131 dPrintf(D_M_NBP_LOW
, D_L_USR3
, ("get_ifs znum:%d zmi%d zmb:%x\n",
1133 TAILQ_FOREACH(ifID
, &at_ifQueueHd
, aa_link
) {
1134 if (!(route
= rt_blookup(ifID
->ifThisNode
.s_net
)))
1136 if (route
->ZoneBitMap
[zmi
] & zmb
) {
1137 dPrintf(D_M_NBP_LOW
, D_L_USR3
, ("zone in port %d \n",
1139 strncpy(ifs_in_zone
->at_if
[cnt
],
1140 ifID_table
[route
->NetPort
]->ifName
, IFNAMESIZ
);