]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/ddp_nbp.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
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
;
82 static gbuf_t
*lzones
=0; /* head of local zones list */
83 static int lzonecnt
=0; /* # zones stored in lzones */
84 static u_int hzonehash
=0; /* hash val of home zone */
85 static int nve_lock_pri
;
87 static int nbp_lkup_reply(nbp_req_t
*, nve_entry_t
*);
88 static int nbp_strcmp(at_nvestr_t
*, at_nvestr_t
*, u_char
);
89 static int nbp_setup_resp(nbp_req_t
*, int);
90 static int nbp_send_resp(nbp_req_t
*);
91 static int nbp_validate_n_hash(nbp_req_t
*, int, int);
92 static nve_entry_t
*nbp_search_nve();
93 static int isZoneLocal(at_nvestr_t
*);
96 #define NVE_LOCK nve_lock
99 void nbp_delete_entry();
100 extern int at_reg_mcast();
101 extern at_nvestr_t
*getRTRLocalZone(zone_usage_t
*);
102 extern void nbp_add_multicast( at_nvestr_t
*, at_ifaddr_t
*);
104 static long nbp_id_count
= 0;
106 void sethzonehash(elapp
)
109 if (elapp
->startup_zone
.len
) {
110 hzonehash
= nbp_strhash(&elapp
->startup_zone
);
116 /* delete all NVE's and release buffers */
117 register nve_entry_t
*nve_entry
, *nve_next
;
119 for ((nve_entry
= TAILQ_FIRST(&name_registry
)); nve_entry
; nve_entry
= nve_next
) {
120 nve_next
= TAILQ_NEXT(nve_entry
, nve_link
);
122 /* NB: nbp_delete_entry calls TAILQ_REMOVE */
123 nbp_delete_entry(nve_entry
);
134 u_char
*nbp2zone(nbp
, maxp
)
141 p
= (u_char
*)&nbp
->tuple
[0].enu_entity
; /* p -> object */
142 if (p
>= maxp
) return NULL
;
143 p
+= (*p
+1); /* p -> type */
144 if (p
>= maxp
) return NULL
;
145 p
+= (*p
+1); /* p -> zone */
146 if (p
>= maxp
) return NULL
;
147 if ((p
+ *p
) >= maxp
) return NULL
;
151 void nbp_input(m
, ifID
)
153 register at_ifaddr_t
*ifID
;
156 register at_ddp_t
*ddp
= DATA_DDP(m
);
157 register at_nbp_t
*nbp
= DATA_NBP(m
);
158 register nve_entry_t
*nve_entry
, *next_nve
;
159 register RT_entry
*rt
;
160 register int ddpSent
= FALSE
; /* true if we re-sent this pkt (don't free) */
161 struct etalk_addr mcastAddr
;
165 /* from original nbp_input() when this function was nbp_handler() */
166 if ((gbuf_type(m
) != MT_DATA
&& gbuf_type(m
) != MSG_DATA
) ||
167 ddp
->type
!= DDP_NBP
) {
172 /* Some initializations */
173 nbp_req
.response
= NULL
;
175 nbp_req
.space_unused
= nbp_req
.flags
= 0;
177 dPrintf(D_M_NBP_LOW
, D_L_USR1
,
178 ("nbp_input control:%d tuplecount:%d id:%d\n",
179 nbp
->control
, nbp
->tuple_count
, nbp
->at_nbp_id
));
180 switch (nbp
->control
) {
185 dst_net
= NET_VALUE(ddp
->dst_net
);
186 dPrintf(D_M_NBP_LOW
, D_L_USR2
, (" LKUP %s\n",
187 ifID
!= ifID_home
? "non-home" : "home"));
188 if ( ROUTING_MODE
&& (NET_VALUE(ddp
->dst_net
) != 0)
189 && ((dst_net
< ifID
->ifThisCableStart
)
190 || (dst_net
> ifID
->ifThisCableEnd
)) ) {
191 routing_needed(m
, ifID
, TRUE
);
197 if (nbp_validate_n_hash (&nbp_req
, TRUE
, FALSE
) == 0) {
198 nbp_req
.func
= nbp_lkup_reply
;
199 (void) nbp_search_nve(&nbp_req
, ifID
);
200 if (nbp_req
.response
) {
201 nbp_send_resp(&nbp_req
);
206 char zone
[35],object
[35],type
[35];
207 strncpy(zone
,nbp_req
.nve
.zone
.str
, nbp_req
.nve
.zone
.len
);
208 strncpy(object
,nbp_req
.nve
.object
.str
, nbp_req
.nve
.object
.len
);
209 strncpy(type
,nbp_req
.nve
.type
.str
, nbp_req
.nve
.type
.len
);
210 object
[nbp_req
.nve
.object
.len
] = '\0';
211 zone
[nbp_req
.nve
.zone
.len
] = '\0';
212 type
[nbp_req
.nve
.type
.len
] = '\0';
213 if (ifID
!= ifID_home
)
214 dPrintf(D_M_NBP_LOW
,D_L_USR2
,
215 ("nbp_LKUP for:%s:%s@%s", object
, type
, zone
));
217 #endif /* NBP_DEBUG */
222 register int zhome
=0;
223 /* true if home zone == destination zone */
226 register int error_found
=0;
227 register at_ifaddr_t
*ifIDorig
;
229 if (!ROUTING_MODE
) /* for routers only! */
234 for (i
= 0 ; i
< RT_maxentry
; i
++) {
236 if ((rt
->EntryState
& RTE_STATE_PERMANENT
) &&
237 NET_VALUE(ddp
->dst_net
) >= rt
->NetStart
&&
238 NET_VALUE(ddp
->dst_net
) <= rt
->NetStop
241 if (rt
->NetPort
>= IF_TOTAL_MAX
) {
242 dPrintf(D_M_NBP
,D_L_ERROR
,
243 ("nbp_input:FWDREQ: bad port# from RT_table\n"));
247 ifID
= ifID_table
[rt
->NetPort
];
249 dPrintf(D_M_NBP
,D_L_ERROR
,
250 ("nbp_input:FWDREQ: ifID %s\n",
251 !ifID
? "not found" : "invalid"));
255 if (ifID
->ifState
== LAP_OFFLINE
) {
256 dPrintf(D_M_NBP
,D_L_ERROR
,
257 ("nbp_input:FWDREQ: ifID offline (port %d)\n",
265 if (error_found
) /* the port is not correct */
268 if (!ifID
) { /* this packet is not for us, let the routing engine handle it */
269 routing_needed(m
, ifIDorig
, TRUE
);
275 * At this point, we have a valid Forward request for one of our
276 * directly connected port. Convert it to a NBP Lookup
279 nbp
->control
= NBP_LKUP
;
280 NET_ASSIGN(ddp
->dst_net
, 0);
284 /*### LD 01/18/94 Check if the dest is also the home zone. */
286 p
= nbp2zone(nbp
, gbuf_wptr(m
));
287 if ((p
== NULL
) || !(zno
= zt_find_zname(p
))) {
288 dPrintf(D_M_NBP
,D_L_WARNING
,
289 ("nbp_input: FWDRQ:zone not found\n"));
292 if (isZoneLocal((at_nvestr_t
*)p
))
293 zhome
= TRUE
; /* one of our ports is in destination zone */
294 if (!zt_get_zmcast(ifID
, p
, &mcastAddr
)) {
295 dPrintf(D_M_NBP
,D_L_ERROR
,
296 ("nbp_input: FDWREQ:zt_get_zmcast error\n"));
301 if (zhome
) { /*### LD 01/18/95 In case our home is here, call back nbp */
303 if (!(m2
= (gbuf_t
*)gbuf_copym((gbuf_t
*)m
))) {
304 dPrintf(D_M_NBP
,D_L_ERROR
,
305 ("nbp_input: FWDRQ:gbuf_copym failed\n"));
311 nbp
->control
= NBP_LKUP
;
312 NET_ASSIGN(ddp
->dst_net
, 0);
314 dPrintf(D_M_NBP
,D_L_INFO
,
315 ("nbp_input: FWDRQ:loop back for us\n"));
316 nbp_input(m2
, ifID_home
);
319 if (FDDI_OR_TOKENRING(ifID
->aa_ifp
->if_type
))
320 ddp_bit_reverse(&mcastAddr
);
321 ddp_router_output(m
, ifID
, ET_ADDR
,NULL
,NULL
, &mcastAddr
);
328 register int zno
; /* zone table entry numb */
329 register int ztind
; /* zone bitmap index into RT_entry */
330 register int ztbit
; /* zone bit to check within above index */
331 register int zhome
=0; /* true if home zone == destination zone */
333 register gbuf_t
*m2
, *m3
;
334 register int fromUs
= FALSE
;
335 register at_socket ourSkt
; /* originating skt */
337 /* for router & MH local only */
338 if ((!(MULTIHOME_MODE
&& FROM_US(ddp
))) && !ROUTING_MODE
) {
339 dPrintf(D_M_NBP
,D_L_USR2
,
340 ("nbp_input: BRREQ:non router or MH local\n"));
344 p
= nbp2zone(nbp
, gbuf_wptr(m
));
345 if ((p
== NULL
) || !(zno
= zt_find_zname(p
))) {
348 if (MULTIHOME_MODE
&& ifID
->ifRouterState
== NO_ROUTER
) {
349 ((at_nvestr_t
*)p
)->len
= 1;
350 ((at_nvestr_t
*)p
)->str
[0] = '*';
352 if (isZoneLocal((at_nvestr_t
*)p
)) {
353 zhome
= TRUE
; /* one of our ports is in destination zone */
355 if (FROM_US(ddp
)){ /* save, before we munge it */
357 ourSkt
= ddp
->src_socket
;
358 dPrintf(D_M_NBP
,D_L_USR2
,
359 ("nbp_input:BRRQ from us net:%d\n",
360 (int)NET_VALUE(ddp
->src_net
)));
362 /* from ZT_CLR_ZMAP */
365 ztbit
= 0x80 >> (i
% 8);
366 for (i
=0,rt
=RT_table
; i
<RT_maxentry
; i
++,rt
++) {
367 if (!(rt
->ZoneBitMap
[ztind
] & ztbit
)) /* if zone not in route, skip*/
369 /* dPrintf(D_M_NBP, D_L_USR3,
370 ("nbp_input: BRREQ: port:%d, entry %d\n",
374 ifID
= ifID_table
[rt
->NetPort
];
376 dPrintf(D_M_NBP
, D_L_ERROR
,
377 ("nbp_input:BRRQ: ifID %s\n",
378 !ifID
? "not found" : "invalid"));
383 ddp
->src_node
= ifID
->ifThisNode
.s_node
;
384 NET_ASSIGN(ddp
->src_net
, ifID
->ifThisNode
.s_net
);
385 ddp
->src_socket
= NBP_SOCKET
;
386 if (!(m2
= (gbuf_t
*)gbuf_copym((gbuf_t
*)m
))) {
387 dPrintf(D_M_NBP
,D_L_ERROR
,
388 ("nbp_input: BRREQ:gbuf_copym failed\n"));
394 /* nbp->tuple[0].enu_addr.socket = NBP_SOCKET; */
395 if (MULTIHOME_MODE
&& fromUs
) {
396 /* set the return address of the lookup to that of the
397 interface it's going out on so that replies come back
399 dPrintf(D_M_NBP
,D_L_USR3
,
400 ("nbp_input: BRREQ: src changed to %d.%d.%d\n",
401 ifID
->ifThisNode
.s_net
,
402 ifID
->ifThisNode
.s_node
, ourSkt
));
403 nbp
->tuple
[0].enu_addr
.net
= htons(ifID
->ifThisNode
.s_net
);
404 nbp
->tuple
[0].enu_addr
.node
= ifID
->ifThisNode
.s_node
;
405 nbp
->tuple
[0].enu_addr
.socket
= ourSkt
;
406 ddp
->src_socket
= NBP_SOCKET
;
409 dPrintf(D_M_NBP
, D_L_USR3
,
410 ("nbp_input: BRREQ: not from us\n"));
412 dPrintf(D_M_NBP
, D_L_USR3
,
413 ("nbp_input dist:%d\n", rt
->NetDist
));
414 if (rt
->NetDist
== 0) { /* if direct connect, *we* do the LKUP */
415 nbp
->control
= NBP_LKUP
;
416 NET_ASSIGN(ddp
->dst_net
, 0);
418 if (!zt_get_zmcast(ifID
, p
, &mcastAddr
)) {
419 dPrintf(D_M_NBP
,D_L_ERROR
,
420 ("nbp_input: BRRQ:zt_get_zmcast error\n"));
423 if (FDDI_OR_TOKENRING(ifID
->aa_ifp
->if_type
))
424 ddp_bit_reverse(&mcastAddr
);
425 ddp_router_output(m2
, ifID
, ET_ADDR
, NULL
, NULL
, &mcastAddr
);
427 else { /* else fwd to router */
429 if (rt
->NetStart
== 0) /* if Ltalk */
430 NET_ASSIGN(ddp
->dst_net
, rt
->NetStop
);
432 NET_ASSIGN(ddp
->dst_net
, rt
->NetStart
);
433 nbp
->control
= NBP_FWDRQ
;
434 ddp_router_output(m2
, ifID
, AT_ADDR
,
435 rt
->NextIRNet
, rt
->NextIRNode
,
442 if (!(m3
= (gbuf_t
*)gbuf_copym((gbuf_t
*)m
))) {
443 dPrintf(D_M_NBP
,D_L_ERROR
,
444 ("nbp_input: BRREQ:gbuf_copym failed\n"));
451 nbp
->control
= NBP_LKUP
;
452 NET_ASSIGN(ddp
->dst_net
, 0);
454 dPrintf(D_M_NBP
,D_L_INFO
, ("nbp_input: BRRQ:loop back for us\n"));
455 nbp_input(m3
, ifID_home
);
461 if (!ROUTING_MODE
) /* for routers only! */
464 dPrintf(D_M_NBP
,D_L_WARNING
,
465 ("nbp_input: routing needed for LKUP_REPLY: from %d.%d\n",
466 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
467 routing_needed(m
, ifID
, TRUE
);
472 dPrintf(D_M_NBP
,D_L_ERROR
,
473 ("nbp_input: unhandled pkt: type:%d\n", nbp
->control
));
475 routing_needed(m
, ifID
, TRUE
);
478 } /* switch control */
485 static int nbp_validate_n_hash (nbp_req
, wild_ok
, checkLocal
)
486 register nbp_req_t
*nbp_req
;
487 register int wild_ok
;
488 register int checkLocal
; /* if true check if local zone */
490 register at_nvestr_t
*object
, *type
, *zone
;
491 at_nbptuple_t
*tuple
;
492 register int i
, part_wild
;
494 tuple
= DATA_NBP(nbp_req
->request
)->tuple
;
499 net
= ntohs(tuple
->enu_addr
.net
);
500 node
= tuple
->enu_addr
.node
;
501 skt
= tuple
->enu_addr
.socket
;
502 dPrintf(D_M_NBP_LOW
,D_L_USR4
,
503 ("nbp_validate: tuple addr:%d:%d:%d\n",net
,node
,skt
));
505 #endif /* COMMENTED_OUT */
507 /* tuple is in the compressed (no "filler") format */
508 object
= (at_nvestr_t
*)&tuple
->enu_entity
;
509 type
= (at_nvestr_t
*)(&object
->str
[object
->len
]);
510 zone
= (at_nvestr_t
*)(&type
->str
[type
->len
]);
512 if (object
->len
> NBP_NVE_STR_SIZE
|| type
->len
> NBP_NVE_STR_SIZE
||
513 zone
->len
> NBP_NVE_STR_SIZE
) {
514 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
515 ("nbp_val_n_hash: bad str len\n"));
522 char xzone
[35],xobject
[35],xtype
[35];
523 strncpy(xzone
,zone
->str
, zone
->len
);
524 strncpy(xobject
,object
->str
, object
->len
);
525 strncpy(xtype
,type
->str
, type
->len
);
526 xobject
[object
->len
] = '\0';
527 xzone
[zone
->len
] = '\0';
528 xtype
[type
->len
] = '\0';
529 dPrintf(D_M_NBP_LOW
, D_L_USR4
,
530 ("nbp_validate: looking for %s:%s@%s\n",
531 xobject
, xtype
, xzone
));
533 #endif /* NBP_DEBUG */
534 /* Is this request for our zone ?? */
535 nbp_req
->nve
.zone
.len
= zone
->len
;
536 nbp_req
->nve
.zone_hash
= 0;
537 bcopy(zone
->str
,nbp_req
->nve
.zone
.str
, zone
->len
);
539 if (checkLocal
&& !isZoneLocal(zone
)) {
541 strncpy(str
,zone
->str
,zone
->len
);
542 str
[zone
->len
] = '\0';
543 dPrintf(D_M_NBP_LOW
,D_L_WARNING
,
544 ("nbp_val_n_hash bad zone: %s\n", str
));
549 if (!DEFAULT_ZONE(zone
)) {
550 nbp_req
->nve
.zone_hash
= nbp_strhash(& nbp_req
->nve
.zone
);
553 nbp_req
->nve
.address
= tuple
->enu_addr
;
554 nbp_req
->nve
.object
.len
= object
->len
;
555 nbp_req
->nve
.object_hash
= 0;
556 if (object
->len
== 1 && (object
->str
[0] == NBP_ORD_WILDCARD
||
557 object
->str
[0] == NBP_SPL_WILDCARD
)) {
559 nbp_req
->flags
|= NBP_WILD_OBJECT
;
561 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
562 ("nbp_val_n_hash: wild not okay\n"));
567 for (i
= part_wild
= 0; (unsigned) i
<object
->len
; i
++) {
568 if (object
->str
[i
] == NBP_SPL_WILDCARD
)
571 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
572 ("nbp_val_n_hash: too many parts wild\n"));
578 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
579 ("nbp_val_n_hash: wild not okay2\n"));
583 nbp_req
->nve
.object
.str
[i
] = object
->str
[i
];
586 nbp_req
->nve
.object_hash
=
587 nbp_strhash(&nbp_req
->nve
.object
);
590 nbp_req
->nve
.type
.len
= type
->len
;
591 nbp_req
->nve
.type_hash
= 0;
592 if (type
->len
== 1 && (type
->str
[0] == NBP_ORD_WILDCARD
||
593 type
->str
[0] == NBP_SPL_WILDCARD
)) {
595 nbp_req
->flags
|= NBP_WILD_TYPE
;
597 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
598 ("nbp_val_n_hash: wild not okay3\n"));
603 for (i
= part_wild
= 0; (unsigned) i
<type
->len
; i
++) {
604 if (type
->str
[i
] == NBP_SPL_WILDCARD
)
607 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
608 ("nbp_val_n_hash: too many parts wild2\n"));
617 nbp_req
->nve
.type
.str
[i
] = type
->str
[i
];
620 nbp_req
->nve
.type_hash
=
621 nbp_strhash(&nbp_req
->nve
.type
);
625 char zone
[35],object
[35],type
[35];
626 strncpy(zone
,nbp_req
->nve
.zone
.str
, nbp_req
->nve
.zone
.len
);
627 strncpy(object
,nbp_req
->nve
.object
.str
, nbp_req
->nve
.object
.len
);
628 strncpy(type
,nbp_req
->nve
.type
.str
, nbp_req
->nve
.type
.len
);
629 object
[nbp_req
->nve
.object
.len
] = '\0';
630 zone
[nbp_req
->nve
.zone
.len
] = '\0';
631 type
[nbp_req
->nve
.type
.len
] = '\0';
632 dPrintf(D_M_NBP_LOW
,D_L_USR4
,
633 ("nbp_validate: after hash: %s:%s@%s\n",
634 object
, type
, zone
));
636 #endif /* NBP_DEBUG */
638 } /* nbp_validate_n_hash */
641 /* Upshifts in place */
642 static void nbp_upshift (str
, count
)
643 register u_char
*str
;
648 static unsigned char lower_case
[] =
649 {0x8a, 0x8c, 0x8d, 0x8e, 0x96, 0x9a, 0x9f, 0xbe,
650 0xbf, 0xcf, 0x9b, 0x8b, 0x88, 0};
651 static unsigned char upper_case
[] =
652 {0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0xae,
653 0xaf, 0xce, 0xcd, 0xcc, 0xcb, 0};
655 for (j
=0 ; j
<count
; j
++) {
657 if (ch
>= 'a' && ch
<= 'z')
658 str
[j
] = ch
+ 'A' - 'a';
660 for (i
=0; lower_case
[i
]; i
++)
661 if (ch
== lower_case
[i
])
662 str
[j
] = upper_case
[i
];
667 u_int
nbp_strhash (nvestr
)
668 register at_nvestr_t
*nvestr
;
670 /* upshift while hashing */
671 register u_int hash
= 0;
678 for (i
=0; (unsigned) i
< nvestr
->len
; i
+=sizeof(int)) {
679 len
= MIN((nvestr
->len
-i
), sizeof(int));
680 if (len
== sizeof(int))
681 bcopy(&(nvestr
->str
[i
]), &un
, sizeof(un
));
684 for ( ; (unsigned) i
<nvestr
->len
; i
++)
685 un
.h_4char
[i
% sizeof(int)] = nvestr
->str
[i
];
687 nbp_upshift (un
.h_4char
, len
);
694 static nve_entry_t
*nbp_search_nve (nbp_req
, ifID
)
695 register nbp_req_t
*nbp_req
;
696 register at_ifaddr_t
*ifID
; /* NULL ok */
698 register nve_entry_t
*nve_entry
;
702 char zone
[35],object
[35],type
[35];
703 strncpy(zone
,nbp_req
->nve
.zone
.str
, nbp_req
->nve
.zone
.len
);
704 strncpy(object
,nbp_req
->nve
.object
.str
, nbp_req
->nve
.object
.len
);
705 strncpy(type
,nbp_req
->nve
.type
.str
, nbp_req
->nve
.type
.len
);
706 object
[nbp_req
->nve
.object
.len
] = '\0';
707 zone
[nbp_req
->nve
.zone
.len
] = '\0';
708 type
[nbp_req
->nve
.type
.len
] = '\0';
709 dPrintf(D_M_NBP_LOW
, D_L_USR4
,
710 ("nbp_search: looking for %s:%s@%s resp:0x%x\n",object
,type
,zone
,
711 (u_int
) nbp_req
->response
));
713 #endif /* NBP_DEBUG */
714 TAILQ_FOREACH(nve_entry
, &name_registry
, nve_link
) {
715 if ((nbp_req
->nve
.zone_hash
) &&
716 ((nbp_req
->nve
.zone_hash
!=
717 nve_entry
->zone_hash
) &&
718 (nbp_req
->nve
.zone_hash
!= hzonehash
)
721 dPrintf(D_M_NBP_LOW
,D_L_USR4
,
722 ("nbp_search: no match for zone, req hash:%x\n",
723 nbp_req
->nve
.zone_hash
));
726 else { /* for this entry's zone OR no zone in request or entry */
727 /* only in singleport mode (!MULTIPORT_MODE) with
728 empty PRAM can an entry have '*' for it's zone
730 at_nvestr_t
*ezone
=&nve_entry
->zone
;
731 at_nvestr_t
*rzone
=&nbp_req
->nve
.zone
;
732 if (!DEFAULT_ZONE(rzone
) && !DEFAULT_ZONE(ezone
)) {
733 if (nbp_strcmp (rzone
, ezone
, 0) != 0)
737 if (MULTIHOME_MODE
&& ifID
&&
738 (nve_entry
->address
.net
!=
739 ifID
->ifThisNode
.s_net
)) {
740 dPrintf(D_M_NBP
, D_L_USR4
,
741 ("nbp search ifID (%d) & req net (%d) not eq\n",
742 nve_entry
->address
.net
,
743 ifID
->ifThisNode
.s_net
));
747 dPrintf(D_M_NBP
, D_L_USR4
,
748 ("nbp search ifID (%d) & req net (%d) equal\n",
749 nve_entry
->address
.net
,
750 ifID
->ifThisNode
.s_net
));
754 if (!(nbp_req
->flags
& NBP_WILD_OBJECT
)) {
755 if ((nbp_req
->nve
.object_hash
) &&
756 (nbp_req
->nve
.object_hash
!=
757 nve_entry
->object_hash
))
760 if (nbp_strcmp (&nbp_req
->nve
.object
,
762 NBP_SPL_WILDCARD
) != 0)
768 if (!(nbp_req
->flags
& NBP_WILD_TYPE
)) {
769 if ((nbp_req
->nve
.type_hash
) &&
770 (nbp_req
->nve
.type_hash
!=nve_entry
->type_hash
))
773 if (nbp_strcmp (&nbp_req
->nve
.type
,
775 NBP_SPL_WILDCARD
) != 0)
783 char zone
[35],object
[35],type
[35];
785 strncpy(zone
,nbp_req
->nve
.zone
.str
, nbp_req
->nve
.zone
.len
);
786 strncpy(object
,nbp_req
->nve
.object
.str
, nbp_req
->nve
.object
.len
);
787 strncpy(type
,nbp_req
->nve
.type
.str
, nbp_req
->nve
.type
.len
);
788 object
[nbp_req
->nve
.object
.len
] = '\0';
789 zone
[nbp_req
->nve
.zone
.len
] = '\0';
790 type
[nbp_req
->nve
.type
.len
] = '\0';
791 dPrintf(D_M_NBP_LOW
, D_L_USR2
,
792 ("nbp_search: found %s:%s@%s net:%d\n",
793 object
, type
, zone
, (int)nve_entry
->address
.net
));
795 #endif /* NBP_DEBUG */
796 if (nbp_req
->func
!= NULL
) {
797 if ((*(nbp_req
->func
))(nbp_req
, nve_entry
) != 0) {
798 /* errno expected to be set by func */
807 } /* nbp_search_nve */
809 static int nbp_lkup_reply (nbp_req
, nve_entry
)
810 register nbp_req_t
*nbp_req
;
811 register nve_entry_t
*nve_entry
;
813 register at_nbptuple_t
*tuple
;
814 register int tuple_size
, buf_len
;
815 register int obj_len
, type_len
;
818 /* size of the current tuple we want to write... */
819 tuple_size
= nve_entry
->object
.len
+ 1 + /* object */
820 nve_entry
->type
.len
+ 1 + /* type */
822 sizeof (at_inet_t
) + 1; /* addr + enum */
824 buf_len
= ((nbp_req
->flags
& NBP_WILD_MASK
) ? DDP_DATA_SIZE
:tuple_size
);
825 if (nbp_req
->response
== NULL
) {
826 if (nbp_setup_resp (nbp_req
, buf_len
) != 0)
827 /* errno expected to be set by nbp_setup_resp() */
831 if ((nbp_req
->space_unused
< tuple_size
) ||
832 (DATA_NBP(nbp_req
->response
)->tuple_count
== NBP_TUPLE_MAX
)) {
833 if (nbp_send_resp (nbp_req
) != 0)
835 if (nbp_setup_resp (nbp_req
, buf_len
) != 0)
839 /* At this point, we have a response buffer that can accommodate the
840 * tuple we want to write. Write it!
842 tuple
= (at_nbptuple_t
*)gbuf_wptr(nbp_req
->response
);
843 tuple
->enu_addr
.net
= htons(nve_entry
->address
.net
);
844 tuple
->enu_addr
.node
= nve_entry
->address
.node
;
845 tuple
->enu_addr
.socket
= nve_entry
->address
.socket
;
846 tuple
->enu_enum
= nve_entry
->enumerator
;
848 /* tuple is in the compressed (no "filler") format */
849 p
= (u_char
*)&tuple
->enu_entity
.object
;
850 obj_len
= nve_entry
->object
.len
+ 1;
851 bcopy(&nve_entry
->object
, p
, obj_len
);
853 type_len
= nve_entry
->type
.len
+ 1;
854 bcopy(&nve_entry
->type
, p
, type_len
);
859 nbp_req
->space_unused
-= tuple_size
;
860 gbuf_winc(nbp_req
->response
, tuple_size
);
862 /* increment the tuple count in header by 1 */
863 DATA_NBP(nbp_req
->response
)->tuple_count
++;
869 static int nbp_strcmp (str1
, str2
, embedded_wildcard
)
870 register at_nvestr_t
*str1
, *str2
;
871 register u_char embedded_wildcard
; /* If str1 may contain a character
872 * that's to be treated as an
873 * embedded wildcard, this character
874 * is it. Making this special case
875 * since for zone names, squiggly
876 * equal is not to be treated as a
882 register int reverse
= 0;
883 register int left_index
;
885 /* Embedded wildcard, if any, could only be in the first string (str1).
886 * returns 0 if two strings are equal (modulo case), -1 otherwise
889 if (str1
->len
== 0 || str2
->len
== 0) {
893 /* Wildcards are not allowed in str2.
895 * If str1 could potentially contain an embedded wildcard, since the
896 * embedded wildcard matches ZERO OR MORE characters, str1 can not be
897 * more than 1 character longer than str2.
899 * If str1 is not supposed to have embedded wildcards, the two strs
900 * must be of equal length.
902 if ((embedded_wildcard
&& (str2
->len
< (unsigned) (str1
->len
-1))) ||
903 (!embedded_wildcard
&& (str2
->len
!= str1
->len
))) {
907 for (i1
= i2
= left_index
= 0; (unsigned) i1
< str1
->len
;) {
911 if (embedded_wildcard
&& (ch1
==embedded_wildcard
)) {
912 /* hit the embedded wild card... start comparing from
913 * the other end of the string.
916 /* But, if embedded wildcard was the last character of
917 * the string, the two strings match, so return okay.
919 if (i1
== str1
->len
-1) {
929 nbp_upshift(&ch1
, 1);
930 nbp_upshift(&ch2
, 1);
938 if (i1
== left_index
) {
942 i1
++; i2
++; left_index
++;
949 static void nbp_setup_hdr (nbp_req
)
950 register nbp_req_t
*nbp_req
;
952 register at_ddp_t
*ddp
;
953 register at_nbp_t
*nbp
;
955 ddp
= DATA_DDP(nbp_req
->response
);
956 nbp
= DATA_NBP(nbp_req
->response
);
959 UAS_ASSIGN(ddp
->checksum
, 0);
960 ddp
->unused
= ddp
->hopcount
= 0;
962 switch(DATA_NBP(nbp_req
->request
)->control
) {
964 ddp
->dst_socket
= nbp_req
->nve
.address
.socket
;
965 ddp
->dst_node
= nbp_req
->nve
.address
.node
;
966 NET_ASSIGN_NOSWAP(ddp
->dst_net
, nbp_req
->nve
.address
.net
);
967 nbp
->control
= NBP_LKUP_REPLY
;
970 nbp
->at_nbp_id
= DATA_NBP(nbp_req
->request
)->at_nbp_id
;
975 static int nbp_setup_resp (nbp_req
, tuples_size
)
976 register nbp_req_t
*nbp_req
;
977 register int tuples_size
;
979 int buf_size
= tuples_size
+ DDP_X_HDR_SIZE
+ NBP_HDR_SIZE
;
980 nbp_req
->response
= gbuf_alloc(AT_WR_OFFSET
+buf_size
, PRI_MED
);
981 if (nbp_req
->response
== NULL
) {
985 gbuf_rinc(nbp_req
->response
, AT_WR_OFFSET
);
986 gbuf_wset(nbp_req
->response
, DDP_X_HDR_SIZE
+ NBP_HDR_SIZE
);
987 nbp_setup_hdr(nbp_req
);
989 DATA_NBP(nbp_req
->response
)->tuple_count
= 0;
990 nbp_req
->space_unused
= tuples_size
;
993 } /* nbp_setup_resp */
996 static int nbp_send_resp (nbp_req
)
997 register nbp_req_t
*nbp_req
;
1001 status
= ddp_output(&nbp_req
->response
, (at_socket
)NBP_SOCKET
, FALSE
);
1002 nbp_req
->response
= NULL
;
1007 void nbp_add_multicast(zone
, ifID
)
1011 char data
[ETHERNET_ADDR_LEN
];
1014 if (zone
->str
[0] == '*')
1019 strncpy(str
,zone
->str
,zone
->len
);
1020 str
[zone
->len
] = '\0';
1021 dPrintf(D_M_NBP_LOW
, D_L_USR3
,
1022 ("nbp_add_multi getting mc for %s\n", str
));
1024 zt_get_zmcast(ifID
, zone
, data
);
1025 if (FDDI_OR_TOKENRING(ifID
->aa_ifp
->if_type
))
1026 ddp_bit_reverse(data
);
1027 dPrintf(D_M_NBP_LOW
,D_L_USR3
,
1028 ("nbp_add_multi adding 0x%x%x port:%d ifID:0x%x if:%s\n",
1029 *(unsigned*)data
, (*(unsigned *)(data
+2))&0x0000ffff,
1030 i
, (u_int
) ifID
, ifID
->ifName
));
1032 bcopy((caddr_t
)data
, (caddr_t
)&ifID
->ZoneMcastAddr
, ETHERNET_ADDR_LEN
);
1033 (void)at_reg_mcast(ifID
, (caddr_t
)&ifID
->ZoneMcastAddr
);
1039 /* for SNMP, returns size in # of entries */
1041 register nve_entry_t
*nve
;
1044 for (nve
= TAILQ_FIRST(&name_registry
); nve
; nve
= TAILQ_NEXT(nve
, nve_link
), i
++)
1049 getNbpTable(p
, s
, c
)
1051 int s
; /* starting entry */
1052 int c
; /* # entries to copy */
1054 /* for SNMP, returns section of nbp table */
1056 register nve_entry_t
*nve
;
1058 static int nextNo
=0; /* entry that *next points to */
1059 static nve_entry_t
*next
= (nve_entry_t
*)NULL
;
1061 if (s
&& next
&& nextNo
== s
) {
1066 nve
= TAILQ_FIRST(&name_registry
);
1068 for ( ; nve
&& c
; nve
= TAILQ_NEXT(nve
, nve_link
), p
++,i
++) {
1070 p
->nbpe_object
= nve
->object
;
1071 p
->nbpe_type
= nve
->type
;
1079 next
= (nve_entry_t
*)NULL
;
1085 #define ZONES_PER_BLK 31 /* 31 fits within a 1k blk) */
1086 #define ZONE_BLK_SIZE ZONES_PER_BLK * sizeof(at_nvestr_t)
1088 int setLocalZones(newzones
, size
)
1089 at_nvestr_t
*newzones
;
1091 /* updates list of zones which are local to all active ports
1092 missing zones are not deleted, only missing zones are added.
1095 int bytesread
=0; /* #bytes read from tuple */
1098 at_nvestr_t
*pnve
, *pnew
= newzones
;
1101 if(!(lzones
= gbuf_alloc(ZONE_BLK_SIZE
, PRI_MED
)))
1103 gbuf_wset(lzones
,0);
1105 while (bytesread
< size
) { /* for each new zone */
1108 strncpy(str
,pnew
->str
,pnew
->len
);
1109 str
[pnew
->len
] = '\0';
1112 pnve
= (at_nvestr_t
*)gbuf_rptr(m
);
1114 for (i
=0; i
<lzonecnt
&& !dupe
; i
++,pnve
++) {
1115 if (i
&& !(i%ZONES_PER_BLK
))
1118 pnve
= (at_nvestr_t
*)gbuf_rptr(m
);
1122 if (pnew
->len
!= pnve
->len
)
1124 if (pnew
->len
> NBP_NVE_STR_SIZE
) {
1127 if (!strncmp(pnew
->str
, pnve
->str
, pnew
->len
)) {
1134 if (lzonecnt
&& !(lzonecnt%ZONES_PER_BLK
)) {
1135 if(!(gbuf_cont(m
) = gbuf_alloc(ZONE_BLK_SIZE
, PRI_MED
)))
1137 gbuf_wset(gbuf_cont(m
),0);
1138 pnve
= (at_nvestr_t
*)gbuf_rptr(gbuf_cont(m
));
1140 strncpy(pnve
->str
,pnew
->str
,pnew
->len
);
1141 pnve
->len
= pnew
->len
;
1144 bytesread
+= (pnew
->len
+1);
1145 pnew
= (at_nvestr_t
*) (((char *)pnew
) + pnew
->len
+ 1);
1147 /* showLocalZones1(); */
1160 if (!(pnve = getLocalZone(i))) {
1163 strncpy(str,pnve->str,pnve->len);
1164 str[pnve->len] = '\0';
1175 if (DEFAULT_ZONE(zone
))
1178 if (!(pnve
= getLocalZone(i
)))
1180 if (!nbp_strcmp(pnve
,zone
,0))
1187 #define NULL_PNVESTR (at_nvestr_t *) 0
1189 at_nvestr_t
*getLocalZone(zno
)
1190 int zno
; /* zone number in virtual list to
1191 return, 0 for first zone */
1192 /* returns pointer to a new local zone number zno,
1193 returns null when no zones left.
1197 ifz
.zone_index
= zno
;
1199 return(getRTRLocalZone(&ifz
));
1201 return(getSPLocalZone(zno
));
1205 at_nvestr_t
*getSPLocalZone(zno
)
1206 int zno
; /* zone number in virtual list to
1207 return, 0 for first zone */
1208 /* single port mode version */
1210 int curz
=0; /* current zone */
1216 pnve
= (at_nvestr_t
*)gbuf_rptr(m
);
1219 return(NULL_PNVESTR
);
1220 if ( zno
>=lzonecnt
)
1221 return(NULL_PNVESTR
);
1222 for (curz
=0; curz
<zno
; curz
++,pnve
++ ) {
1223 if ( curz
<lzonecnt
) {
1224 if (curz
&& !(curz%ZONES_PER_BLK
) ) {
1227 pnve
= (at_nvestr_t
*)gbuf_rptr(m
);
1230 return(NULL_PNVESTR
);
1233 if (pnve
->len
> NBP_NVE_STR_SIZE
) {
1234 return(NULL_PNVESTR
);
1238 return(NULL_PNVESTR
);
1243 /* The following functions are used in name registration and removal */
1245 int nbp_fillin_nve(entity
, nve
)
1246 at_entity_t
*entity
;
1251 if (entity
->object
.len
> NBP_NVE_STR_SIZE
||
1252 entity
->type
.len
> NBP_NVE_STR_SIZE
||
1253 entity
->zone
.len
> NBP_NVE_STR_SIZE
) {
1254 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1255 ("nbp_fillin_nve: bad str len\n"));
1260 nve
->zone
= entity
->zone
;
1262 if (!isZoneLocal(&entity
->zone
)) {
1266 /* if there's no zone, '*' gets filled in when entry is created */
1267 if (!DEFAULT_ZONE(&entity
->zone
))
1268 nve
->zone_hash
= nbp_strhash(&nve
->zone
);
1270 nve
->object
= entity
->object
;
1271 nve
->object_hash
= 0;
1272 if (entity
->object
.len
== 1 &&
1273 (entity
->object
.str
[0] == NBP_ORD_WILDCARD
||
1274 entity
->object
.str
[0] == NBP_SPL_WILDCARD
)) {
1275 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1276 ("nbp_fillin_nve: wildcard\n"));
1280 for (i
= 0; i
< entity
->object
.len
; i
++) {
1281 if (entity
->object
.str
[i
] == NBP_SPL_WILDCARD
) {
1282 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1283 ("nbp_fillin_nve: wildcard2\n"));
1288 nve
->object_hash
= nbp_strhash(&nve
->object
);
1290 nve
->type
= entity
->type
;
1292 if (entity
->type
.len
== 1 &&
1293 (entity
->type
.str
[0] == NBP_ORD_WILDCARD
||
1294 entity
->type
.str
[0] == NBP_SPL_WILDCARD
)) {
1298 for (i
= 0; i
< entity
->type
.len
; i
++) {
1299 if (entity
->type
.str
[i
] == NBP_SPL_WILDCARD
) {
1300 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1301 ("nbp_fillin_nve: wildcard3\n"));
1306 nve
->type_hash
= nbp_strhash(&nve
->type
);
1309 } /* nbp_fillin_nve */
1311 nve_entry_t
*nbp_find_nve(nve
)
1314 register nve_entry_t
*nve_entry
;
1316 TAILQ_FOREACH(nve_entry
, &name_registry
, nve_link
) {
1317 if (nve
->zone_hash
&&
1318 ((nve
->zone_hash
!= nve_entry
->zone_hash
) &&
1319 (nve
->zone_hash
!= hzonehash
))) {
1320 dPrintf(D_M_NBP_LOW
,D_L_USR4
,
1321 ("nbp_find_nve: no match for zone, req hash:%x\n",
1326 if ((nve
->object_hash
) &&
1327 (nve
->object_hash
!= nve_entry
->object_hash
))
1330 if ((nve
->type_hash
) &&
1331 (nve
->type_hash
!= nve_entry
->type_hash
))
1334 /* Found a match! */
1339 } /* nbp_find_nve */
1341 static int nbp_enum_gen (nve_entry
)
1342 register nve_entry_t
*nve_entry
;
1344 register int new_enum
= 0;
1345 register nve_entry_t
*ne
;
1348 TAILQ_FOREACH(ne
, &name_registry
, nve_link
) {
1349 if ((*(int *)&ne
->address
== *(int *)&nve_entry
->address
) &&
1350 (ne
->enumerator
== new_enum
)) {
1351 if (new_enum
== 255)
1352 return(EADDRNOTAVAIL
);
1360 nve_entry
->enumerator
= new_enum
;
1364 int nbp_new_nve_entry(nve_entry
, ifID
)
1365 nve_entry_t
*nve_entry
;
1369 nve_entry_t
*new_entry
;
1373 if (!(valid_at_addr((at_inet_t
*)&nve_entry
->address
))) {
1374 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1375 ("nbp_new_nve_entry: valid_at_addr\n"));
1378 if ((error
= nbp_enum_gen(nve_entry
)))
1381 nve_entry
->unique_nbp_id
= ++nbp_id_count
;
1383 /* Got an nve entry on hand.... allocate a buffer, copy the entry
1384 * on to it and stick it in the registry.
1386 if ((tag
= gbuf_alloc(sizeof(nve_entry_t
), PRI_HI
)) == NULL
){
1389 gbuf_wset(tag
, sizeof(nve_entry_t
));
1390 new_entry
= (nve_entry_t
*)gbuf_rptr(tag
);
1391 bcopy(nve_entry
, new_entry
, sizeof(nve_entry_t
));
1393 if (DEFAULT_ZONE(&nve_entry
->zone
)) {
1394 /* put actual zone name in entry instead of "*" */
1395 /* if single port mode and no zone name, then a router
1396 is down, so use pram zone name hint from elap cfg */
1397 if (!MULTIPORT_MODE
&& ifID_home
->ifZoneName
.str
[0] == '*') {
1398 zone
= &ifID_home
->startup_zone
;
1400 zone
= &ifID_home
->ifZoneName
;
1402 new_entry
->zone
= *zone
;
1403 if ( new_entry
->zone
.len
== 0 ) {
1404 new_entry
->zone
.str
[0] = '*';
1405 new_entry
->zone
.len
= 1;
1407 new_entry
->zone_hash
= nbp_strhash(&new_entry
->zone
);
1409 new_entry
->tag
= tag
;
1410 new_entry
->pid
= proc_selfpid();
1412 TAILQ_INSERT_TAIL(&name_registry
, new_entry
, nve_link
);
1413 at_state
.flags
|= AT_ST_NBP_CHANGED
;
1417 char zone
[35],object
[35],type
[35];
1418 strncpy(zone
,new_entry
->zone
.str
, new_entry
->zone
.len
);
1419 strncpy(object
,new_entry
->object
.str
, new_entry
->object
.len
);
1420 strncpy(type
,new_entry
->type
.str
, new_entry
->type
.len
);
1421 object
[new_entry
->object
.len
] = '\0';
1422 zone
[new_entry
->zone
.len
] = '\0';
1423 type
[new_entry
->type
.len
] = '\0';
1424 dPrintf(D_M_NBP_LOW
, D_L_USR4
,
1425 ("nbp_insert: adding %s:%s@%s addr:%d.%d ",
1427 new_entry
->address
.net
, new_entry
->address
.node
));
1429 #endif /* NBP_DEBUG */
1431 nbp_add_multicast(&new_entry
->zone
, ifID
);
1433 } /* nbp_new_nve_entry */
1435 void nbp_delete_entry (nve_entry
)
1436 nve_entry_t
*nve_entry
;
1438 TAILQ_REMOVE(&name_registry
, nve_entry
, nve_link
);
1439 gbuf_freem(nve_entry
->tag
);
1440 at_state
.flags
|= AT_ST_NBP_CHANGED
;
1443 /* Registration of an NBP entity in multihoming mode, from AIOCNBPREG
1445 int nbp_mh_reg(nbpP
)
1449 at_ifaddr_t
*ifID
= 0;
1451 int finished
= FALSE
;
1453 if (nbp_fillin_nve(&nbpP
->name
, &nve
) != 0) {
1455 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1456 ("nbp_mh_reg: bad tuple\n"));
1459 nve
.address
= nbpP
->addr
;
1460 nve
.ddptype
= nbpP
->ddptype
;
1462 if (DEFAULT_ZONE(&nbpP
->name
.zone
)) {
1463 /* multihoming mode with the default zone specified */
1465 /* now find the matching interfaces */
1466 TAILQ_FOREACH(ifID
, &at_ifQueueHd
, aa_link
) {
1467 if (nbpP
->addr
.net
|| nbpP
->addr
.node
) {
1468 /* if address is specified */
1469 if ((nbpP
->addr
.net
!= ifID
->ifThisNode
.s_net
||
1470 nbpP
->addr
.node
!= ifID
->ifThisNode
.s_node
))
1473 /* the address was specified, and
1474 we found the matching interface */
1477 /* address is not specified, so fill in
1478 the address for the interface */
1479 nve
.address
.net
= ifID
->ifThisNode
.s_net
;
1480 nve
.address
.node
= ifID
->ifThisNode
.s_node
;
1482 nve
.zone
= ifID
->ifZoneName
;
1483 nve
.zone_hash
= nbp_strhash(&nve
.zone
);
1484 if (nbp_find_nve(&nve
))
1486 if (nbp_new_nve_entry(&nve
, ifID
) == 0)
1489 if (registered
&& !nbpP
->addr
.net
&& !nbpP
->addr
.node
) {
1490 nbpP
->addr
.net
= ifID_home
->ifThisNode
.s_net
;
1491 nbpP
->addr
.node
= ifID_home
->ifThisNode
.s_node
;
1494 /* multihoming mode with a specific zone specified */
1495 /* see which segments (interfaces) are seeded for this zone */
1497 at_ifnames_t ifs_in_zone
;
1498 if (!(zno
= zt_find_zname(&nve
.zone
))) {
1499 dPrintf(D_M_NBP_LOW
, D_L_WARNING
,
1500 ("nbp_mh_reg: didn't find zone name\n"));
1503 getIfUsage(zno
-1, &ifs_in_zone
);
1505 /* now find the matching interfaces */
1506 TAILQ_FOREACH(ifID
, &at_ifQueueHd
, aa_link
) {
1507 if (!ifs_in_zone
.at_if
[ifID
->ifPort
])
1508 /* zone doesn't match */
1511 /* the zone matches, so unless the
1512 address is specified and doesn't
1513 match, we only need to do this once */
1516 if (nbpP
->addr
.net
|| nbpP
->addr
.node
) {
1517 /* address is specified */
1519 if ((nbpP
->addr
.net
!= ifID
->ifThisNode
.s_net
||
1520 nbpP
->addr
.node
!= ifID
->ifThisNode
.s_node
))
1523 /* the address was specified, and
1524 we found the matching interface */
1527 /* address is not specified, so fill in
1528 the address for the interface */
1529 nve
.address
.net
= ifID
->ifThisNode
.s_net
;
1530 nve
.address
.node
= ifID
->ifThisNode
.s_node
;
1532 if (nbp_find_nve(&nve
))
1534 if (nbp_new_nve_entry(&nve
, ifID
) == 0)
1536 if (registered
&& !nbpP
->addr
.net
&& !nbpP
->addr
.node
) {
1537 nbpP
->addr
.net
= ifID
->ifThisNode
.s_net
;
1538 nbpP
->addr
.node
= ifID
->ifThisNode
.s_node
;
1543 nbpP
->unique_nbp_id
= (registered
> 1)? 0: nve
.unique_nbp_id
;
1548 return(EADDRNOTAVAIL
);