]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/ddp_nbp.c
73fdc6aeafa7717ac9076ed0af1f4db37a842544
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
74 extern at_ifaddr_t
*ifID_table
[];
75 extern at_ifaddr_t
*ifID_home
;
77 TAILQ_HEAD(name_registry
, _nve_
) name_registry
;
83 static gbuf_t
*lzones
=0; /* head of local zones list */
84 static int lzonecnt
=0; /* # zones stored in lzones */
85 static u_int hzonehash
=0; /* hash val of home zone */
86 static int nve_lock_pri
;
88 static int nbp_lkup_reply(nbp_req_t
*, nve_entry_t
*);
89 static int nbp_strcmp(at_nvestr_t
*, at_nvestr_t
*, u_char
);
90 static int nbp_setup_resp(nbp_req_t
*, int);
91 static int nbp_send_resp(nbp_req_t
*);
92 static int nbp_validate_n_hash(nbp_req_t
*, int, int);
93 static nve_entry_t
*nbp_search_nve();
94 static int isZoneLocal(at_nvestr_t
*);
97 #define NVE_LOCK nve_lock
100 void nbp_delete_entry();
101 extern int at_reg_mcast();
102 extern at_nvestr_t
*getRTRLocalZone(zone_usage_t
*);
103 extern void nbp_add_multicast( at_nvestr_t
*, at_ifaddr_t
*);
105 static long nbp_id_count
= 0;
108 * Copy src to string dst of size siz. At most siz-1 characters
109 * will be copied. Always NUL terminates (unless siz == 0).
110 * Returns strlen(src); if retval >= siz, truncation occurred.
112 __private_extern__
size_t
113 strlcpy(char *dst
, const char *src
, size_t siz
)
119 /* Copy as many bytes as will fit */
120 if (n
!= 0 && --n
!= 0) {
122 if ((*d
++ = *s
++) == 0)
127 /* Not enough room in dst, add NUL and traverse rest of src */
130 *d
= '\0'; /* NUL-terminate dst */
135 return(s
- src
- 1); /* count does not include NUL */
140 void sethzonehash(elapp
)
143 if (elapp
->startup_zone
.len
) {
144 hzonehash
= nbp_strhash(&elapp
->startup_zone
);
150 /* delete all NVE's and release buffers */
151 register nve_entry_t
*nve_entry
, *nve_next
;
153 ATDISABLE(nve_lock_pri
,NVE_LOCK
);
154 for ((nve_entry
= TAILQ_FIRST(&name_registry
)); nve_entry
; nve_entry
= nve_next
) {
155 nve_next
= TAILQ_NEXT(nve_entry
, nve_link
);
157 /* NB: nbp_delete_entry calls TAILQ_REMOVE */
158 nbp_delete_entry(nve_entry
);
160 ATENABLE(nve_lock_pri
,NVE_LOCK
);
170 u_char
*nbp2zone(nbp
, maxp
)
177 p
= (u_char
*)&nbp
->tuple
[0].enu_entity
; /* p -> object */
178 if (p
>= maxp
) return NULL
;
179 p
+= (*p
+1); /* p -> type */
180 if (p
>= maxp
) return NULL
;
181 p
+= (*p
+1); /* p -> zone */
182 if (p
>= maxp
) return NULL
;
183 if ((p
+ *p
) >= maxp
) return NULL
;
187 void nbp_input(m
, ifID
)
189 register at_ifaddr_t
*ifID
;
192 register at_ddp_t
*ddp
= DATA_DDP(m
);
193 register at_nbp_t
*nbp
= DATA_NBP(m
);
194 register nve_entry_t
*nve_entry
, *next_nve
;
195 register RT_entry
*rt
;
196 register int ddpSent
= FALSE
; /* true if we re-sent this pkt (don't free) */
197 struct etalk_addr mcastAddr
;
201 /* from original nbp_input() when this function was nbp_handler() */
202 if ((gbuf_type(m
) != MT_DATA
&& gbuf_type(m
) != MSG_DATA
) ||
203 ddp
->type
!= DDP_NBP
) {
208 /* Some initializations */
209 nbp_req
.response
= NULL
;
211 nbp_req
.space_unused
= nbp_req
.flags
= 0;
213 dPrintf(D_M_NBP_LOW
, D_L_USR1
,
214 ("nbp_input control:%d tuplecount:%d id:%d\n",
215 nbp
->control
, nbp
->tuple_count
, nbp
->at_nbp_id
));
216 switch (nbp
->control
) {
221 dst_net
= NET_VALUE(ddp
->dst_net
);
222 dPrintf(D_M_NBP_LOW
, D_L_USR2
, (" LKUP %s\n",
223 ifID
!= ifID_home
? "non-home" : "home"));
224 if ( ROUTING_MODE
&& (NET_VALUE(ddp
->dst_net
) != 0)
225 && ((dst_net
< ifID
->ifThisCableStart
)
226 || (dst_net
> ifID
->ifThisCableEnd
)) ) {
227 routing_needed(m
, ifID
, TRUE
);
233 if (nbp_validate_n_hash (&nbp_req
, TRUE
, FALSE
) == 0) {
234 nbp_req
.func
= nbp_lkup_reply
;
235 (void) nbp_search_nve(&nbp_req
, ifID
);
236 if (nbp_req
.response
) {
237 nbp_send_resp(&nbp_req
);
242 char zone
[35],object
[35],type
[35];
243 strlcpy(zone
,nbp_req
.nve
.zone
.str
, sizeof(zone
));
244 strlcpy(object
,nbp_req
.nve
.object
.str
, sizeof(object
));
245 strlcpy(type
,nbp_req
.nve
.type
.str
, sizeof(type
));
246 if (ifID
!= ifID_home
)
247 dPrintf(D_M_NBP_LOW
,D_L_USR2
,
248 ("nbp_LKUP for:%s:%s@%s", object
, type
, zone
));
250 #endif /* NBP_DEBUG */
255 register int zhome
=0;
256 /* true if home zone == destination zone */
259 register int error_found
=0;
260 register at_ifaddr_t
*ifIDorig
;
262 if (!ROUTING_MODE
) /* for routers only! */
267 for (i
= 0 ; i
< RT_maxentry
; i
++) {
269 if ((rt
->EntryState
& RTE_STATE_PERMANENT
) &&
270 NET_VALUE(ddp
->dst_net
) >= rt
->NetStart
&&
271 NET_VALUE(ddp
->dst_net
) <= rt
->NetStop
274 if (rt
->NetPort
>= IF_TOTAL_MAX
) {
275 dPrintf(D_M_NBP
,D_L_ERROR
,
276 ("nbp_input:FWDREQ: bad port# from RT_table\n"));
280 ifID
= ifID_table
[rt
->NetPort
];
282 dPrintf(D_M_NBP
,D_L_ERROR
,
283 ("nbp_input:FWDREQ: ifID %s\n",
284 !ifID
? "not found" : "invalid"));
288 if (ifID
->ifState
== LAP_OFFLINE
) {
289 dPrintf(D_M_NBP
,D_L_ERROR
,
290 ("nbp_input:FWDREQ: ifID offline (port %d)\n",
298 if (error_found
) /* the port is not correct */
301 if (!ifID
) { /* this packet is not for us, let the routing engine handle it */
302 routing_needed(m
, ifIDorig
, TRUE
);
308 * At this point, we have a valid Forward request for one of our
309 * directly connected port. Convert it to a NBP Lookup
312 nbp
->control
= NBP_LKUP
;
313 NET_ASSIGN(ddp
->dst_net
, 0);
317 /*### LD 01/18/94 Check if the dest is also the home zone. */
319 p
= nbp2zone(nbp
, gbuf_wptr(m
));
320 if ((p
== NULL
) || !(zno
= zt_find_zname(p
))) {
321 dPrintf(D_M_NBP
,D_L_WARNING
,
322 ("nbp_input: FWDRQ:zone not found\n"));
325 if (isZoneLocal((at_nvestr_t
*)p
))
326 zhome
= TRUE
; /* one of our ports is in destination zone */
327 if (!zt_get_zmcast(ifID
, p
, &mcastAddr
)) {
328 dPrintf(D_M_NBP
,D_L_ERROR
,
329 ("nbp_input: FDWREQ:zt_get_zmcast error\n"));
334 if (zhome
) { /*### LD 01/18/95 In case our home is here, call back nbp */
336 if (!(m2
= (gbuf_t
*)gbuf_copym((gbuf_t
*)m
))) {
337 dPrintf(D_M_NBP
,D_L_ERROR
,
338 ("nbp_input: FWDRQ:gbuf_copym failed\n"));
344 nbp
->control
= NBP_LKUP
;
345 NET_ASSIGN(ddp
->dst_net
, 0);
347 dPrintf(D_M_NBP
,D_L_INFO
,
348 ("nbp_input: FWDRQ:loop back for us\n"));
349 nbp_input(m2
, ifID_home
);
352 if (FDDI_OR_TOKENRING(ifID
->aa_ifp
->if_type
))
353 ddp_bit_reverse(&mcastAddr
);
354 ddp_router_output(m
, ifID
, ET_ADDR
,NULL
,NULL
, &mcastAddr
);
361 register int zno
; /* zone table entry numb */
362 register int ztind
; /* zone bitmap index into RT_entry */
363 register int ztbit
; /* zone bit to check within above index */
364 register int zhome
=0; /* true if home zone == destination zone */
366 register gbuf_t
*m2
, *m3
;
367 register int fromUs
= FALSE
;
368 register at_socket ourSkt
; /* originating skt */
370 /* for router & MH local only */
371 if ((!(MULTIHOME_MODE
&& FROM_US(ddp
))) && !ROUTING_MODE
) {
372 dPrintf(D_M_NBP
,D_L_USR2
,
373 ("nbp_input: BRREQ:non router or MH local\n"));
377 p
= nbp2zone(nbp
, gbuf_wptr(m
));
378 if ((p
== NULL
) || !(zno
= zt_find_zname(p
))) {
381 if (MULTIHOME_MODE
&& ifID
->ifRouterState
== NO_ROUTER
) {
382 ((at_nvestr_t
*)p
)->len
= 1;
383 ((at_nvestr_t
*)p
)->str
[0] = '*';
385 if (isZoneLocal((at_nvestr_t
*)p
)) {
386 zhome
= TRUE
; /* one of our ports is in destination zone */
388 if (FROM_US(ddp
)){ /* save, before we munge it */
390 ourSkt
= ddp
->src_socket
;
391 dPrintf(D_M_NBP
,D_L_USR2
,
392 ("nbp_input:BRRQ from us net:%d\n",
393 (int)NET_VALUE(ddp
->src_net
)));
395 /* from ZT_CLR_ZMAP */
398 ztbit
= 0x80 >> (i
% 8);
399 for (i
=0,rt
=RT_table
; i
<RT_maxentry
; i
++,rt
++) {
400 if (!(rt
->ZoneBitMap
[ztind
] & ztbit
)) /* if zone not in route, skip*/
402 /* dPrintf(D_M_NBP, D_L_USR3,
403 ("nbp_input: BRREQ: port:%d, entry %d\n",
407 ifID
= ifID_table
[rt
->NetPort
];
409 dPrintf(D_M_NBP
, D_L_ERROR
,
410 ("nbp_input:BRRQ: ifID %s\n",
411 !ifID
? "not found" : "invalid"));
416 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
417 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
418 ddp
->src_socket
= NBP_SOCKET
;
419 if (!(m2
= (gbuf_t
*)gbuf_copym((gbuf_t
*)m
))) {
420 dPrintf(D_M_NBP
,D_L_ERROR
,
421 ("nbp_input: BRREQ:gbuf_copym failed\n"));
427 /* nbp->tuple[0].enu_addr.socket = NBP_SOCKET; */
428 if (MULTIHOME_MODE
&& fromUs
) {
429 /* set the return address of the lookup to that of the
430 interface it's going out on so that replies come back
432 dPrintf(D_M_NBP
,D_L_USR3
,
433 ("nbp_input: BRREQ: src changed to %d.%d.%d\n",
434 ifID
->ifThisNode
.s_net
,
435 ifID
->ifThisNode
.s_node
, ourSkt
));
436 nbp
->tuple
[0].enu_addr
.net
= ifID
->ifThisNode
.s_net
;
437 nbp
->tuple
[0].enu_addr
.node
= ifID
->ifThisNode
.s_node
;
438 nbp
->tuple
[0].enu_addr
.socket
= ourSkt
;
439 ddp
->src_socket
= NBP_SOCKET
;
442 dPrintf(D_M_NBP
, D_L_USR3
,
443 ("nbp_input: BRREQ: not from us\n"));
445 dPrintf(D_M_NBP
, D_L_USR3
,
446 ("nbp_input dist:%d\n", rt
->NetDist
));
447 if (rt
->NetDist
== 0) { /* if direct connect, *we* do the LKUP */
448 nbp
->control
= NBP_LKUP
;
449 NET_ASSIGN(ddp
->dst_net
, 0);
451 if (!zt_get_zmcast(ifID
, p
, &mcastAddr
)) {
452 dPrintf(D_M_NBP
,D_L_ERROR
,
453 ("nbp_input: BRRQ:zt_get_zmcast error\n"));
456 if (FDDI_OR_TOKENRING(ifID
->aa_ifp
->if_type
))
457 ddp_bit_reverse(&mcastAddr
);
458 ddp_router_output(m2
, ifID
, ET_ADDR
, NULL
, NULL
, &mcastAddr
);
460 else { /* else fwd to router */
462 if (rt
->NetStart
== 0) /* if Ltalk */
463 NET_ASSIGN(ddp
->dst_net
, rt
->NetStop
);
465 NET_ASSIGN(ddp
->dst_net
, rt
->NetStart
);
466 nbp
->control
= NBP_FWDRQ
;
467 ddp_router_output(m2
, ifID
, AT_ADDR
,
468 rt
->NextIRNet
, rt
->NextIRNode
,
475 if (!(m3
= (gbuf_t
*)gbuf_copym((gbuf_t
*)m
))) {
476 dPrintf(D_M_NBP
,D_L_ERROR
,
477 ("nbp_input: BRREQ:gbuf_copym failed\n"));
484 nbp
->control
= NBP_LKUP
;
485 NET_ASSIGN(ddp
->dst_net
, 0);
487 dPrintf(D_M_NBP
,D_L_INFO
, ("nbp_input: BRRQ:loop back for us\n"));
488 nbp_input(m3
, ifID_home
);
494 if (!ROUTING_MODE
) /* for routers only! */
497 dPrintf(D_M_NBP
,D_L_WARNING
,
498 ("nbp_input: routing needed for LKUP_REPLY: from %d.%d\n",
499 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
500 routing_needed(m
, ifID
, TRUE
);
505 dPrintf(D_M_NBP
,D_L_ERROR
,
506 ("nbp_input: unhandled pkt: type:%d\n", nbp
->control
));
508 routing_needed(m
, ifID
, TRUE
);
511 } /* switch control */
518 static int nbp_validate_n_hash (nbp_req
, wild_ok
, checkLocal
)
519 register nbp_req_t
*nbp_req
;
520 register int wild_ok
;
521 register int checkLocal
; /* if true check if local zone */
523 register at_nvestr_t
*object
, *type
, *zone
;
524 at_nbptuple_t
*tuple
;
525 register int i
, part_wild
;
527 tuple
= DATA_NBP(nbp_req
->request
)->tuple
;
532 net
= tuple
->enu_addr
.net
;
533 node
= tuple
->enu_addr
.node
;
534 skt
= tuple
->enu_addr
.socket
;
535 dPrintf(D_M_NBP_LOW
,D_L_USR4
,
536 ("nbp_validate: tuple addr:%d:%d:%d\n",net
,node
,skt
));
538 #endif /* COMMENTED_OUT */
540 /* tuple is in the compressed (no "filler") format */
541 object
= (at_nvestr_t
*)&tuple
->enu_entity
;
542 type
= (at_nvestr_t
*)(&object
->str
[object
->len
]);
543 zone
= (at_nvestr_t
*)(&type
->str
[type
->len
]);
545 if (object
->len
> NBP_NVE_STR_SIZE
|| type
->len
> NBP_NVE_STR_SIZE
||
546 zone
->len
> NBP_NVE_STR_SIZE
) {
547 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
548 ("nbp_val_n_hash: bad str len\n"));
555 char xzone
[35],xobject
[35],xtype
[35];
556 strlcpy(xzone
,zone
->str
, sizeof(xzone
));
557 strlcpy(xobject
,object
->str
, sizeof(xobject
));
558 strlcpy(xtype
,type
->str
, sizeof(xtype
));
559 dPrintf(D_M_NBP_LOW
, D_L_USR4
,
560 ("nbp_validate: looking for %s:%s@%s\n",
561 xobject
, xtype
, xzone
));
563 #endif /* NBP_DEBUG */
564 /* Is this request for our zone ?? */
565 nbp_req
->nve
.zone
.len
= zone
->len
;
566 nbp_req
->nve
.zone_hash
= 0;
567 bcopy(zone
->str
,nbp_req
->nve
.zone
.str
, zone
->len
);
569 if (checkLocal
&& !isZoneLocal(zone
)) {
571 strlcpy(str
,zone
->str
,sizeof(str
));
572 dPrintf(D_M_NBP_LOW
,D_L_WARNING
,
573 ("nbp_val_n_hash bad zone: %s\n", str
));
578 if (!DEFAULT_ZONE(zone
)) {
579 nbp_req
->nve
.zone_hash
= nbp_strhash(& nbp_req
->nve
.zone
);
582 nbp_req
->nve
.address
= tuple
->enu_addr
;
583 nbp_req
->nve
.object
.len
= object
->len
;
584 nbp_req
->nve
.object_hash
= 0;
585 if (object
->len
== 1 && (object
->str
[0] == NBP_ORD_WILDCARD
||
586 object
->str
[0] == NBP_SPL_WILDCARD
)) {
588 nbp_req
->flags
|= NBP_WILD_OBJECT
;
590 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
591 ("nbp_val_n_hash: wild not okay\n"));
596 for (i
= part_wild
= 0; (unsigned) i
<object
->len
; i
++) {
597 if (object
->str
[i
] == NBP_SPL_WILDCARD
)
600 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
601 ("nbp_val_n_hash: too many parts wild\n"));
607 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
608 ("nbp_val_n_hash: wild not okay2\n"));
612 nbp_req
->nve
.object
.str
[i
] = object
->str
[i
];
615 nbp_req
->nve
.object_hash
=
616 nbp_strhash(&nbp_req
->nve
.object
);
619 nbp_req
->nve
.type
.len
= type
->len
;
620 nbp_req
->nve
.type_hash
= 0;
621 if (type
->len
== 1 && (type
->str
[0] == NBP_ORD_WILDCARD
||
622 type
->str
[0] == NBP_SPL_WILDCARD
)) {
624 nbp_req
->flags
|= NBP_WILD_TYPE
;
626 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
627 ("nbp_val_n_hash: wild not okay3\n"));
632 for (i
= part_wild
= 0; (unsigned) i
<type
->len
; i
++) {
633 if (type
->str
[i
] == NBP_SPL_WILDCARD
)
636 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
637 ("nbp_val_n_hash: too many parts wild2\n"));
646 nbp_req
->nve
.type
.str
[i
] = type
->str
[i
];
649 nbp_req
->nve
.type_hash
=
650 nbp_strhash(&nbp_req
->nve
.type
);
654 char zone
[35],object
[35],type
[35];
655 strlcpy(zone
,nbp_req
.nve
.zone
.str
, sizeof(zone
));
656 strlcpy(object
,nbp_req
.nve
.object
.str
, sizeof(object
));
657 strlcpy(type
,nbp_req
.nve
.type
.str
, sizeof(type
));
658 dPrintf(D_M_NBP_LOW
,D_L_USR4
,
659 ("nbp_validate: after hash: %s:%s@%s\n",
660 object
, type
, zone
));
662 #endif /* NBP_DEBUG */
664 } /* nbp_validate_n_hash */
667 /* Upshifts in place */
668 static void nbp_upshift (str
, count
)
669 register u_char
*str
;
674 static unsigned char lower_case
[] =
675 {0x8a, 0x8c, 0x8d, 0x8e, 0x96, 0x9a, 0x9f, 0xbe,
676 0xbf, 0xcf, 0x9b, 0x8b, 0x88, 0};
677 static unsigned char upper_case
[] =
678 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0xae,
679 0xaf, 0xce, 0xcd, 0xcc, 0xcb, 0};
681 for (j
=0 ; j
<count
; j
++) {
683 if (ch
>= 'a' && ch
<= 'z')
684 str
[j
] = ch
+ 'A' - 'a';
686 for (i
=0; lower_case
[i
]; i
++)
687 if (ch
== lower_case
[i
])
688 str
[j
] = upper_case
[i
];
693 u_int
nbp_strhash (nvestr
)
694 register at_nvestr_t
*nvestr
;
696 /* upshift while hashing */
697 register u_int hash
= 0;
704 for (i
=0; (unsigned) i
< nvestr
->len
; i
+=sizeof(int)) {
705 len
= MIN((nvestr
->len
-i
), sizeof(int));
706 if (len
== sizeof(int))
707 bcopy(&(nvestr
->str
[i
]), &un
, sizeof(un
));
710 for ( ; (unsigned) i
<nvestr
->len
; i
++)
711 un
.h_4char
[i
% sizeof(int)] = nvestr
->str
[i
];
713 nbp_upshift (un
.h_4char
, len
);
720 static nve_entry_t
*nbp_search_nve (nbp_req
, ifID
)
721 register nbp_req_t
*nbp_req
;
722 register at_ifaddr_t
*ifID
; /* NULL ok */
724 register nve_entry_t
*nve_entry
;
728 char zone
[35],object
[35],type
[35];
729 strlcpy(zone
,nbp_req
.nve
.zone
.str
, sizeof(zone
));
730 strlcpy(object
,nbp_req
.nve
.object
.str
, sizeof(object
));
731 strlcpy(type
,nbp_req
.nve
.type
.str
, sizeof(type
));
732 dPrintf(D_M_NBP_LOW
, D_L_USR4
,
733 ("nbp_search: looking for %s:%s@%s resp:0x%x\n",object
,type
,zone
,
734 (u_int
) nbp_req
->response
));
736 #endif /* NBP_DEBUG */
737 ATDISABLE(nve_lock_pri
,NVE_LOCK
);
738 TAILQ_FOREACH(nve_entry
, &name_registry
, nve_link
) {
739 if ((nbp_req
->nve
.zone_hash
) &&
740 ((nbp_req
->nve
.zone_hash
!=
741 nve_entry
->zone_hash
) &&
742 (nbp_req
->nve
.zone_hash
!= hzonehash
)
745 dPrintf(D_M_NBP_LOW
,D_L_USR4
,
746 ("nbp_search: no match for zone, req hash:%x\n",
747 nbp_req
->nve
.zone_hash
));
750 else { /* for this entry's zone OR no zone in request or entry */
751 /* only in singleport mode (!MULTIPORT_MODE) with
752 empty PRAM can an entry have '*' for it's zone
754 at_nvestr_t
*ezone
=&nve_entry
->zone
;
755 at_nvestr_t
*rzone
=&nbp_req
->nve
.zone
;
756 if (!DEFAULT_ZONE(rzone
) && !DEFAULT_ZONE(ezone
)) {
757 if (nbp_strcmp (rzone
, ezone
, 0) != 0)
761 if (MULTIHOME_MODE
&& ifID
&&
762 (nve_entry
->address
.net
!=
763 ifID
->ifThisNode
.s_net
)) {
764 dPrintf(D_M_NBP
, D_L_USR4
,
765 ("nbp search ifID (%d) & req net (%d) not eq\n",
766 nve_entry
->address
.net
,
767 ifID
->ifThisNode
.s_net
));
771 dPrintf(D_M_NBP
, D_L_USR4
,
772 ("nbp search ifID (%d) & req net (%d) equal\n",
773 nve_entry
->address
.net
,
774 ifID
->ifThisNode
.s_net
));
778 if (!(nbp_req
->flags
& NBP_WILD_OBJECT
)) {
779 if ((nbp_req
->nve
.object_hash
) &&
780 (nbp_req
->nve
.object_hash
!=
781 nve_entry
->object_hash
))
784 if (nbp_strcmp (&nbp_req
->nve
.object
,
786 NBP_SPL_WILDCARD
) != 0)
792 if (!(nbp_req
->flags
& NBP_WILD_TYPE
)) {
793 if ((nbp_req
->nve
.type_hash
) &&
794 (nbp_req
->nve
.type_hash
!=nve_entry
->type_hash
))
797 if (nbp_strcmp (&nbp_req
->nve
.type
,
799 NBP_SPL_WILDCARD
) != 0)
807 char zone
[35],object
[35],type
[35];
809 strlcpy(zone
,nbp_req
.nve
.zone
.str
, sizeof(zone
));
810 strlcpy(object
,nbp_req
.nve
.object
.str
, sizeof(object
));
811 strlcpy(type
,nbp_req
.nve
.type
.str
, sizeof(type
));
812 dPrintf(D_M_NBP_LOW
, D_L_USR2
,
813 ("nbp_search: found %s:%s@%s net:%d\n",
814 object
, type
, zone
, (int)nve_entry
->address
.net
));
816 #endif /* NBP_DEBUG */
817 if (nbp_req
->func
!= NULL
) {
818 if ((*(nbp_req
->func
))(nbp_req
, nve_entry
) != 0) {
819 /* errno expected to be set by func */
820 ATENABLE(nve_lock_pri
,NVE_LOCK
);
824 ATENABLE(nve_lock_pri
,NVE_LOCK
);
828 ATENABLE(nve_lock_pri
,NVE_LOCK
);
832 } /* nbp_search_nve */
834 static int nbp_lkup_reply (nbp_req
, nve_entry
)
835 register nbp_req_t
*nbp_req
;
836 register nve_entry_t
*nve_entry
;
838 register at_nbptuple_t
*tuple
;
839 register int tuple_size
, buf_len
;
840 register int obj_len
, type_len
;
843 /* size of the current tuple we want to write... */
844 tuple_size
= nve_entry
->object
.len
+ 1 + /* object */
845 nve_entry
->type
.len
+ 1 + /* type */
847 sizeof (at_inet_t
) + 1; /* addr + enum */
849 buf_len
= ((nbp_req
->flags
& NBP_WILD_MASK
) ? DDP_DATA_SIZE
:tuple_size
);
850 if (nbp_req
->response
== NULL
) {
851 if (nbp_setup_resp (nbp_req
, buf_len
) != 0)
852 /* errno expected to be set by nbp_setup_resp() */
856 if ((nbp_req
->space_unused
< tuple_size
) ||
857 (DATA_NBP(nbp_req
->response
)->tuple_count
== NBP_TUPLE_MAX
)) {
858 if (nbp_send_resp (nbp_req
) != 0)
860 if (nbp_setup_resp (nbp_req
, buf_len
) != 0)
864 /* At this point, we have a response buffer that can accommodate the
865 * tuple we want to write. Write it!
867 tuple
= (at_nbptuple_t
*)gbuf_wptr(nbp_req
->response
);
868 tuple
->enu_addr
= nve_entry
->address
;
869 tuple
->enu_enum
= nve_entry
->enumerator
;
871 /* tuple is in the compressed (no "filler") format */
872 p
= (u_char
*)&tuple
->enu_entity
.object
;
873 obj_len
= nve_entry
->object
.len
+ 1;
874 bcopy(&nve_entry
->object
, p
, obj_len
);
876 type_len
= nve_entry
->type
.len
+ 1;
877 bcopy(&nve_entry
->type
, p
, type_len
);
882 nbp_req
->space_unused
-= tuple_size
;
883 gbuf_winc(nbp_req
->response
, tuple_size
);
885 /* increment the tuple count in header by 1 */
886 DATA_NBP(nbp_req
->response
)->tuple_count
++;
892 static int nbp_strcmp (str1
, str2
, embedded_wildcard
)
893 register at_nvestr_t
*str1
, *str2
;
894 register u_char embedded_wildcard
; /* If str1 may contain a character
895 * that's to be treated as an
896 * embedded wildcard, this character
897 * is it. Making this special case
898 * since for zone names, squiggly
899 * equal is not to be treated as a
905 register int reverse
= 0;
906 register int left_index
;
908 /* Embedded wildcard, if any, could only be in the first string (str1).
909 * returns 0 if two strings are equal (modulo case), -1 otherwise
912 if (str1
->len
== 0 || str2
->len
== 0) {
916 /* Wildcards are not allowed in str2.
918 * If str1 could potentially contain an embedded wildcard, since the
919 * embedded wildcard matches ZERO OR MORE characters, str1 can not be
920 * more than 1 character longer than str2.
922 * If str1 is not supposed to have embedded wildcards, the two strs
923 * must be of equal length.
925 if ((embedded_wildcard
&& (str2
->len
< (unsigned) (str1
->len
-1))) ||
926 (!embedded_wildcard
&& (str2
->len
!= str1
->len
))) {
930 for (i1
= i2
= left_index
= 0; (unsigned) i1
< str1
->len
;) {
934 if (embedded_wildcard
&& (ch1
==embedded_wildcard
)) {
935 /* hit the embedded wild card... start comparing from
936 * the other end of the string.
939 /* But, if embedded wildcard was the last character of
940 * the string, the two strings match, so return okay.
942 if (i1
== str1
->len
-1) {
952 nbp_upshift(&ch1
, 1);
953 nbp_upshift(&ch2
, 1);
961 if (i1
== left_index
) {
965 i1
++; i2
++; left_index
++;
972 static void nbp_setup_hdr (nbp_req
)
973 register nbp_req_t
*nbp_req
;
975 register at_ddp_t
*ddp
;
976 register at_nbp_t
*nbp
;
978 ddp
= DATA_DDP(nbp_req
->response
);
979 nbp
= DATA_NBP(nbp_req
->response
);
982 UAS_ASSIGN(ddp
->checksum
, 0);
983 ddp
->unused
= ddp
->hopcount
= 0;
985 switch(DATA_NBP(nbp_req
->request
)->control
) {
987 ddp
->dst_socket
= nbp_req
->nve
.address
.socket
;
988 ddp
->dst_node
= nbp_req
->nve
.address
.node
;
989 NET_ASSIGN(ddp
->dst_net
, nbp_req
->nve
.address
.net
);
990 nbp
->control
= NBP_LKUP_REPLY
;
993 nbp
->at_nbp_id
= DATA_NBP(nbp_req
->request
)->at_nbp_id
;
998 static int nbp_setup_resp (nbp_req
, tuples_size
)
999 register nbp_req_t
*nbp_req
;
1000 register int tuples_size
;
1002 int buf_size
= tuples_size
+ DDP_X_HDR_SIZE
+ NBP_HDR_SIZE
;
1003 nbp_req
->response
= gbuf_alloc(AT_WR_OFFSET
+buf_size
, PRI_MED
);
1004 if (nbp_req
->response
== NULL
) {
1008 gbuf_rinc(nbp_req
->response
, AT_WR_OFFSET
);
1009 gbuf_wset(nbp_req
->response
, DDP_X_HDR_SIZE
+ NBP_HDR_SIZE
);
1010 nbp_setup_hdr(nbp_req
);
1012 DATA_NBP(nbp_req
->response
)->tuple_count
= 0;
1013 nbp_req
->space_unused
= tuples_size
;
1016 } /* nbp_setup_resp */
1019 static int nbp_send_resp (nbp_req
)
1020 register nbp_req_t
*nbp_req
;
1024 status
= ddp_output(&nbp_req
->response
, (at_socket
)NBP_SOCKET
, FALSE
);
1025 nbp_req
->response
= NULL
;
1030 void nbp_add_multicast(zone
, ifID
)
1034 char data
[ETHERNET_ADDR_LEN
];
1037 if (zone
->str
[0] == '*')
1042 strlcpy(str
,zone
->str
,sizeof(str
));
1043 dPrintf(D_M_NBP_LOW
, D_L_USR3
,
1044 ("nbp_add_multi getting mc for %s\n", str
));
1046 zt_get_zmcast(ifID
, zone
, data
);
1047 if (FDDI_OR_TOKENRING(ifID
->aa_ifp
->if_type
))
1048 ddp_bit_reverse(data
);
1049 dPrintf(D_M_NBP_LOW
,D_L_USR3
,
1050 ("nbp_add_multi adding 0x%x%x port:%d ifID:0x%x if:%s\n",
1051 *(unsigned*)data
, (*(unsigned *)(data
+2))&0x0000ffff,
1052 i
, (u_int
) ifID
, ifID
->ifName
));
1054 bcopy((caddr_t
)data
, (caddr_t
)&ifID
->ZoneMcastAddr
, ETHERNET_ADDR_LEN
);
1055 (void)at_reg_mcast(ifID
, (caddr_t
)&ifID
->ZoneMcastAddr
);
1061 /* for SNMP, returns size in # of entries */
1063 register nve_entry_t
*nve
;
1066 ATDISABLE(nve_lock_pri
,NVE_LOCK
);
1067 for (nve
= TAILQ_FIRST(&name_registry
); nve
; nve
= TAILQ_NEXT(nve
, nve_link
), i
++)
1069 ATENABLE(nve_lock_pri
,NVE_LOCK
);
1073 getNbpTable(p
, s
, c
)
1075 int s
; /* starting entry */
1076 int c
; /* # entries to copy */
1078 /* for SNMP, returns section of nbp table */
1080 register nve_entry_t
*nve
;
1082 static int nextNo
=0; /* entry that *next points to */
1083 static nve_entry_t
*next
= (nve_entry_t
*)NULL
;
1085 if (s
&& next
&& nextNo
== s
) {
1090 nve
= TAILQ_FIRST(&name_registry
);
1092 ATDISABLE(nve_lock_pri
,NVE_LOCK
);
1093 for ( ; nve
&& c
; nve
= TAILQ_NEXT(nve
, nve_link
), p
++,i
++) {
1095 p
->nbpe_object
= nve
->object
;
1096 p
->nbpe_type
= nve
->type
;
1100 ATENABLE(nve_lock_pri
,NVE_LOCK
);
1105 next
= (nve_entry_t
*)NULL
;
1111 #define ZONES_PER_BLK 31 /* 31 fits within a 1k blk) */
1112 #define ZONE_BLK_SIZE ZONES_PER_BLK * sizeof(at_nvestr_t)
1114 int setLocalZones(newzones
, size
)
1115 at_nvestr_t
*newzones
;
1117 /* updates list of zones which are local to all active ports
1118 missing zones are not deleted, only missing zones are added.
1121 int bytesread
=0; /* #bytes read from tuple */
1124 at_nvestr_t
*pnve
, *pnew
= newzones
;
1127 if(!(lzones
= gbuf_alloc(ZONE_BLK_SIZE
, PRI_MED
)))
1129 gbuf_wset(lzones
,0);
1131 while (bytesread
< size
) { /* for each new zone */
1134 strlcpy(str
,pnew
->str
,sizeof(str
));
1137 pnve
= (at_nvestr_t
*)gbuf_rptr(m
);
1139 for (i
=0; i
<lzonecnt
&& !dupe
; i
++,pnve
++) {
1140 if (i
&& !(i%ZONES_PER_BLK
))
1143 pnve
= (at_nvestr_t
*)gbuf_rptr(m
);
1147 if (pnew
->len
!= pnve
->len
)
1149 if (pnew
->len
> NBP_NVE_STR_SIZE
) {
1152 if (!strncmp(pnew
->str
, pnve
->str
, pnew
->len
)) {
1159 if (lzonecnt
&& !(lzonecnt%ZONES_PER_BLK
)) {
1160 if(!(gbuf_cont(m
) = gbuf_alloc(ZONE_BLK_SIZE
, PRI_MED
)))
1162 gbuf_wset(gbuf_cont(m
),0);
1163 pnve
= (at_nvestr_t
*)gbuf_rptr(gbuf_cont(m
));
1165 strlcpy(pnve
->str
,pnew
->str
,sizeof(pnve
->str
));
1166 pnve
->len
= pnew
->len
;
1169 bytesread
+= (pnew
->len
+1);
1170 pnew
= (at_nvestr_t
*) (((char *)pnew
) + pnew
->len
+ 1);
1172 /* showLocalZones1(); */
1185 if (!(pnve = getLocalZone(i))) {
1188 strlcpy(str,pnve->str,sizeof(str));
1199 if (DEFAULT_ZONE(zone
))
1202 if (!(pnve
= getLocalZone(i
)))
1204 if (!nbp_strcmp(pnve
,zone
,0))
1211 #define NULL_PNVESTR (at_nvestr_t *) 0
1213 at_nvestr_t
*getLocalZone(zno
)
1214 int zno
; /* zone number in virtual list to
1215 return, 0 for first zone */
1216 /* returns pointer to a new local zone number zno,
1217 returns null when no zones left.
1221 ifz
.zone_index
= zno
;
1223 return(getRTRLocalZone(&ifz
));
1225 return(getSPLocalZone(zno
));
1229 at_nvestr_t
*getSPLocalZone(zno
)
1230 int zno
; /* zone number in virtual list to
1231 return, 0 for first zone */
1232 /* single port mode version */
1234 int curz
=0; /* current zone */
1240 pnve
= (at_nvestr_t
*)gbuf_rptr(m
);
1243 return(NULL_PNVESTR
);
1244 if ( zno
>=lzonecnt
)
1245 return(NULL_PNVESTR
);
1246 for (curz
=0; curz
<zno
; curz
++,pnve
++ ) {
1247 if ( curz
<lzonecnt
) {
1248 if (curz
&& !(curz%ZONES_PER_BLK
) ) {
1251 pnve
= (at_nvestr_t
*)gbuf_rptr(m
);
1254 return(NULL_PNVESTR
);
1257 if (pnve
->len
> NBP_NVE_STR_SIZE
) {
1258 return(NULL_PNVESTR
);
1262 return(NULL_PNVESTR
);
1267 /* The following functions are used in name registration and removal */
1269 int nbp_fillin_nve(entity
, nve
)
1270 at_entity_t
*entity
;
1275 if (entity
->object
.len
> NBP_NVE_STR_SIZE
||
1276 entity
->type
.len
> NBP_NVE_STR_SIZE
||
1277 entity
->zone
.len
> NBP_NVE_STR_SIZE
) {
1278 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1279 ("nbp_fillin_nve: bad str len\n"));
1284 nve
->zone
= entity
->zone
;
1286 if (!isZoneLocal(&entity
->zone
)) {
1290 /* if there's no zone, '*' gets filled in when entry is created */
1291 if (!DEFAULT_ZONE(&entity
->zone
))
1292 nve
->zone_hash
= nbp_strhash(&nve
->zone
);
1294 nve
->object
= entity
->object
;
1295 nve
->object_hash
= 0;
1296 if (entity
->object
.len
== 1 &&
1297 (entity
->object
.str
[0] == NBP_ORD_WILDCARD
||
1298 entity
->object
.str
[0] == NBP_SPL_WILDCARD
)) {
1299 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1300 ("nbp_fillin_nve: wildcard\n"));
1304 for (i
= 0; i
< entity
->object
.len
; i
++) {
1305 if (entity
->object
.str
[i
] == NBP_SPL_WILDCARD
) {
1306 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1307 ("nbp_fillin_nve: wildcard2\n"));
1312 nve
->object_hash
= nbp_strhash(&nve
->object
);
1314 nve
->type
= entity
->type
;
1316 if (entity
->type
.len
== 1 &&
1317 (entity
->type
.str
[0] == NBP_ORD_WILDCARD
||
1318 entity
->type
.str
[0] == NBP_SPL_WILDCARD
)) {
1322 for (i
= 0; i
< entity
->type
.len
; i
++) {
1323 if (entity
->type
.str
[i
] == NBP_SPL_WILDCARD
) {
1324 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1325 ("nbp_fillin_nve: wildcard3\n"));
1330 nve
->type_hash
= nbp_strhash(&nve
->type
);
1333 } /* nbp_fillin_nve */
1335 nve_entry_t
*nbp_find_nve(nve
)
1338 register nve_entry_t
*nve_entry
;
1340 ATDISABLE(nve_lock_pri
,NVE_LOCK
);
1341 TAILQ_FOREACH(nve_entry
, &name_registry
, nve_link
) {
1342 if (nve
->zone_hash
&&
1343 ((nve
->zone_hash
!= nve_entry
->zone_hash
) &&
1344 (nve
->zone_hash
!= hzonehash
))) {
1345 dPrintf(D_M_NBP_LOW
,D_L_USR4
,
1346 ("nbp_find_nve: no match for zone, req hash:%x\n",
1351 if ((nve
->object_hash
) &&
1352 (nve
->object_hash
!= nve_entry
->object_hash
))
1355 if ((nve
->type_hash
) &&
1356 (nve
->type_hash
!= nve_entry
->type_hash
))
1359 /* Found a match! */
1360 ATENABLE(nve_lock_pri
,NVE_LOCK
);
1363 ATENABLE(nve_lock_pri
,NVE_LOCK
);
1366 } /* nbp_find_nve */
1368 static int nbp_enum_gen (nve_entry
)
1369 register nve_entry_t
*nve_entry
;
1371 register int new_enum
= 0;
1372 register nve_entry_t
*ne
;
1374 ATDISABLE(nve_lock_pri
,NVE_LOCK
);
1376 TAILQ_FOREACH(ne
, &name_registry
, nve_link
) {
1377 if ((*(int *)&ne
->address
== *(int *)&nve_entry
->address
) &&
1378 (ne
->enumerator
== new_enum
)) {
1379 if (new_enum
== 255) {
1380 ATENABLE(nve_lock_pri
,NVE_LOCK
);
1381 return(EADDRNOTAVAIL
);
1389 ATENABLE(nve_lock_pri
,NVE_LOCK
);
1390 nve_entry
->enumerator
= new_enum
;
1394 int nbp_new_nve_entry(nve_entry
, ifID
)
1395 nve_entry_t
*nve_entry
;
1399 nve_entry_t
*new_entry
;
1403 if (!(valid_at_addr((at_inet_t
*)&nve_entry
->address
))) {
1404 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1405 ("nbp_new_nve_entry: valid_at_addr\n"));
1408 if ((error
= nbp_enum_gen(nve_entry
)))
1411 nve_entry
->unique_nbp_id
= ++nbp_id_count
;
1413 /* Got an nve entry on hand.... allocate a buffer, copy the entry
1414 * on to it and stick it in the registry.
1416 if ((tag
= gbuf_alloc(sizeof(nve_entry_t
), PRI_HI
)) == NULL
){
1419 gbuf_wset(tag
, sizeof(nve_entry_t
));
1420 new_entry
= (nve_entry_t
*)gbuf_rptr(tag
);
1421 bcopy(nve_entry
, new_entry
, sizeof(nve_entry_t
));
1423 if (DEFAULT_ZONE(&nve_entry
->zone
)) {
1424 /* put actual zone name in entry instead of "*" */
1425 /* if single port mode and no zone name, then a router
1426 is down, so use pram zone name hint from elap cfg */
1427 if (!MULTIPORT_MODE
&& ifID_home
->ifZoneName
.str
[0] == '*') {
1428 zone
= &ifID_home
->startup_zone
;
1430 zone
= &ifID_home
->ifZoneName
;
1432 new_entry
->zone
= *zone
;
1433 if ( new_entry
->zone
.len
== 0 ) {
1434 new_entry
->zone
.str
[0] = '*';
1435 new_entry
->zone
.len
= 1;
1437 new_entry
->zone_hash
= nbp_strhash(&new_entry
->zone
);
1439 new_entry
->tag
= tag
;
1440 new_entry
->pid
= proc_selfpid();
1442 ATDISABLE(nve_lock_pri
,NVE_LOCK
);
1443 TAILQ_INSERT_TAIL(&name_registry
, new_entry
, nve_link
);
1444 ATENABLE(nve_lock_pri
,NVE_LOCK
);
1445 at_state
.flags
|= AT_ST_NBP_CHANGED
;
1449 char zone
[35],object
[35],type
[35];
1450 strlcpy(zone
,nbp_req
.nve
.zone
.str
, sizeof(zone
));
1451 strlcpy(object
,nbp_req
.nve
.object
.str
, sizeof(object
));
1452 strlcpy(type
,nbp_req
.nve
.type
.str
, sizeof(type
));
1453 dPrintf(D_M_NBP_LOW
, D_L_USR4
,
1454 ("nbp_insert: adding %s:%s@%s addr:%d.%d ",
1456 new_entry
->address
.net
, new_entry
->address
.node
));
1458 #endif /* NBP_DEBUG */
1460 nbp_add_multicast(&new_entry
->zone
, ifID
);
1462 } /* nbp_new_nve_entry */
1464 void nbp_delete_entry (nve_entry
)
1465 nve_entry_t
*nve_entry
;
1467 TAILQ_REMOVE(&name_registry
, nve_entry
, nve_link
);
1468 gbuf_freem(nve_entry
->tag
);
1469 at_state
.flags
|= AT_ST_NBP_CHANGED
;
1472 /* Registration of an NBP entity in multihoming mode, from AIOCNBPREG
1474 int nbp_mh_reg(nbpP
)
1478 at_ifaddr_t
*ifID
= 0;
1480 int finished
= FALSE
;
1482 if (nbp_fillin_nve(&nbpP
->name
, &nve
) != 0) {
1484 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1485 ("nbp_mh_reg: bad tuple\n"));
1488 nve
.address
= nbpP
->addr
;
1489 nve
.ddptype
= nbpP
->ddptype
;
1491 if (DEFAULT_ZONE(&nbpP
->name
.zone
)) {
1492 /* multihoming mode with the default zone specified */
1494 /* now find the matching interfaces */
1495 TAILQ_FOREACH(ifID
, &at_ifQueueHd
, aa_link
) {
1496 if (nbpP
->addr
.net
|| nbpP
->addr
.node
) {
1497 /* if address is specified */
1498 if ((nbpP
->addr
.net
!= ifID
->ifThisNode
.s_net
||
1499 nbpP
->addr
.node
!= ifID
->ifThisNode
.s_node
))
1502 /* the address was specified, and
1503 we found the matching interface */
1506 /* address is not specified, so fill in
1507 the address for the interface */
1508 nve
.address
.net
= ifID
->ifThisNode
.s_net
;
1509 nve
.address
.node
= ifID
->ifThisNode
.s_node
;
1511 nve
.zone
= ifID
->ifZoneName
;
1512 nve
.zone_hash
= nbp_strhash(&nve
.zone
);
1513 if (nbp_find_nve(&nve
))
1515 if (nbp_new_nve_entry(&nve
, ifID
) == 0)
1518 if (registered
&& !nbpP
->addr
.net
&& !nbpP
->addr
.node
) {
1519 nbpP
->addr
.net
= ifID_home
->ifThisNode
.s_net
;
1520 nbpP
->addr
.node
= ifID_home
->ifThisNode
.s_node
;
1523 /* multihoming mode with a specific zone specified */
1524 /* see which segments (interfaces) are seeded for this zone */
1526 at_ifnames_t ifs_in_zone
;
1527 if (!(zno
= zt_find_zname(&nve
.zone
))) {
1528 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1529 ("nbp_mh_reg: didn't find zone name\n"));
1532 getIfUsage(zno
-1, &ifs_in_zone
);
1534 /* now find the matching interfaces */
1535 TAILQ_FOREACH(ifID
, &at_ifQueueHd
, aa_link
) {
1536 if (!ifs_in_zone
.at_if
[ifID
->ifPort
])
1537 /* zone doesn't match */
1540 /* the zone matches, so unless the
1541 address is specified and doesn't
1542 match, we only need to do this once */
1545 if (nbpP
->addr
.net
|| nbpP
->addr
.node
) {
1546 /* address is specified */
1548 if ((nbpP
->addr
.net
!= ifID
->ifThisNode
.s_net
||
1549 nbpP
->addr
.node
!= ifID
->ifThisNode
.s_node
))
1552 /* the address was specified, and
1553 we found the matching interface */
1556 /* address is not specified, so fill in
1557 the address for the interface */
1558 nve
.address
.net
= ifID
->ifThisNode
.s_net
;
1559 nve
.address
.node
= ifID
->ifThisNode
.s_node
;
1561 if (nbp_find_nve(&nve
))
1563 if (nbp_new_nve_entry(&nve
, ifID
) == 0)
1565 if (registered
&& !nbpP
->addr
.net
&& !nbpP
->addr
.node
) {
1566 nbpP
->addr
.net
= ifID
->ifThisNode
.s_net
;
1567 nbpP
->addr
.node
= ifID
->ifThisNode
.s_node
;
1572 nbpP
->unique_nbp_id
= (registered
> 1)? 0: nve
.unique_nbp_id
;
1577 return(EADDRNOTAVAIL
);