]>
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 * 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@
25 /*----------------------------------------------------------------------------
27 * RTMP & ZIP routing tables access routines
29 * This code implement b-tree search and manipulation of
30 * of the RTMP routing table and ZIP zone table.
32 * The RTMP routing table is a data block divided in several routing
33 * entries sorted during insertion in a b-tree form. We use a table and
34 * not dynamically allocated entries because it allow us to scan the whole
35 * table when RTMP packets are generated. The routing table entries are sorted
36 * by there NetStop value (because non extended nets have a NetStart value of
37 * zero. From any point in the tree, the left side contains Network ranges
38 * smaller or equal to the current Node, and the right tree points to higher
39 * values network ranges.
42 * 0.01 3/16/94 LD Creation
43 * Modified for MP, 1996 by Tuyen Nguyen
44 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
46 *----------------------------------------------------------------------------
48 * Copyright (c) 1994, 1996, 1997, 1998 Apple Computer, Inc.
51 #include <sys/errno.h>
52 #include <sys/types.h>
53 #include <sys/param.h>
54 #include <machine/spl.h>
55 #include <sys/systm.h>
56 #include <sys/kernel.h>
58 #include <sys/filedesc.h>
59 #include <sys/fcntl.h>
61 #include <sys/ioctl.h>
62 #include <sys/malloc.h>
63 #include <sys/socket.h>
64 #include <sys/socketvar.h>
67 #include <net/if_types.h>
69 #include <netat/sysglue.h>
70 #include <netat/appletalk.h>
71 #include <netat/at_var.h>
72 #include <netat/ddp.h>
73 #include <netat/rtmp.h>
74 #include <netat/at_pcb.h>
75 #include <netat/zip.h>
76 #include <netat/routing_tables.h>
77 #include <netat/at_snmp.h>
78 #include <netat/debug.h>
80 RT_entry
*RT_table_freelist
; /* start of free entry list */
81 RT_entry RT_table_start
; /* start of the actual entry table */
82 RT_entry
*RT_table
; /* the routing table */
83 ZT_entry
*ZT_table
; /* the Zone Information Protocol table */
84 short RT_maxentry
; /* Number of entry in RTMP table */
85 short ZT_maxentry
; /* Number of entry in ZIP table */
87 char errstr
[512]; /* used to display meaningfull router errors*/
89 extern at_ifaddr_t
*ifID_table
[];
90 extern at_ifaddr_t
*ifID_home
;
91 extern snmpStats_t snmpStats
;
92 extern atlock_t ddpinp_lock
;
94 short ErrorRTMPoverflow
= 0; /* flag if RTMP table is too small for this net */
95 short ErrorZIPoverflow
= 0; /* flag if ZIP table is too small for this net */
98 void getIfUsage( int, at_ifnames_t
*);
101 * This a temporary function : just to display the router error
104 void RouterError(port
, err_number
)
105 short port
, err_number
;
108 switch (err_number
) {
110 case ERTR_SEED_CONFLICT
:
111 dPrintf(D_M_RTMP
, D_L_ERROR
,
112 ("**** RTR Error on port# %d SEED_CONFLICT\n", port
));
115 case ERTR_CABLE_CONFLICT
:
116 dPrintf(D_M_RTMP
, D_L_ERROR
,
117 ("**** RTR Error on port# %d CABLE_CONFLICT\n", port
));
120 case ERTR_RTMP_BAD_VERSION
:
121 dPrintf(D_M_RTMP
, D_L_ERROR
,
122 ("**** RTR Error on port# %d RTMP_BAD_VERSION\n", port
));
125 case ERTR_CABLE_STARTUP
:
126 dPrintf(D_M_RTMP
, D_L_ERROR
,
127 ("**** RTR Error on port# %d RTMP_CABLE_STARTUP\n",
132 dPrintf(D_M_RTMP
, D_L_ERROR
,
133 ("**** RTR Error on port# %d WHAT IN THE WORLD IS THIS ONE? code=%d\n",
137 dPrintf(D_M_RTMP
, D_L_ERROR
, ("Explanation: %s\n", errstr
));
142 * this function just look for a NetNumber in the routing table,
143 * no check is done for the validity of the entry
146 RT_entry
*rt_blookup (NetNumber
)
150 RT_entry
*ptree
= &RT_table_start
;
152 register unsigned int s
;
154 dPrintf(D_M_RTMP_LOW, D_L_ROUTING, ("%s : Lookup for Net=%d\n",
155 "rt_blookup", NetNumber));
157 ATDISABLE(s
, ddpinp_lock
);
160 if (NetNumber
> ptree
->NetStop
) {
162 dPrintf(D_M_RTMP_LOW, D_L_ROUTING, ("%s : Go Right from #%d\n",
163 "rt_blookup", ptree->NextIRNet));
165 ptree
= ptree
->right
;
170 LowEnd
= ptree
->NetStart
;
172 LowEnd
= ptree
->NetStop
;
174 if (NetNumber
< LowEnd
) {
176 dPrintf(D_M_RTMP_LOW, D_L_ROUTING, ("%s : Go Left from #%d\n",
177 "rt_blookup", ptree->NextIRNet));
182 ATENABLE(s
, ddpinp_lock
);
184 /* we're in the range (either extended or not)
185 * return the entry found.
188 /* dPrintf(D_M_RTMP_LOW, D_L_ROUTING, ("%s : found %04d-%04d Port=%d State=0x%x\n",
189 "rt_blookup", ptree->NetStart, ptree->NetStop, ptree->NetPort,
196 ATENABLE(s
, ddpinp_lock
);
198 dPrintf(D_M_RTMP_LOW
, D_L_ROUTING
, ("%s : %04d : NOT FOUND\n",
199 "rt_blookup", NetNumber
));
200 return ((RT_entry
*)NULL
);
204 /* Routing table btree insert routine
205 * Uses a RT_entry parameter as the input, the insert is sorted in
206 * the tree on the NetStop field. Provision is made for non extented
207 * net (ie NetStart = 0).
208 * The function returns the element where the new entry was inserted, or
209 * NULL if the insert didn't work. (In this cas there is a problem with
210 * the tree coherency...
215 RT_entry
*rt_binsert (NewEntry
)
218 RT_entry
*ptree
= &RT_table_start
;
220 register at_net_al NetStart
= NewEntry
->NetStart
;
221 register at_net_al NetStop
= NewEntry
->NetStop
;
223 dPrintf(D_M_RTMP_LOW
, D_L_ROUTING
, ("rt_binsert: for Net %d-%d state=x%x NextIR %d:%d\n",
224 NetStart
, NetStop
, NewEntry
->EntryState
,NewEntry
->NextIRNet
, NewEntry
->NextIRNode
));
226 if (ptree
== (RT_entry
*)NULL
) {
228 at_state
.flags
|= AT_ST_RT_CHANGED
;
235 if (NetStop
> ptree
->NetStop
) { /* walk the right sub-tree */
237 ptree
= ptree
->right
;
239 ptree
->right
= NewEntry
;
240 at_state
.flags
|= AT_ST_RT_CHANGED
;
244 else { /* walk the left sub-tree */
248 ptree
->left
= NewEntry
;
249 at_state
.flags
|= AT_ST_RT_CHANGED
;
256 dPrintf(D_M_RTMP
, D_L_WARNING
, ("%s : ERROR NOT INSERTED Net %d-%d\n",
257 "rt_binsert", NetStart
, NetStop
));
258 return ((RT_entry
*)NULL
);
261 RT_entry
*rt_insert(NStop
, NStart
, NxNet
, NxNode
, NtDist
, NtPort
, EntS
)
262 at_net_al NStop
, NStart
, NxNet
;
264 u_char NtDist
, NtPort
, EntS
;
267 if ((New
= RT_table_freelist
)) {
268 RT_table_freelist
= RT_table_freelist
->right
;
270 return ((RT_entry
*)NULL
);
272 New
->NetStop
= NStop
;
273 New
->NetStart
= NStart
;
274 New
->NextIRNet
= NxNet
;
275 New
->NextIRNode
= NxNode
;
276 New
->NetDist
= NtDist
;
277 New
->NetPort
= NtPort
;
278 New
->EntryState
= EntS
;
279 bzero(New
->ZoneBitMap
, sizeof(New
->ZoneBitMap
));
280 at_state
.flags
|= AT_ST_RT_CHANGED
;
281 return(rt_binsert(New
));
285 dPrintf(D_M_RTMP_LOW, D_L_ROUTING, ("%s : %04d : NOT FOUND\n",
286 "rt_blookup", NetNumber));
287 * Routing table btree deletion routine
291 RT_entry
*rt_bdelete (NetStop
, NetStart
)
292 at_net_al NetStop
, NetStart
;
295 RT_entry
*rt_found
, *pprevious
, *pnext
, *pnextl
, *psub
;
298 rt_found
= &RT_table_start
;
300 dPrintf(D_M_RTMP_LOW
, D_L_ROUTING
, ("%s : Delete %d-%d\n",
301 "rt_bdelete", NetStart
, NetStop
));
305 if (NetStop
> rt_found
->NetStop
) {
306 pprevious
= rt_found
;
307 rt_found
= rt_found
->right
;
312 /* non extended nets cases */
314 if (rt_found
->NetStart
)
315 LowEnd
= rt_found
->NetStart
;
317 LowEnd
= rt_found
->NetStop
;
319 if (NetStop
< LowEnd
) {
320 pprevious
= rt_found
;
321 rt_found
= rt_found
->left
;
325 /* we're in the range (either extended or not)
326 * return the entry found.
333 dPrintf(D_M_RTMP
, D_L_ROUTING
, ("%s : Delete %d-%d found to delete %d-%d\n",
334 "rt_bdelete", NetStart
, NetStop
, rt_found
->NetStart
,rt_found
->NetStop
));
340 /* we found the entry, now reorg the sub-trees
341 * spanning from our node.
344 if ((pnext
= rt_found
->right
)) {
346 /* Tree pruning: take the left branch of the current
347 * node and place it at the lowest left branch
348 * of the current right branch
353 /* walk the Right/Left sub tree from current node */
355 while ((pnextl
= psub
->left
))
358 /* plug the old left tree to the new ->Right leftmost node */
360 psub
->left
= rt_found
->left
;
363 } else { /* only left sub-tree, simple case */
365 pnext
= rt_found
->left
;
368 /* Now, plug the current node sub tree to the good pointer of
373 if (pprevious
->left
== rt_found
)
374 pprevious
->left
= pnext
;
376 pprevious
->right
= pnext
;
378 /* clean-up entry and add to the free-list */
380 at_state
.flags
|= AT_ST_RT_CHANGED
;
384 else { /* Trying to delete something that doesn't exist? */
386 dPrintf(D_M_RTMP
, D_L_WARNING
, ("%s : %d NOT Removed\n",
387 "rt_bdelete", NetStop
));
389 return ((RT_entry
*)NULL
);
396 RT_entry
*rt_sortedshow(parent
)
403 if (parent
== NULL
) {
404 me
= &RT_table_start
;
410 /* parent = parent->parent; */
416 * debug only: display the contents of the routing table
424 ptree
= &RT_table
[0];
426 while (ptree
&& i
< 600 ) {
427 if (ptree
->NetStop
) {
428 dPrintf(D_M_RTMP_LOW
, D_L_VERBOSE
,
429 ("%4d-%4d IR=%d:%d Dist=%d\n",
430 ptree
->NetStop
, ptree
->NetStart
, ptree
->NextIRNet
,
431 ptree
->NextIRNode
, (short)ptree
->NetDist
));
433 dPrintf(D_M_RTMP_LOW
, D_L_VERBOSE
,
434 ("%04d : * FREE ENTRY\n", i
));
442 * prepare the indexing of the free entries in the RTMP table
449 if ((RT_table
= (RT_entry
*)_MALLOC(sizeof(RT_entry
)*RT_maxentry
,
450 M_RTABLE
, M_WAITOK
)) == NULL
) {
451 dPrintf(D_M_RTMP
, D_L_WARNING
,
452 ("rtmptable: Can't allocate RT_table\n"));
455 if ((ZT_table
= (ZT_entry
*)_MALLOC(sizeof(ZT_entry
)*ZT_maxentry
,
456 M_RTABLE
, M_WAITOK
)) == NULL
) {
457 dPrintf(D_M_RTMP
, D_L_WARNING
,
458 ("rtmptable: Can't allocate ZT_table\n"));
461 dPrintf(D_M_RTMP
, D_L_STARTUP
, ("rt_table_init called\n"));
462 bzero(&RT_table
[0], sizeof(RT_entry
)* RT_maxentry
);
463 for (i
= 1 ; i
< RT_maxentry
; i
++) {
464 (&RT_table
[i
-1])->right
= &RT_table
[i
];
466 RT_table_freelist
= &RT_table
[0];
468 at_state
.flags
|= AT_ST_RT_CHANGED
;
469 at_state
.flags
|= AT_ST_ZT_CHANGED
;
470 bzero(&RT_table_start
, sizeof(RT_entry
));
472 /* also clean up the ZIP table */
474 bzero(&ZT_table
[0], sizeof(ZT_entry
)* ZT_maxentry
);
475 ErrorRTMPoverflow
= 0;
476 ErrorZIPoverflow
= 0;
481 * zt_add_zone: add a zone name in the zone table.
484 zt_add_zone(name
, length
)
489 bcopy(name
, &zname
.str
, length
);
491 return (zt_add_zonename(&zname
));
495 * zt_add_zonename: add a zone name in the zone table.
498 int zt_add_zonename(zname
)
501 register short res
,i
;
502 register unsigned int s
;
504 if (res
= zt_find_zname(zname
))
507 ATDISABLE(s
, ddpinp_lock
);
508 for (i
= 0; i
< ZT_maxentry
; i
++) {
509 if (ZT_table
[i
].ZoneCount
== 0 && ZT_table
[i
].Zone
.len
== 0) {/* free entry */
510 ZT_table
[i
].Zone
= *zname
;
511 dPrintf(D_M_RTMP
, D_L_VERBOSE
, ("zt_add_zonename: zone #%d %s len=%d\n",
512 i
, ZT_table
[i
].Zone
.str
, ZT_table
[i
].Zone
.len
));
513 at_state
.flags
|= AT_ST_ZT_CHANGED
;
514 ATENABLE(s
, ddpinp_lock
);
518 ATENABLE(s
, ddpinp_lock
);
520 return (ZT_MAXEDOUT
);
523 /* Adjust zone counts for a removed network entry.
524 * If the ZoneCount of a zone reaches zero, delete the zone from the zone table
526 void zt_remove_zones(zmap
)
530 register u_short i
,j
, Index
;
532 for (i
=0; i
< ZT_BYTES
; i
++) {
535 for (j
=0; j
< 8 ; j
++)
536 if ((zmap
[i
] << j
) & 0x80) {
537 Index
= i
*8 + j
; /* get the index in ZT */
538 /* 1-23-97 this routine caused a crash once, presumably
539 zmap bits beyond ZT_table size got set somehow.
542 if (Index
>= ZT_maxentry
) {
543 dPrintf(D_M_RTMP
, D_L_ERROR
,
544 ("zt_remove_zones: index (%d) GT ZT_maxentry (%d) (zmap:%d)\n",
545 Index
,ZT_maxentry
,i
));
548 dPrintf(D_M_RTMP
, D_L_VERBOSE
,
549 ("zt_remove_zones: zone #%d %s was=%d\n", Index
,
550 ZT_table
[Index
].Zone
.str
, ZT_table
[Index
].ZoneCount
));
551 if (ZT_table
[Index
].ZoneCount
> 0)
552 ZT_table
[Index
].ZoneCount
--;
553 if (ZT_table
[Index
].ZoneCount
== 0)
554 ZT_table
[Index
].Zone
.len
= 0;
555 at_state
.flags
|= AT_ST_ZT_CHANGED
;
564 * zt_compute_hash: compute hash index from the zone name string
567 short zt_compute_hash(zname
)
570 register u_short checksum
=0, i
;
573 /* apply the upper name + DDP checksum algorithm */
575 for (i
= 0 ; i
< zname
->len
; i
++) {
577 /* upperize the character */
580 if (c1
>= 'a' && c1
<= 'z')
588 checksum
= ((checksum
& 0x8000) ?
589 (checksum
<< 1 | 1) : (checksum
<< 1));
592 dPrintf(D_M_RTMP_LOW
, D_L_ROUTING
, ("zt_comphash: value computed for zone=%s h=%d\n",
593 zname
->str
, checksum
));
603 * zt_upper_zname: translate the name string into uppercase
606 void zt_upper_zname(zname
)
612 for (i
= 0 ; i
< zname
->len
; i
++) {
615 if (c1
>= 'a' && c1
<= 'z')
625 * zt_get_zmcast: calcularte the zone multicast address for a
627 * Returns the result in "buffer"
630 zt_get_zmcast(ifID
, zname
, buffer
)
631 at_ifaddr_t
*ifID
; /* we want to know the media type */
632 at_nvestr_t
*zname
; /* source name for multicast address */
633 char *buffer
; /* resulting Zone Multicast address */
637 h
= zt_compute_hash(zname
);
640 * Find a nice way to decide if it is TokenRing or Ethernet for
641 * the Multicast address computation....
644 if (ifID
->aa_ifp
->if_type
!= IFT_ISO88025
) { /* token ring */
651 /* no router, use cable multicast */
652 if (MULTIHOME_MODE
&& ifID
->ifRouterState
== NO_ROUTER
) {
653 buffer
[3] = buffer
[4] = buffer
[5] = 0xff;
658 buffer
[5] = h
% 0xFD;
660 dPrintf(D_M_RTMP_LOW
, D_L_ROUTING
, ("zt_get_multi: computed for h=%d %x %x\n",
661 h
, *(u_int
*)&buffer
[0], *(u_short
*)&buffer
[4]));
663 return(6); /* returns Multicast address length */
667 /* assume it is token ring: note for the magic number computation,
668 * first see Inside Mac Page 3-10, there is 20 multicast addresses
669 * for TLAP, and they are from 0xC000 0000 0008 00 to 0xC000 0200 0000 00
673 *(u_int
*)&buffer
[2] = 1 << ((h
% 19) + 11);
674 dPrintf(D_M_RTMP
, D_L_WARNING
,("zt_get_multi: BROAD not found forr h=%d \n",
684 * zt_ent_zindex: return the first zone index found in the zone map
685 * return the entry number+1 in the Zone Table, or zero if not found
688 int zt_ent_zindex(zmap
)
694 for (i
= 0 ; i
< ZT_BYTES
; i
++)
697 for (j
= 0 ; j
< 8 ; j
++)
698 if ((zmap
[i
] << j
) & 0x80)
704 * zt_ent_zcount: count the number of actives zone for a routing entry
710 register u_char
*zmap
;
711 register u_short i
,j
;
712 register int zone_count
= 0 ;
713 register unsigned int s
;
715 ATDISABLE(s
, ddpinp_lock
);
717 if (!RT_ALL_ZONES_KNOWN(ent
)) {
718 ATENABLE(s
, ddpinp_lock
);
721 zmap
= ent
->ZoneBitMap
;
723 for (i
= 0 ; i
< ZT_BYTES
; i
++) {
727 for (j
= 0 ; j
< 8 ; j
++)
728 if ((*zmap
<< j
) & 0x80)
733 ATENABLE(s
, ddpinp_lock
);
738 * zt_find_zname: match a zone name in the zone table and return the entry if found
743 register short i
, j
, found
;
744 register char c1
, c2
;
745 register unsigned int s
;
751 ATDISABLE(s
, ddpinp_lock
);
752 for (i
= 0 ; i
< ZT_maxentry
; i
++) {
753 if (!ZT_table
[i
].ZoneCount
|| zname
->len
!= ZT_table
[i
].Zone
.len
)
756 found
= 1; /* did we get the right one? */
758 for (j
= 0 ; j
< zname
->len
; j
++) {
760 c2
= ZT_table
[i
].Zone
.str
[j
];
761 if (c1
>= 'a' && c1
<= 'z')
763 if (c2
>= 'a' && c2
<= 'z')
776 ATENABLE(s
, ddpinp_lock
);
781 ATENABLE(s
, ddpinp_lock
);
787 * zt_set_zmap: set a bit for the corresponding zone map in an entry bitmap
789 void zt_set_zmap(znum
, zmap
)
793 register u_short num
= znum
-1;
794 register unsigned int s
;
796 ATDISABLE(s
, ddpinp_lock
);
797 if (!(zmap
[num
>> 3] & 0x80 >> (num
% 8))) {
798 zmap
[num
>> 3] |= 0x80 >> (num
% 8);
799 ZT_table
[num
].ZoneCount
++;
801 ATENABLE(s
, ddpinp_lock
);
806 * zt_clr_zmap: clear a bit for the corresponding zone map in an entry bitmap
808 void zt_clr_zmap(znum
, zmap
)
812 register u_short num
= znum
-1;
813 register unsigned int s
;
815 ATDISABLE(s
, ddpinp_lock
);
816 if (zmap
[num
>> 3] & 0x80 >> (num
% 8)) {
817 zmap
[num
>> 3] ^= 0x80 >> (num
% 8);
818 ZT_table
[num
].ZoneCount
--;
820 ATENABLE(s
, ddpinp_lock
);
826 * This function performs the actual lookup and forward of packets
827 * send to the box for routing.
829 * The destination network is looked up in our tables, and if we
830 * know the next IR to send the packet to, we forward the packet
833 * If the destination is unknown, we simply dump the packet.
836 void routing_needed(mp
, ifID
, bypass
)
839 char bypass
; /* set by special socket handlers */
842 register at_ddp_t
*ddp
;
843 register int msgsize
;
844 register RT_entry
*Entry
;
845 register gbuf_t
*tmp_m
;
847 /* first check the interface is up and forwarding */
850 dPrintf(D_M_RTMP
, D_L_WARNING
,
851 ("routing_needed: non valid IFID!\n"));
855 if ((ifID
->ifRoutingState
< PORT_ONLINE
)) {
856 dPrintf(D_M_RTMP
, D_L_WARNING
,
857 ("routing_needed: port %d not online yet\n",
863 ddp
= (at_ddp_t
*)gbuf_rptr(mp
);
864 msgsize
= DDPLEN_VALUE(ddp
);
865 for (tmp_m
= gbuf_next(mp
); tmp_m
; tmp_m
= gbuf_next(tmp_m
))
866 msgsize
+= DDPLEN_VALUE(((at_ddp_t
*)gbuf_rptr(tmp_m
)));
868 if (ddp
->hopcount
++ > 15) {
869 dPrintf(D_M_RTMP
, D_L_WARNING
,
870 ("routing_needed: drop packet for %d:%d, hopcount too high\n",
871 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
));
873 snmpStats
.dd_hopCount
++;
874 return; /* was return(1); */
877 if ((Entry
= rt_blookup(NET_VALUE(ddp
->dst_net
)))) {
879 dPrintf(D_M_RTMP_LOW
, D_L_ROUTING
,
880 ("routing_needed: FOUND for %d.%d p=%d to %d.%d \n",
881 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, ifID
->ifPort
,
882 Entry
->NextIRNet
, Entry
->NextIRNode
));
884 /* somehow, come to that point... */
886 /* if multihomed - need to set source address to the interface
887 * the packet is being sent from.
889 if (MULTIHOME_MODE
) {
890 NET_ASSIGN(ddp
->src_net
, ifID_table
[Entry
->NetPort
]->ifThisNode
.s_net
);
891 ddp
->src_node
= ifID_table
[Entry
->NetPort
]->ifThisNode
.s_node
;
894 ifID
->ifStatistics
.fwdPkts
++;
895 ifID
->ifStatistics
.fwdBytes
+= msgsize
;
897 if (Entry
->NetDist
) /* net not directly connected */
898 ddp_router_output(mp
, ifID_table
[Entry
->NetPort
], AT_ADDR
,
899 Entry
->NextIRNet
, Entry
->NextIRNode
, 0);
900 else {/* we are directly on this net */
902 /* we want to avoid duplicating broadcast packet on the same net,
903 * but special sockets handlers are ok to do that (mainly for
904 * for loopback purpose). So, if the "bypass" flag is set, we don't
905 * check for that test... [Problem was "movietalk"].
908 if (bypass
|| ifID_table
[Entry
->NetPort
] != ifID
)
909 ddp_router_output(mp
, ifID_table
[Entry
->NetPort
], AT_ADDR
,
910 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, 0);
912 dPrintf(D_M_RTMP
, D_L_ROUTING
,
913 ("routing_needed: bad loopback for add %d.%d from port %d (%d.%d)\n",
914 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, ifID
->ifPort
,
915 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
916 ifID
->ifStatistics
.droppedPkts
++;
917 ifID
->ifStatistics
.droppedBytes
+= msgsize
;
920 return; /* was return (2); */
927 dPrintf(D_M_RTMP
, D_L_ROUTING
,
928 ("routing_needed: NOT FOUND for add %d.%d from port %d our %d.%d\n",
929 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, ifID
->ifPort
,
930 ifID_home
->ifThisNode
.s_net
,
931 ifID_home
->ifThisNode
.s_node
));
933 ifID
->ifStatistics
.droppedPkts
++;
934 ifID
->ifStatistics
.droppedBytes
+= msgsize
;
935 snmpStats
.dd_noRoutes
++;
938 return; /* was return (2); */
942 } /* routing_needed */
944 ZT_entryno
*zt_getNextZone(first
)
946 /* a call made with first = TRUE returns the first valid entry in
947 the ZT_table, if first != TRUE, then then each call returns the
948 next valid entry in the table. The next call after the last
949 valid entry was read returns NULL
954 static ZT_entryno zte
;
962 for (i
=idx
; i
<ZT_maxentry
; i
++) {
963 if (ZT_table
[i
].ZoneCount
)
968 zte
.zt
= ZT_table
[i
];
976 RT_entry
*rt_getNextRoute(first
)
979 /* a call made with first = TRUE returns the first valid entry in
980 the RT_table, if first != TRUE, then then each call returns the
981 next valid entry in the table. The next call after the last
982 valid entry was read returns NULL
995 for (i
=idx
; i
<RT_maxentry
; i
++) {
996 if (RT_table
[i
].EntryState
!= RTE_STATE_UNUSED
)
1001 return(&RT_table
[i
]);
1011 register RT_entry
*rt
;
1014 if(!(at_state
.flags
&AT_ST_RT_CHANGED
))
1017 for (i
=RT_maxentry
,rt
= &RT_table
[RT_maxentry
-1]; i
; i
--,rt
--)
1018 if (rt
->EntryState
!= RTE_STATE_UNUSED
) {
1028 register ZT_entry
*zt
;
1031 if (!(at_state
.flags
& AT_ST_ZT_CHANGED
))
1034 for (i
=ZT_maxentry
,zt
= &ZT_table
[ZT_maxentry
-1]; i
; i
--,zt
--)
1035 if (zt
->ZoneCount
) {
1043 RT_entry
*d
; /* destination */
1044 int s
; /* starting entry */
1045 int c
; /* # entries to copy */
1048 register RT_entry
*rt
;
1050 for(i
=s
,rt
=&RT_table
[s
]; i
<RT_maxentry
&& n
<c
; rt
++,i
++)
1051 if (rt
->EntryState
!= RTE_STATE_UNUSED
) {
1058 ZT_entry
*d
; /* destination */
1059 int s
; /* starting entry */
1060 int c
; /* # entries to copy */
1063 bcopy(&ZT_table
[s
], d
, c
*sizeof(ZT_entry
));
1066 at_nvestr_t
*getRTRLocalZone(ifz
)
1072 int zcnt
=0; /* zone we're pointing to in the list */
1073 char zonesChecked
[ZT_BYTES
];
1076 if (ifz
->zone_index
< 0) {
1077 return((at_nvestr_t
*)NULL
);
1079 bzero(zonesChecked
,sizeof(zonesChecked
));
1080 TAILQ_FOREACH(ifID
, &at_ifQueueHd
, aa_link
) {
1081 if (!(route
= rt_blookup(ifID
->ifThisNode
.s_net
))) {
1082 return((at_nvestr_t
*)NULL
);
1084 zmap
=route
->ZoneBitMap
;
1085 dPrintf(D_M_RTMP_LOW
, D_L_USR1
,
1086 ("getRTRLocal: i/f %s, net:%d\n",ifID
->ifName
,
1087 ifID
->ifThisNode
.s_net
));
1088 for (i
= 0 ; i
< ZT_BYTES
; i
++) {
1090 for (j
= 0; j
< 8 ; j
++)
1091 if ( (zmap
[i
] & (0x80 >> j
)) &&
1092 !(zonesChecked
[i
] & (0x80 >> j
))
1094 zonesChecked
[i
] |= (0x80 >> j
);
1095 if (ifz
->zone_index
== zcnt
) {
1097 getIfUsage(index
, &ifz
->zone_iflist
);
1098 ifz
->zone_name
= ZT_table
[index
].Zone
;
1099 dPrintf(D_M_RTMP_LOW
, D_L_USR1
,
1100 ("getRTRLocal:zmap:%8x zcnt:%d\n",
1101 *(int*)zmap
, zcnt
));
1102 ifz
->zone_index
= index
+1;
1103 return(&ZT_table
[index
].Zone
);
1110 dPrintf(D_M_RTMP_LOW
, D_L_USR1
,
1111 ("getRTRLocal: returning NULL last ent:%d net:%d zmap:%08x\n",
1112 (ifID
? ifID
->ifPort
: 0),
1113 (ifID
? ifID
->ifThisNode
.s_net
: 0),*(int*)zmap
));
1114 ifz
->zone_name
.len
= 0;
1115 return((at_nvestr_t
*)NULL
);
1116 } /* getRTRLocalZone */
1118 void getIfUsage(zone
, ifs_in_zone
)
1120 at_ifnames_t
*ifs_in_zone
;
1122 /* sets the interface name in each element of the array for each I/F in the
1123 requested zone. The array has a 1:1 correspondence with the
1124 ifID_table. Zone is assumed to be valid and local, so if we're in
1125 single port mode, we'll set the home port and thats it.
1128 u_int zmi
; /* zone map index for zone */
1129 u_char zmb
; /* zone map bit mask for zone */
1134 if (!MULTIPORT_MODE
) {
1135 strncpy(ifs_in_zone
->at_if
[cnt
], ifID_home
->ifName
,
1139 bzero(ifs_in_zone
, sizeof(at_ifnames_t
));
1141 zmb
= 0x80>>(zone
% 8);
1142 dPrintf(D_M_NBP_LOW
, D_L_USR3
, ("get_ifs znum:%d zmi%d zmb:%x\n",
1144 TAILQ_FOREACH(ifID
, &at_ifQueueHd
, aa_link
) {
1145 if (!(route
= rt_blookup(ifID
->ifThisNode
.s_net
)))
1147 if (route
->ZoneBitMap
[zmi
] & zmb
) {
1148 dPrintf(D_M_NBP_LOW
, D_L_USR3
, ("zone in port %d \n",
1150 strncpy(ifs_in_zone
->at_if
[cnt
],
1151 ifID_table
[route
->NetPort
]->ifName
, IFNAMESIZ
);