]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/ddp_nbp.c
e8dc74b466f218585bf3108ef4861546aa1dede1
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@
23 * Copyright (c) 1988, 1989, 1997, 1998 Apple Computer, Inc.
25 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
30 #include <sys/errno.h>
31 #include <sys/types.h>
32 #include <sys/param.h>
33 #include <machine/spl.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
37 #include <sys/filedesc.h>
38 #include <sys/fcntl.h>
40 #include <sys/ioctl.h>
41 #include <sys/malloc.h>
42 #include <sys/socket.h>
43 #include <sys/socketvar.h>
46 #include <net/if_types.h>
48 #include <netat/sysglue.h>
49 #include <netat/appletalk.h>
50 #include <netat/at_var.h>
51 #include <netat/ddp.h>
52 #include <netat/nbp.h>
53 #include <netat/zip.h>
54 #include <netat/rtmp.h>
55 #include <netat/routing_tables.h> /* router */
56 #include <netat/at_snmp.h>
57 #include <netat/at_pcb.h>
58 #include <netat/debug.h>
60 /* reaching for DDP and NBP headers in the datagram */
61 #define DATA_DDP(mp) ((at_ddp_t *)(gbuf_rptr(mp)))
62 #define DATA_NBP(mp) ((at_nbp_t *)((DATA_DDP(mp))->data))
64 /* Get to the nve_entry_t part ofthe buffer */
65 #define NVE_ENTRY(mp) (nve_entry_t *)(gbuf_rptr(mp))
68 #define MIN(a,b) ((a)>(b)?(b):(a))
71 #define errno nbperrno
75 extern at_ifaddr_t
*ifID_table
[];
76 extern at_ifaddr_t
*ifID_home
;
78 TAILQ_HEAD(name_registry
, _nve_
) name_registry
;
84 static gbuf_t
*lzones
=0; /* head of local zones list */
85 static int lzonecnt
=0; /* # zones stored in lzones */
86 static u_int hzonehash
=0; /* hash val of home zone */
87 static int nve_lock_pri
;
89 static int nbp_lkup_reply(nbp_req_t
*, nve_entry_t
*);
90 static int nbp_strcmp(at_nvestr_t
*, at_nvestr_t
*, u_char
);
91 static int nbp_setup_resp(nbp_req_t
*, int);
92 static int nbp_send_resp(nbp_req_t
*);
93 static int nbp_validate_n_hash(nbp_req_t
*, int, int);
94 static nve_entry_t
*nbp_search_nve();
95 static int isZoneLocal(at_nvestr_t
*);
98 #define NVE_LOCK nve_lock
101 void nbp_delete_entry();
102 extern int at_reg_mcast();
103 extern at_nvestr_t
*getRTRLocalZone(zone_usage_t
*);
104 extern void nbp_add_multicast( at_nvestr_t
*, at_ifaddr_t
*);
106 static long nbp_id_count
= 0;
108 void sethzonehash(elapp
)
111 if (elapp
->startup_zone
.len
) {
112 hzonehash
= nbp_strhash(&elapp
->startup_zone
);
118 /* delete all NVE's and release buffers */
119 register nve_entry_t
*nve_entry
, *nve_next
;
121 ATDISABLE(nve_lock_pri
,NVE_LOCK
);
122 for ((nve_entry
= TAILQ_FIRST(&name_registry
)); nve_entry
; nve_entry
= nve_next
) {
123 nve_next
= TAILQ_NEXT(nve_entry
, nve_link
);
125 /* NB: nbp_delete_entry calls TAILQ_REMOVE */
126 nbp_delete_entry(nve_entry
);
128 ATENABLE(nve_lock_pri
,NVE_LOCK
);
138 u_char
*nbp2zone(nbp
, maxp
)
145 p
= (u_char
*)&nbp
->tuple
[0].enu_entity
; /* p -> object */
146 if (p
>= maxp
) return NULL
;
147 p
+= (*p
+1); /* p -> type */
148 if (p
>= maxp
) return NULL
;
149 p
+= (*p
+1); /* p -> zone */
150 if (p
>= maxp
) return NULL
;
151 if ((p
+ *p
) >= maxp
) return NULL
;
155 void nbp_input(m
, ifID
)
157 register at_ifaddr_t
*ifID
;
160 register at_ddp_t
*ddp
= DATA_DDP(m
);
161 register at_nbp_t
*nbp
= DATA_NBP(m
);
162 register nve_entry_t
*nve_entry
, *next_nve
;
163 register RT_entry
*rt
;
164 register int ddpSent
= FALSE
; /* true if we re-sent this pkt (don't free) */
165 struct etalk_addr mcastAddr
;
169 /* from original nbp_input() when this function was nbp_handler() */
170 if ((gbuf_type(m
) != MT_DATA
&& gbuf_type(m
) != MSG_DATA
) ||
171 ddp
->type
!= DDP_NBP
) {
176 /* Some initializations */
177 nbp_req
.response
= NULL
;
179 nbp_req
.space_unused
= nbp_req
.flags
= 0;
181 dPrintf(D_M_NBP_LOW
, D_L_USR1
,
182 ("nbp_input control:%d tuplecount:%d id:%d\n",
183 nbp
->control
, nbp
->tuple_count
, nbp
->at_nbp_id
));
184 switch (nbp
->control
) {
189 dst_net
= NET_VALUE(ddp
->dst_net
);
190 dPrintf(D_M_NBP_LOW
, D_L_USR2
, (" LKUP %s\n",
191 ifID
!= ifID_home
? "non-home" : "home"));
192 if ( ROUTING_MODE
&& (NET_VALUE(ddp
->dst_net
) != 0)
193 && ((dst_net
< ifID
->ifThisCableStart
)
194 || (dst_net
> ifID
->ifThisCableEnd
)) ) {
195 routing_needed(m
, ifID
, TRUE
);
201 if (nbp_validate_n_hash (&nbp_req
, TRUE
, FALSE
) == 0) {
202 nbp_req
.func
= nbp_lkup_reply
;
203 (void) nbp_search_nve(&nbp_req
, ifID
);
204 if (nbp_req
.response
) {
205 nbp_send_resp(&nbp_req
);
210 char zone
[35],object
[35],type
[35];
211 strncpy(zone
,nbp_req
.nve
.zone
.str
, nbp_req
.nve
.zone
.len
);
212 strncpy(object
,nbp_req
.nve
.object
.str
, nbp_req
.nve
.object
.len
);
213 strncpy(type
,nbp_req
.nve
.type
.str
, nbp_req
.nve
.type
.len
);
214 object
[nbp_req
.nve
.object
.len
] = '\0';
215 zone
[nbp_req
.nve
.zone
.len
] = '\0';
216 type
[nbp_req
.nve
.type
.len
] = '\0';
217 if (ifID
!= ifID_home
)
218 dPrintf(D_M_NBP_LOW
,D_L_USR2
,
219 ("nbp_LKUP for:%s:%s@%s", object
, type
, zone
));
221 #endif /* NBP_DEBUG */
226 register int zhome
=0;
227 /* true if home zone == destination zone */
230 register error_found
=0;
231 register at_ifaddr_t
*ifIDorig
;
233 if (!ROUTING_MODE
) /* for routers only! */
238 for (i
= 0 ; i
< RT_maxentry
; i
++) {
240 if ((rt
->EntryState
& RTE_STATE_PERMANENT
) &&
241 NET_VALUE(ddp
->dst_net
) >= rt
->NetStart
&&
242 NET_VALUE(ddp
->dst_net
) <= rt
->NetStop
245 if (rt
->NetPort
>= IF_TOTAL_MAX
) {
246 dPrintf(D_M_NBP
,D_L_ERROR
,
247 ("nbp_input:FWDREQ: bad port# from RT_table\n"));
251 ifID
= ifID_table
[rt
->NetPort
];
253 dPrintf(D_M_NBP
,D_L_ERROR
,
254 ("nbp_input:FWDREQ: ifID %s\n",
255 !ifID
? "not found" : "invalid"));
259 if (ifID
->ifState
== LAP_OFFLINE
) {
260 dPrintf(D_M_NBP
,D_L_ERROR
,
261 ("nbp_input:FWDREQ: ifID offline (port %d)\n",
269 if (error_found
) /* the port is not correct */
272 if (!ifID
) { /* this packet is not for us, let the routing engine handle it */
273 routing_needed(m
, ifIDorig
, TRUE
);
279 * At this point, we have a valid Forward request for one of our
280 * directly connected port. Convert it to a NBP Lookup
283 nbp
->control
= NBP_LKUP
;
284 NET_ASSIGN(ddp
->dst_net
, 0);
288 /*### LD 01/18/94 Check if the dest is also the home zone. */
290 p
= nbp2zone(nbp
, gbuf_wptr(m
));
291 if ((p
== NULL
) || !(zno
= zt_find_zname(p
))) {
292 dPrintf(D_M_NBP
,D_L_WARNING
,
293 ("nbp_input: FWDRQ:zone not found\n"));
296 if (isZoneLocal((at_nvestr_t
*)p
))
297 zhome
= TRUE
; /* one of our ports is in destination zone */
298 if (!zt_get_zmcast(ifID
, p
, &mcastAddr
)) {
299 dPrintf(D_M_NBP
,D_L_ERROR
,
300 ("nbp_input: FDWREQ:zt_get_zmcast error\n"));
305 if (zhome
) { /*### LD 01/18/95 In case our home is here, call back nbp */
307 if (!(m2
= (gbuf_t
*)gbuf_copym((gbuf_t
*)m
))) {
308 dPrintf(D_M_NBP
,D_L_ERROR
,
309 ("nbp_input: FWDRQ:gbuf_copym failed\n"));
315 nbp
->control
= NBP_LKUP
;
316 NET_ASSIGN(ddp
->dst_net
, 0);
318 dPrintf(D_M_NBP
,D_L_INFO
,
319 ("nbp_input: FWDRQ:loop back for us\n"));
320 nbp_input(m2
, ifID_home
);
323 if (FDDI_OR_TOKENRING(ifID
->aa_ifp
->if_type
))
324 ddp_bit_reverse(&mcastAddr
);
325 ddp_router_output(m
, ifID
, ET_ADDR
,NULL
,NULL
, &mcastAddr
);
332 register int zno
; /* zone table entry numb */
333 register int ztind
; /* zone bitmap index into RT_entry */
334 register int ztbit
; /* zone bit to check within above index */
335 register int zhome
=0; /* true if home zone == destination zone */
337 register gbuf_t
*m2
, *m3
;
338 register int fromUs
= FALSE
;
339 register at_socket ourSkt
; /* originating skt */
341 /* for router & MH local only */
342 if ((!(MULTIHOME_MODE
&& FROM_US(ddp
))) && !ROUTING_MODE
) {
343 dPrintf(D_M_NBP
,D_L_USR2
,
344 ("nbp_input: BRREQ:non router or MH local\n"));
348 p
= nbp2zone(nbp
, gbuf_wptr(m
));
349 if ((p
== NULL
) || !(zno
= zt_find_zname(p
))) {
352 if (MULTIHOME_MODE
&& ifID
->ifRouterState
== NO_ROUTER
) {
353 ((at_nvestr_t
*)p
)->len
= 1;
354 ((at_nvestr_t
*)p
)->str
[0] = '*';
356 if (isZoneLocal((at_nvestr_t
*)p
)) {
357 zhome
= TRUE
; /* one of our ports is in destination zone */
359 if (FROM_US(ddp
)){ /* save, before we munge it */
361 ourSkt
= ddp
->src_socket
;
362 dPrintf(D_M_NBP
,D_L_USR2
,
363 ("nbp_input:BRRQ from us net:%d\n",
364 (int)NET_VALUE(ddp
->src_net
)));
366 /* from ZT_CLR_ZMAP */
369 ztbit
= 0x80 >> (i
% 8);
370 for (i
=0,rt
=RT_table
; i
<RT_maxentry
; i
++,rt
++) {
371 if (!(rt
->ZoneBitMap
[ztind
] & ztbit
)) /* if zone not in route, skip*/
373 /* dPrintf(D_M_NBP, D_L_USR3,
374 ("nbp_input: BRREQ: port:%d, entry %d\n",
378 ifID
= ifID_table
[rt
->NetPort
];
380 dPrintf(D_M_NBP
, D_L_ERROR
,
381 ("nbp_input:BRRQ: ifID %s\n",
382 !ifID
? "not found" : "invalid"));
387 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
388 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
389 ddp
->src_socket
= NBP_SOCKET
;
390 if (!(m2
= (gbuf_t
*)gbuf_copym((gbuf_t
*)m
))) {
391 dPrintf(D_M_NBP
,D_L_ERROR
,
392 ("nbp_input: BRREQ:gbuf_copym failed\n"));
398 /* nbp->tuple[0].enu_addr.socket = NBP_SOCKET; */
399 if (MULTIHOME_MODE
&& fromUs
) {
400 /* set the return address of the lookup to that of the
401 interface it's going out on so that replies come back
403 dPrintf(D_M_NBP
,D_L_USR3
,
404 ("nbp_input: BRREQ: src changed to %d.%d.%d\n",
405 ifID
->ifThisNode
.s_net
,
406 ifID
->ifThisNode
.s_node
, ourSkt
));
407 nbp
->tuple
[0].enu_addr
.net
= ifID
->ifThisNode
.s_net
;
408 nbp
->tuple
[0].enu_addr
.node
= ifID
->ifThisNode
.s_node
;
409 nbp
->tuple
[0].enu_addr
.socket
= ourSkt
;
410 ddp
->src_socket
= NBP_SOCKET
;
413 dPrintf(D_M_NBP
, D_L_USR3
,
414 ("nbp_input: BRREQ: not from us\n"));
416 dPrintf(D_M_NBP
, D_L_USR3
,
417 ("nbp_input dist:%d\n", rt
->NetDist
));
418 if (rt
->NetDist
== 0) { /* if direct connect, *we* do the LKUP */
419 nbp
->control
= NBP_LKUP
;
420 NET_ASSIGN(ddp
->dst_net
, 0);
422 if (!zt_get_zmcast(ifID
, p
, &mcastAddr
)) {
423 dPrintf(D_M_NBP
,D_L_ERROR
,
424 ("nbp_input: BRRQ:zt_get_zmcast error\n"));
427 if (FDDI_OR_TOKENRING(ifID
->aa_ifp
->if_type
))
428 ddp_bit_reverse(&mcastAddr
);
429 ddp_router_output(m2
, ifID
, ET_ADDR
, NULL
, NULL
, &mcastAddr
);
431 else { /* else fwd to router */
433 if (rt
->NetStart
== 0) /* if Ltalk */
434 NET_ASSIGN(ddp
->dst_net
, rt
->NetStop
);
436 NET_ASSIGN(ddp
->dst_net
, rt
->NetStart
);
437 nbp
->control
= NBP_FWDRQ
;
438 ddp_router_output(m2
, ifID
, AT_ADDR
,
439 rt
->NextIRNet
, rt
->NextIRNode
,
446 if (!(m3
= (gbuf_t
*)gbuf_copym((gbuf_t
*)m
))) {
447 dPrintf(D_M_NBP
,D_L_ERROR
,
448 ("nbp_input: BRREQ:gbuf_copym failed\n"));
455 nbp
->control
= NBP_LKUP
;
456 NET_ASSIGN(ddp
->dst_net
, 0);
458 dPrintf(D_M_NBP
,D_L_INFO
, ("nbp_input: BRRQ:loop back for us\n"));
459 nbp_input(m3
, ifID_home
);
465 if (!ROUTING_MODE
) /* for routers only! */
468 dPrintf(D_M_NBP
,D_L_WARNING
,
469 ("nbp_input: routing needed for LKUP_REPLY: from %d.%d\n",
470 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
471 routing_needed(m
, ifID
, TRUE
);
476 dPrintf(D_M_NBP
,D_L_ERROR
,
477 ("nbp_input: unhandled pkt: type:%d\n", nbp
->control
));
479 routing_needed(m
, ifID
, TRUE
);
482 } /* switch control */
489 static int nbp_validate_n_hash (nbp_req
, wild_ok
, checkLocal
)
490 register nbp_req_t
*nbp_req
;
491 register int wild_ok
;
492 register int checkLocal
; /* if true check if local zone */
494 register at_nvestr_t
*object
, *type
, *zone
;
495 at_nbptuple_t
*tuple
;
496 register int i
, part_wild
;
498 tuple
= DATA_NBP(nbp_req
->request
)->tuple
;
503 net
= tuple
->enu_addr
.net
;
504 node
= tuple
->enu_addr
.node
;
505 skt
= tuple
->enu_addr
.socket
;
506 dPrintf(D_M_NBP_LOW
,D_L_USR4
,
507 ("nbp_validate: tuple addr:%d:%d:%d\n",net
,node
,skt
));
509 #endif /* COMMENTED_OUT */
511 /* tuple is in the compressed (no "filler") format */
512 object
= (at_nvestr_t
*)&tuple
->enu_entity
;
513 type
= (at_nvestr_t
*)(&object
->str
[object
->len
]);
514 zone
= (at_nvestr_t
*)(&type
->str
[type
->len
]);
516 if (object
->len
> NBP_NVE_STR_SIZE
|| type
->len
> NBP_NVE_STR_SIZE
||
517 zone
->len
> NBP_NVE_STR_SIZE
) {
518 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
519 ("nbp_val_n_hash: bad str len\n"));
526 char xzone
[35],xobject
[35],xtype
[35];
527 strncpy(xzone
,zone
->str
, zone
->len
);
528 strncpy(xobject
,object
->str
, object
->len
);
529 strncpy(xtype
,type
->str
, type
->len
);
530 xobject
[object
->len
] = '\0';
531 xzone
[zone
->len
] = '\0';
532 xtype
[type
->len
] = '\0';
533 dPrintf(D_M_NBP_LOW
, D_L_USR4
,
534 ("nbp_validate: looking for %s:%s@%s\n",
535 xobject
, xtype
, xzone
));
537 #endif /* NBP_DEBUG */
538 /* Is this request for our zone ?? */
539 nbp_req
->nve
.zone
.len
= zone
->len
;
540 nbp_req
->nve
.zone_hash
= 0;
541 bcopy(zone
->str
,nbp_req
->nve
.zone
.str
, zone
->len
);
543 if (checkLocal
&& !isZoneLocal(zone
)) {
545 strncpy(str
,zone
->str
,zone
->len
);
546 str
[zone
->len
] = '\0';
547 dPrintf(D_M_NBP_LOW
,D_L_WARNING
,
548 ("nbp_val_n_hash bad zone: %s\n", str
));
553 if (!DEFAULT_ZONE(zone
)) {
554 nbp_req
->nve
.zone_hash
= nbp_strhash(& nbp_req
->nve
.zone
);
557 nbp_req
->nve
.address
= tuple
->enu_addr
;
558 nbp_req
->nve
.object
.len
= object
->len
;
559 nbp_req
->nve
.object_hash
= 0;
560 if (object
->len
== 1 && (object
->str
[0] == NBP_ORD_WILDCARD
||
561 object
->str
[0] == NBP_SPL_WILDCARD
)) {
563 nbp_req
->flags
|= NBP_WILD_OBJECT
;
565 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
566 ("nbp_val_n_hash: wild not okay\n"));
571 for (i
= part_wild
= 0; (unsigned) i
<object
->len
; i
++) {
572 if (object
->str
[i
] == NBP_SPL_WILDCARD
)
575 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
576 ("nbp_val_n_hash: too many parts wild\n"));
582 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
583 ("nbp_val_n_hash: wild not okay2\n"));
587 nbp_req
->nve
.object
.str
[i
] = object
->str
[i
];
590 nbp_req
->nve
.object_hash
=
591 nbp_strhash(&nbp_req
->nve
.object
);
594 nbp_req
->nve
.type
.len
= type
->len
;
595 nbp_req
->nve
.type_hash
= 0;
596 if (type
->len
== 1 && (type
->str
[0] == NBP_ORD_WILDCARD
||
597 type
->str
[0] == NBP_SPL_WILDCARD
)) {
599 nbp_req
->flags
|= NBP_WILD_TYPE
;
601 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
602 ("nbp_val_n_hash: wild not okay3\n"));
607 for (i
= part_wild
= 0; (unsigned) i
<type
->len
; i
++) {
608 if (type
->str
[i
] == NBP_SPL_WILDCARD
)
611 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
612 ("nbp_val_n_hash: too many parts wild2\n"));
621 nbp_req
->nve
.type
.str
[i
] = type
->str
[i
];
624 nbp_req
->nve
.type_hash
=
625 nbp_strhash(&nbp_req
->nve
.type
);
629 char zone
[35],object
[35],type
[35];
630 strncpy(zone
,nbp_req
->nve
.zone
.str
, nbp_req
->nve
.zone
.len
);
631 strncpy(object
,nbp_req
->nve
.object
.str
, nbp_req
->nve
.object
.len
);
632 strncpy(type
,nbp_req
->nve
.type
.str
, nbp_req
->nve
.type
.len
);
633 object
[nbp_req
->nve
.object
.len
] = '\0';
634 zone
[nbp_req
->nve
.zone
.len
] = '\0';
635 type
[nbp_req
->nve
.type
.len
] = '\0';
636 dPrintf(D_M_NBP_LOW
,D_L_USR4
,
637 ("nbp_validate: after hash: %s:%s@%s\n",
638 object
, type
, zone
));
640 #endif /* NBP_DEBUG */
642 } /* nbp_validate_n_hash */
645 /* Upshifts in place */
646 static void nbp_upshift (str
, count
)
647 register u_char
*str
;
652 static unsigned char lower_case
[] =
653 {0x8a, 0x8c, 0x8d, 0x8e, 0x96, 0x9a, 0x9f, 0xbe,
654 0xbf, 0xcf, 0x9b, 0x8b, 0x88, 0};
655 static unsigned char upper_case
[] =
656 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0xae,
657 0xaf, 0xce, 0xcd, 0xcc, 0xcb, 0};
659 for (j
=0 ; j
<count
; j
++) {
661 if (ch
>= 'a' && ch
<= 'z')
662 str
[j
] = ch
+ 'A' - 'a';
664 for (i
=0; lower_case
[i
]; i
++)
665 if (ch
== lower_case
[i
])
666 str
[j
] = upper_case
[i
];
671 u_int
nbp_strhash (nvestr
)
672 register at_nvestr_t
*nvestr
;
674 /* upshift while hashing */
675 register u_int hash
= 0;
682 for (i
=0; (unsigned) i
< nvestr
->len
; i
+=sizeof(int)) {
683 len
= MIN((nvestr
->len
-i
), sizeof(int));
684 if (len
== sizeof(int))
685 bcopy(&(nvestr
->str
[i
]), &un
, sizeof(un
));
688 for ( ; (unsigned) i
<nvestr
->len
; i
++)
689 un
.h_4char
[i
% sizeof(int)] = nvestr
->str
[i
];
691 nbp_upshift (un
.h_4char
, len
);
698 static nve_entry_t
*nbp_search_nve (nbp_req
, ifID
)
699 register nbp_req_t
*nbp_req
;
700 register at_ifaddr_t
*ifID
; /* NULL ok */
702 register nve_entry_t
*nve_entry
;
706 char zone
[35],object
[35],type
[35];
707 strncpy(zone
,nbp_req
->nve
.zone
.str
, nbp_req
->nve
.zone
.len
);
708 strncpy(object
,nbp_req
->nve
.object
.str
, nbp_req
->nve
.object
.len
);
709 strncpy(type
,nbp_req
->nve
.type
.str
, nbp_req
->nve
.type
.len
);
710 object
[nbp_req
->nve
.object
.len
] = '\0';
711 zone
[nbp_req
->nve
.zone
.len
] = '\0';
712 type
[nbp_req
->nve
.type
.len
] = '\0';
713 dPrintf(D_M_NBP_LOW
, D_L_USR4
,
714 ("nbp_search: looking for %s:%s@%s resp:0x%x\n",object
,type
,zone
,
715 (u_int
) nbp_req
->response
));
717 #endif /* NBP_DEBUG */
718 ATDISABLE(nve_lock_pri
,NVE_LOCK
);
719 TAILQ_FOREACH(nve_entry
, &name_registry
, nve_link
) {
720 if ((nbp_req
->nve
.zone_hash
) &&
721 ((nbp_req
->nve
.zone_hash
!=
722 nve_entry
->zone_hash
) &&
723 (nbp_req
->nve
.zone_hash
!= hzonehash
)
726 dPrintf(D_M_NBP_LOW
,D_L_USR4
,
727 ("nbp_search: no match for zone, req hash:%x\n",
728 nbp_req
->nve
.zone_hash
));
731 else { /* for this entry's zone OR no zone in request or entry */
732 /* only in singleport mode (!MULTIPORT_MODE) with
733 empty PRAM can an entry have '*' for it's zone
735 at_nvestr_t
*ezone
=&nve_entry
->zone
;
736 at_nvestr_t
*rzone
=&nbp_req
->nve
.zone
;
737 if (!DEFAULT_ZONE(rzone
) && !DEFAULT_ZONE(ezone
)) {
738 if (nbp_strcmp (rzone
, ezone
, 0) != 0)
742 if (MULTIHOME_MODE
&& ifID
&&
743 (nve_entry
->address
.net
!=
744 ifID
->ifThisNode
.s_net
)) {
745 dPrintf(D_M_NBP
, D_L_USR4
,
746 ("nbp search ifID (%d) & req net (%d) not eq\n",
747 nve_entry
->address
.net
,
748 ifID
->ifThisNode
.s_net
));
752 dPrintf(D_M_NBP
, D_L_USR4
,
753 ("nbp search ifID (%d) & req net (%d) equal\n",
754 nve_entry
->address
.net
,
755 ifID
->ifThisNode
.s_net
));
759 if (!(nbp_req
->flags
& NBP_WILD_OBJECT
)) {
760 if ((nbp_req
->nve
.object_hash
) &&
761 (nbp_req
->nve
.object_hash
!=
762 nve_entry
->object_hash
))
765 if (nbp_strcmp (&nbp_req
->nve
.object
,
767 NBP_SPL_WILDCARD
) != 0)
773 if (!(nbp_req
->flags
& NBP_WILD_TYPE
)) {
774 if ((nbp_req
->nve
.type_hash
) &&
775 (nbp_req
->nve
.type_hash
!=nve_entry
->type_hash
))
778 if (nbp_strcmp (&nbp_req
->nve
.type
,
780 NBP_SPL_WILDCARD
) != 0)
788 char zone
[35],object
[35],type
[35];
790 strncpy(zone
,nbp_req
->nve
.zone
.str
, nbp_req
->nve
.zone
.len
);
791 strncpy(object
,nbp_req
->nve
.object
.str
, nbp_req
->nve
.object
.len
);
792 strncpy(type
,nbp_req
->nve
.type
.str
, nbp_req
->nve
.type
.len
);
793 object
[nbp_req
->nve
.object
.len
] = '\0';
794 zone
[nbp_req
->nve
.zone
.len
] = '\0';
795 type
[nbp_req
->nve
.type
.len
] = '\0';
796 dPrintf(D_M_NBP_LOW
, D_L_USR2
,
797 ("nbp_search: found %s:%s@%s net:%d\n",
798 object
, type
, zone
, (int)nve_entry
->address
.net
));
800 #endif /* NBP_DEBUG */
801 if (nbp_req
->func
!= NULL
) {
802 if ((*(nbp_req
->func
))(nbp_req
, nve_entry
) != 0) {
803 /* errno expected to be set by func */
804 ATENABLE(nve_lock_pri
,NVE_LOCK
);
808 ATENABLE(nve_lock_pri
,NVE_LOCK
);
812 ATENABLE(nve_lock_pri
,NVE_LOCK
);
816 } /* nbp_search_nve */
818 static int nbp_lkup_reply (nbp_req
, nve_entry
)
819 register nbp_req_t
*nbp_req
;
820 register nve_entry_t
*nve_entry
;
822 register at_nbptuple_t
*tuple
;
823 register int tuple_size
, buf_len
;
824 register int obj_len
, type_len
;
827 /* size of the current tuple we want to write... */
828 tuple_size
= nve_entry
->object
.len
+ 1 + /* object */
829 nve_entry
->type
.len
+ 1 + /* type */
831 sizeof (at_inet_t
) + 1; /* addr + enum */
833 buf_len
= ((nbp_req
->flags
& NBP_WILD_MASK
) ? DDP_DATA_SIZE
:tuple_size
);
834 if (nbp_req
->response
== NULL
) {
835 if (nbp_setup_resp (nbp_req
, buf_len
) != 0)
836 /* errno expected to be set by nbp_setup_resp() */
840 if ((nbp_req
->space_unused
< tuple_size
) ||
841 (DATA_NBP(nbp_req
->response
)->tuple_count
== NBP_TUPLE_MAX
)) {
842 if (nbp_send_resp (nbp_req
) != 0)
844 if (nbp_setup_resp (nbp_req
, buf_len
) != 0)
848 /* At this point, we have a response buffer that can accommodate the
849 * tuple we want to write. Write it!
851 tuple
= (at_nbptuple_t
*)gbuf_wptr(nbp_req
->response
);
852 tuple
->enu_addr
= nve_entry
->address
;
853 tuple
->enu_enum
= nve_entry
->enumerator
;
855 /* tuple is in the compressed (no "filler") format */
856 p
= (u_char
*)&tuple
->enu_entity
.object
;
857 obj_len
= nve_entry
->object
.len
+ 1;
858 bcopy(&nve_entry
->object
, p
, obj_len
);
860 type_len
= nve_entry
->type
.len
+ 1;
861 bcopy(&nve_entry
->type
, p
, type_len
);
866 nbp_req
->space_unused
-= tuple_size
;
867 gbuf_winc(nbp_req
->response
, tuple_size
);
869 /* increment the tuple count in header by 1 */
870 DATA_NBP(nbp_req
->response
)->tuple_count
++;
876 static int nbp_strcmp (str1
, str2
, embedded_wildcard
)
877 register at_nvestr_t
*str1
, *str2
;
878 register u_char embedded_wildcard
; /* If str1 may contain a character
879 * that's to be treated as an
880 * embedded wildcard, this character
881 * is it. Making this special case
882 * since for zone names, squiggly
883 * equal is not to be treated as a
889 register int reverse
= 0;
890 register int left_index
;
892 /* Embedded wildcard, if any, could only be in the first string (str1).
893 * returns 0 if two strings are equal (modulo case), -1 otherwise
896 if (str1
->len
== 0 || str2
->len
== 0) {
900 /* Wildcards are not allowed in str2.
902 * If str1 could potentially contain an embedded wildcard, since the
903 * embedded wildcard matches ZERO OR MORE characters, str1 can not be
904 * more than 1 character longer than str2.
906 * If str1 is not supposed to have embedded wildcards, the two strs
907 * must be of equal length.
909 if ((embedded_wildcard
&& (str2
->len
< (unsigned) (str1
->len
-1))) ||
910 (!embedded_wildcard
&& (str2
->len
!= str1
->len
))) {
914 for (i1
= i2
= left_index
= 0; (unsigned) i1
< str1
->len
;) {
918 if (embedded_wildcard
&& (ch1
==embedded_wildcard
)) {
919 /* hit the embedded wild card... start comparing from
920 * the other end of the string.
923 /* But, if embedded wildcard was the last character of
924 * the string, the two strings match, so return okay.
926 if (i1
== str1
->len
-1) {
936 nbp_upshift(&ch1
, 1);
937 nbp_upshift(&ch2
, 1);
945 if (i1
== left_index
) {
949 i1
++; i2
++; left_index
++;
956 static void nbp_setup_hdr (nbp_req
)
957 register nbp_req_t
*nbp_req
;
959 register at_ddp_t
*ddp
;
960 register at_nbp_t
*nbp
;
962 ddp
= DATA_DDP(nbp_req
->response
);
963 nbp
= DATA_NBP(nbp_req
->response
);
966 UAS_ASSIGN(ddp
->checksum
, 0);
967 ddp
->unused
= ddp
->hopcount
= 0;
969 switch(DATA_NBP(nbp_req
->request
)->control
) {
971 ddp
->dst_socket
= nbp_req
->nve
.address
.socket
;
972 ddp
->dst_node
= nbp_req
->nve
.address
.node
;
973 NET_ASSIGN(ddp
->dst_net
, nbp_req
->nve
.address
.net
);
974 nbp
->control
= NBP_LKUP_REPLY
;
977 nbp
->at_nbp_id
= DATA_NBP(nbp_req
->request
)->at_nbp_id
;
982 static int nbp_setup_resp (nbp_req
, tuples_size
)
983 register nbp_req_t
*nbp_req
;
984 register int tuples_size
;
986 int buf_size
= tuples_size
+ DDP_X_HDR_SIZE
+ NBP_HDR_SIZE
;
987 nbp_req
->response
= gbuf_alloc(AT_WR_OFFSET
+buf_size
, PRI_MED
);
988 if (nbp_req
->response
== NULL
) {
992 gbuf_rinc(nbp_req
->response
, AT_WR_OFFSET
);
993 gbuf_wset(nbp_req
->response
, DDP_X_HDR_SIZE
+ NBP_HDR_SIZE
);
994 nbp_setup_hdr(nbp_req
);
996 DATA_NBP(nbp_req
->response
)->tuple_count
= 0;
997 nbp_req
->space_unused
= tuples_size
;
1000 } /* nbp_setup_resp */
1003 static int nbp_send_resp (nbp_req
)
1004 register nbp_req_t
*nbp_req
;
1008 status
= ddp_output(&nbp_req
->response
, (at_socket
)NBP_SOCKET
, FALSE
);
1009 nbp_req
->response
= NULL
;
1014 void nbp_add_multicast(zone
, ifID
)
1018 char data
[ETHERNET_ADDR_LEN
];
1021 if (zone
->str
[0] == '*')
1026 strncpy(str
,zone
->str
,zone
->len
);
1027 str
[zone
->len
] = '\0';
1028 dPrintf(D_M_NBP_LOW
, D_L_USR3
,
1029 ("nbp_add_multi getting mc for %s\n", str
));
1031 zt_get_zmcast(ifID
, zone
, data
);
1032 if (FDDI_OR_TOKENRING(ifID
->aa_ifp
->if_type
))
1033 ddp_bit_reverse(data
);
1034 dPrintf(D_M_NBP_LOW
,D_L_USR3
,
1035 ("nbp_add_multi adding 0x%x%x port:%d ifID:0x%x if:%s\n",
1036 *(unsigned*)data
, (*(unsigned *)(data
+2))&0x0000ffff,
1037 i
, (u_int
) ifID
, ifID
->ifName
));
1039 bcopy((caddr_t
)data
, (caddr_t
)&ifID
->ZoneMcastAddr
, ETHERNET_ADDR_LEN
);
1040 (void)at_reg_mcast(ifID
, (caddr_t
)&ifID
->ZoneMcastAddr
);
1046 /* for SNMP, returns size in # of entries */
1048 register nve_entry_t
*nve
;
1051 ATDISABLE(nve_lock_pri
,NVE_LOCK
);
1052 for (nve
= TAILQ_FIRST(&name_registry
); nve
; nve
= TAILQ_NEXT(nve
, nve_link
), i
++)
1054 ATENABLE(nve_lock_pri
,NVE_LOCK
);
1058 getNbpTable(p
, s
, c
)
1060 int s
; /* starting entry */
1061 int c
; /* # entries to copy */
1063 /* for SNMP, returns section of nbp table */
1065 register nve_entry_t
*nve
;
1067 static int nextNo
=0; /* entry that *next points to */
1068 static nve_entry_t
*next
= (nve_entry_t
*)NULL
;
1070 if (s
&& next
&& nextNo
== s
) {
1075 nve
= TAILQ_FIRST(&name_registry
);
1077 ATDISABLE(nve_lock_pri
,NVE_LOCK
);
1078 for ( ; nve
&& c
; nve
= TAILQ_NEXT(nve
, nve_link
), p
++,i
++) {
1080 p
->nbpe_object
= nve
->object
;
1081 p
->nbpe_type
= nve
->type
;
1085 ATENABLE(nve_lock_pri
,NVE_LOCK
);
1090 next
= (nve_entry_t
*)NULL
;
1096 #define ZONES_PER_BLK 31 /* 31 fits within a 1k blk) */
1097 #define ZONE_BLK_SIZE ZONES_PER_BLK * sizeof(at_nvestr_t)
1099 int setLocalZones(newzones
, size
)
1100 at_nvestr_t
*newzones
;
1102 /* updates list of zones which are local to all active ports
1103 missing zones are not deleted, only missing zones are added.
1106 int bytesread
=0; /* #bytes read from tuple */
1109 at_nvestr_t
*pnve
, *pnew
= newzones
;
1112 if(!(lzones
= gbuf_alloc(ZONE_BLK_SIZE
, PRI_MED
)))
1114 gbuf_wset(lzones
,0);
1116 while (bytesread
< size
) { /* for each new zone */
1119 strncpy(str
,pnew
->str
,pnew
->len
);
1120 str
[pnew
->len
] = '\0';
1123 pnve
= (at_nvestr_t
*)gbuf_rptr(m
);
1125 for (i
=0; i
<lzonecnt
&& !dupe
; i
++,pnve
++) {
1126 if (i
&& !(i%ZONES_PER_BLK
))
1129 pnve
= (at_nvestr_t
*)gbuf_rptr(m
);
1133 if (pnew
->len
!= pnve
->len
)
1135 if (pnew
->len
> NBP_NVE_STR_SIZE
) {
1138 if (!strncmp(pnew
->str
, pnve
->str
, pnew
->len
)) {
1145 if (lzonecnt
&& !(lzonecnt%ZONES_PER_BLK
)) {
1146 if(!(gbuf_cont(m
) = gbuf_alloc(ZONE_BLK_SIZE
, PRI_MED
)))
1148 gbuf_wset(gbuf_cont(m
),0);
1149 pnve
= (at_nvestr_t
*)gbuf_rptr(gbuf_cont(m
));
1151 strncpy(pnve
->str
,pnew
->str
,pnew
->len
);
1152 pnve
->len
= pnew
->len
;
1155 bytesread
+= (pnew
->len
+1);
1156 pnew
= (at_nvestr_t
*) (((char *)pnew
) + pnew
->len
+ 1);
1158 /* showLocalZones1(); */
1171 if (!(pnve = getLocalZone(i))) {
1174 strncpy(str,pnve->str,pnve->len);
1175 str[pnve->len] = '\0';
1186 if (DEFAULT_ZONE(zone
))
1189 if (!(pnve
= getLocalZone(i
)))
1191 if (!nbp_strcmp(pnve
,zone
,0))
1198 #define NULL_PNVESTR (at_nvestr_t *) 0
1200 at_nvestr_t
*getLocalZone(zno
)
1201 int zno
; /* zone number in virtual list to
1202 return, 0 for first zone */
1203 /* returns pointer to a new local zone number zno,
1204 returns null when no zones left.
1208 ifz
.zone_index
= zno
;
1210 return(getRTRLocalZone(&ifz
));
1212 return(getSPLocalZone(zno
));
1216 at_nvestr_t
*getSPLocalZone(zno
)
1217 int zno
; /* zone number in virtual list to
1218 return, 0 for first zone */
1219 /* single port mode version */
1221 int curz
=0; /* current zone */
1227 pnve
= (at_nvestr_t
*)gbuf_rptr(m
);
1230 return(NULL_PNVESTR
);
1231 if ( zno
>=lzonecnt
)
1232 return(NULL_PNVESTR
);
1233 for (curz
=0; curz
<zno
; curz
++,pnve
++ ) {
1234 if ( curz
<lzonecnt
) {
1235 if (curz
&& !(curz%ZONES_PER_BLK
) ) {
1238 pnve
= (at_nvestr_t
*)gbuf_rptr(m
);
1241 return(NULL_PNVESTR
);
1244 if (pnve
->len
> NBP_NVE_STR_SIZE
) {
1245 return(NULL_PNVESTR
);
1249 return(NULL_PNVESTR
);
1254 /* The following functions are used in name registration and removal */
1256 int nbp_fillin_nve(entity
, nve
)
1257 at_entity_t
*entity
;
1262 if (entity
->object
.len
> NBP_NVE_STR_SIZE
||
1263 entity
->type
.len
> NBP_NVE_STR_SIZE
||
1264 entity
->zone
.len
> NBP_NVE_STR_SIZE
) {
1265 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1266 ("nbp_fillin_nve: bad str len\n"));
1271 nve
->zone
= entity
->zone
;
1273 if (!isZoneLocal(&entity
->zone
)) {
1277 /* if there's no zone, '*' gets filled in when entry is created */
1278 if (!DEFAULT_ZONE(&entity
->zone
))
1279 nve
->zone_hash
= nbp_strhash(&nve
->zone
);
1281 nve
->object
= entity
->object
;
1282 nve
->object_hash
= 0;
1283 if (entity
->object
.len
== 1 &&
1284 (entity
->object
.str
[0] == NBP_ORD_WILDCARD
||
1285 entity
->object
.str
[0] == NBP_SPL_WILDCARD
)) {
1286 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1287 ("nbp_fillin_nve: wildcard\n"));
1291 for (i
= 0; i
< entity
->object
.len
; i
++) {
1292 if (entity
->object
.str
[i
] == NBP_SPL_WILDCARD
) {
1293 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1294 ("nbp_fillin_nve: wildcard2\n"));
1299 nve
->object_hash
= nbp_strhash(&nve
->object
);
1301 nve
->type
= entity
->type
;
1303 if (entity
->type
.len
== 1 &&
1304 (entity
->type
.str
[0] == NBP_ORD_WILDCARD
||
1305 entity
->type
.str
[0] == NBP_SPL_WILDCARD
)) {
1309 for (i
= 0; i
< entity
->type
.len
; i
++) {
1310 if (entity
->type
.str
[i
] == NBP_SPL_WILDCARD
) {
1311 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1312 ("nbp_fillin_nve: wildcard3\n"));
1317 nve
->type_hash
= nbp_strhash(&nve
->type
);
1320 } /* nbp_fillin_nve */
1322 nve_entry_t
*nbp_find_nve(nve
)
1325 register nve_entry_t
*nve_entry
;
1327 ATDISABLE(nve_lock_pri
,NVE_LOCK
);
1328 TAILQ_FOREACH(nve_entry
, &name_registry
, nve_link
) {
1329 if (nve
->zone_hash
&&
1330 ((nve
->zone_hash
!= nve_entry
->zone_hash
) &&
1331 (nve
->zone_hash
!= hzonehash
))) {
1332 dPrintf(D_M_NBP_LOW
,D_L_USR4
,
1333 ("nbp_find_nve: no match for zone, req hash:%x\n",
1338 if ((nve
->object_hash
) &&
1339 (nve
->object_hash
!= nve_entry
->object_hash
))
1342 if ((nve
->type_hash
) &&
1343 (nve
->type_hash
!= nve_entry
->type_hash
))
1346 /* Found a match! */
1347 ATENABLE(nve_lock_pri
,NVE_LOCK
);
1350 ATENABLE(nve_lock_pri
,NVE_LOCK
);
1353 } /* nbp_find_nve */
1355 static int nbp_enum_gen (nve_entry
)
1356 register nve_entry_t
*nve_entry
;
1358 register int new_enum
= 0;
1359 register nve_entry_t
*ne
;
1361 ATDISABLE(nve_lock_pri
,NVE_LOCK
);
1363 TAILQ_FOREACH(ne
, &name_registry
, nve_link
) {
1364 if ((*(int *)&ne
->address
== *(int *)&nve_entry
->address
) &&
1365 (ne
->enumerator
== new_enum
)) {
1366 if (new_enum
== 255) {
1367 ATENABLE(nve_lock_pri
,NVE_LOCK
);
1368 return(EADDRNOTAVAIL
);
1376 ATENABLE(nve_lock_pri
,NVE_LOCK
);
1377 nve_entry
->enumerator
= new_enum
;
1381 int nbp_new_nve_entry(nve_entry
, ifID
)
1382 nve_entry_t
*nve_entry
;
1386 nve_entry_t
*new_entry
;
1390 if (!(valid_at_addr((at_inet_t
*)&nve_entry
->address
))) {
1391 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1392 ("nbp_new_nve_entry: valid_at_addr\n"));
1395 if ((error
= nbp_enum_gen(nve_entry
)))
1398 nve_entry
->unique_nbp_id
= ++nbp_id_count
;
1400 /* Got an nve entry on hand.... allocate a buffer, copy the entry
1401 * on to it and stick it in the registry.
1403 if ((tag
= gbuf_alloc(sizeof(nve_entry_t
), PRI_HI
)) == NULL
){
1406 gbuf_wset(tag
, sizeof(nve_entry_t
));
1407 new_entry
= (nve_entry_t
*)gbuf_rptr(tag
);
1408 bcopy(nve_entry
, new_entry
, sizeof(nve_entry_t
));
1410 if (DEFAULT_ZONE(&nve_entry
->zone
)) {
1411 /* put actual zone name in entry instead of "*" */
1412 /* if single port mode and no zone name, then a router
1413 is down, so use pram zone name hint from elap cfg */
1414 if (!MULTIPORT_MODE
&& ifID_home
->ifZoneName
.str
[0] == '*') {
1415 zone
= &ifID_home
->startup_zone
;
1417 zone
= &ifID_home
->ifZoneName
;
1419 new_entry
->zone
= *zone
;
1420 if ( new_entry
->zone
.len
== 0 ) {
1421 new_entry
->zone
.str
[0] = '*';
1422 new_entry
->zone
.len
= 1;
1424 new_entry
->zone_hash
= nbp_strhash(&new_entry
->zone
);
1426 new_entry
->tag
= tag
;
1427 new_entry
->pid
= current_proc()->p_pid
;
1429 ATDISABLE(nve_lock_pri
,NVE_LOCK
);
1430 TAILQ_INSERT_TAIL(&name_registry
, new_entry
, nve_link
);
1431 ATENABLE(nve_lock_pri
,NVE_LOCK
);
1432 at_state
.flags
|= AT_ST_NBP_CHANGED
;
1436 char zone
[35],object
[35],type
[35];
1437 strncpy(zone
,new_entry
->zone
.str
, new_entry
->zone
.len
);
1438 strncpy(object
,new_entry
->object
.str
, new_entry
->object
.len
);
1439 strncpy(type
,new_entry
->type
.str
, new_entry
->type
.len
);
1440 object
[new_entry
->object
.len
] = '\0';
1441 zone
[new_entry
->zone
.len
] = '\0';
1442 type
[new_entry
->type
.len
] = '\0';
1443 dPrintf(D_M_NBP_LOW
, D_L_USR4
,
1444 ("nbp_insert: adding %s:%s@%s addr:%d.%d ",
1446 new_entry
->address
.net
, new_entry
->address
.node
));
1448 #endif /* NBP_DEBUG */
1450 nbp_add_multicast(&new_entry
->zone
, ifID
);
1452 } /* nbp_new_nve_entry */
1454 void nbp_delete_entry (nve_entry
)
1455 nve_entry_t
*nve_entry
;
1457 TAILQ_REMOVE(&name_registry
, nve_entry
, nve_link
);
1458 gbuf_freem(nve_entry
->tag
);
1459 at_state
.flags
|= AT_ST_NBP_CHANGED
;
1462 /* Registration of an NBP entity in multihoming mode, from AIOCNBPREG
1464 int nbp_mh_reg(nbpP
)
1468 at_ifaddr_t
*ifID
= 0;
1470 int finished
= FALSE
;
1472 if (nbp_fillin_nve(&nbpP
->name
, &nve
) != 0) {
1474 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1475 ("nbp_mh_reg: bad tuple\n"));
1478 nve
.address
= nbpP
->addr
;
1479 nve
.ddptype
= nbpP
->ddptype
;
1481 if (DEFAULT_ZONE(&nbpP
->name
.zone
)) {
1482 /* multihoming mode with the default zone specified */
1484 /* now find the matching interfaces */
1485 TAILQ_FOREACH(ifID
, &at_ifQueueHd
, aa_link
) {
1486 if (nbpP
->addr
.net
|| nbpP
->addr
.node
) {
1487 /* if address is specified */
1488 if ((nbpP
->addr
.net
!= ifID
->ifThisNode
.s_net
||
1489 nbpP
->addr
.node
!= ifID
->ifThisNode
.s_node
))
1492 /* the address was specified, and
1493 we found the matching interface */
1496 /* address is not specified, so fill in
1497 the address for the interface */
1498 nve
.address
.net
= ifID
->ifThisNode
.s_net
;
1499 nve
.address
.node
= ifID
->ifThisNode
.s_node
;
1501 nve
.zone
= ifID
->ifZoneName
;
1502 nve
.zone_hash
= nbp_strhash(&nve
.zone
);
1503 if (nbp_find_nve(&nve
))
1505 if (nbp_new_nve_entry(&nve
, ifID
) == 0)
1508 if (registered
&& !nbpP
->addr
.net
&& !nbpP
->addr
.node
) {
1509 nbpP
->addr
.net
= ifID_home
->ifThisNode
.s_net
;
1510 nbpP
->addr
.node
= ifID_home
->ifThisNode
.s_node
;
1513 /* multihoming mode with a specific zone specified */
1514 /* see which segments (interfaces) are seeded for this zone */
1516 char ifs_in_zone
[IF_TOTAL_MAX
];
1517 if (!(zno
= zt_find_zname(&nve
.zone
))) {
1518 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1519 ("nbp_mh_reg: didn't find zone name\n"));
1522 getIfUsage(zno
-1, ifs_in_zone
);
1524 /* now find the first matching interface */
1525 TAILQ_FOREACH(ifID
, &at_ifQueueHd
, aa_link
) {
1526 if (!ifs_in_zone
[ifID
->ifPort
])
1527 /* zone doesn't match */
1530 /* the zone matches, so unless the
1531 address is specified and doesn't
1532 match, we only need to do this once */
1535 if (nbpP
->addr
.net
|| nbpP
->addr
.node
) {
1536 /* address is specified */
1538 if ((nbpP
->addr
.net
!= ifID
->ifThisNode
.s_net
||
1539 nbpP
->addr
.node
!= ifID
->ifThisNode
.s_node
))
1542 /* the address was specified, and
1543 we found the matching interface */
1546 /* address is not specified, so fill in
1547 the address for the interface */
1548 nve
.address
.net
= ifID
->ifThisNode
.s_net
;
1549 nve
.address
.node
= ifID
->ifThisNode
.s_node
;
1551 if (nbp_find_nve(&nve
))
1553 if (nbp_new_nve_entry(&nve
, ifID
) == 0)
1556 if (registered
&& !nbpP
->addr
.net
&& !nbpP
->addr
.node
) {
1557 nbpP
->addr
.net
= ifID
->ifThisNode
.s_net
;
1558 nbpP
->addr
.node
= ifID
->ifThisNode
.s_node
;
1561 nbpP
->unique_nbp_id
= (registered
> 1)? 0: nve
.unique_nbp_id
;
1566 return(EADDRNOTAVAIL
);