/*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1998-2007 Apple Inc. All rights reserved.
*
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License"). You may not use this file except in compliance with the
- * License. Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
*
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
*
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
/*
- * Copyright (c) 1988, 1989, 1997, 1998 Apple Computer, Inc.
- *
* Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
*/
#include <netat/sysglue.h>
#include <netat/appletalk.h>
+#include <netat/at_pcb.h>
#include <netat/at_var.h>
#include <netat/ddp.h>
#include <netat/nbp.h>
#include <netat/rtmp.h>
#include <netat/routing_tables.h> /* router */
#include <netat/at_snmp.h>
-#include <netat/at_pcb.h>
#include <netat/debug.h>
/* reaching for DDP and NBP headers in the datagram */
static gbuf_t *lzones=0; /* head of local zones list */
static int lzonecnt=0; /* # zones stored in lzones */
static u_int hzonehash=0; /* hash val of home zone */
-static int nve_lock_pri;
static int nbp_lkup_reply(nbp_req_t *, nve_entry_t *);
static int nbp_strcmp(at_nvestr_t *, at_nvestr_t *, u_char);
static int nbp_setup_resp(nbp_req_t *, int);
static int nbp_send_resp(nbp_req_t *);
static int nbp_validate_n_hash(nbp_req_t *, int, int);
-static nve_entry_t *nbp_search_nve();
+static nve_entry_t *nbp_search_nve(nbp_req_t *, at_ifaddr_t *);
static int isZoneLocal(at_nvestr_t *);
+static int nbp_enum_gen (nve_entry_t *);
+static void nbp_setup_hdr (nbp_req_t *);
+static void nbp_upshift (u_char *, int);
+static u_char *nbp2zone(at_nbp_t *, u_char *);
/* macros */
#define NVE_LOCK nve_lock
-/* prototypes */
-void nbp_delete_entry();
-extern int at_reg_mcast();
-extern at_nvestr_t *getRTRLocalZone(zone_usage_t *);
-extern void nbp_add_multicast( at_nvestr_t *, at_ifaddr_t *);
static long nbp_id_count = 0;
-/*
- * Copy src to string dst of size siz. At most siz-1 characters
- * will be copied. Always NUL terminates (unless siz == 0).
- * Returns strlen(src); if retval >= siz, truncation occurred.
- */
-__private_extern__ size_t
-strlcpy(char *dst, const char *src, size_t siz)
-{
- char *d = dst;
- const char *s = src;
- size_t n = siz;
-
- /* Copy as many bytes as will fit */
- if (n != 0 && --n != 0) {
- do {
- if ((*d++ = *s++) == 0)
- break;
- } while (--n != 0);
- }
-
- /* Not enough room in dst, add NUL and traverse rest of src */
- if (n == 0) {
- if (siz != 0)
- *d = '\0'; /* NUL-terminate dst */
- while (*s++)
- ;
- }
-
- return(s - src - 1); /* count does not include NUL */
-}
-
-
-
void sethzonehash(elapp)
at_ifaddr_t *elapp;
{
}
}
-void nbp_shutdown()
+void nbp_shutdown(void)
{
/* delete all NVE's and release buffers */
register nve_entry_t *nve_entry, *nve_next;
{
register at_ddp_t *ddp = DATA_DDP(m);
register at_nbp_t *nbp = DATA_NBP(m);
- register nve_entry_t *nve_entry, *next_nve;
register RT_entry *rt;
register int ddpSent = FALSE; /* true if we re-sent this pkt (don't free) */
struct etalk_addr mcastAddr;
/*### LD 01/18/94 Check if the dest is also the home zone. */
- p = nbp2zone(nbp, gbuf_wptr(m));
- if ((p == NULL) || !(zno = zt_find_zname(p))) {
+ p = nbp2zone(nbp, (u_char *)gbuf_wptr(m));
+ if ((p == NULL) || !(zno = zt_find_zname((at_nvestr_t *)p))) {
dPrintf(D_M_NBP,D_L_WARNING,
("nbp_input: FWDRQ:zone not found\n"));
break;
}
if (isZoneLocal((at_nvestr_t*)p))
zhome = TRUE; /* one of our ports is in destination zone */
- if (!zt_get_zmcast(ifID, p, &mcastAddr)) {
+ if (!zt_get_zmcast(ifID, (at_nvestr_t*)p, (char *)&mcastAddr)) {
dPrintf(D_M_NBP,D_L_ERROR,
("nbp_input: FDWREQ:zt_get_zmcast error\n"));
break;
}
if (FDDI_OR_TOKENRING(ifID->aa_ifp->if_type))
- ddp_bit_reverse(&mcastAddr);
- ddp_router_output(m, ifID, ET_ADDR,NULL,NULL, &mcastAddr);
+ ddp_bit_reverse((unsigned char *)&mcastAddr);
+ ddp_router_output(m, ifID, ET_ADDR, 0, 0, &mcastAddr);
ddpSent = TRUE;
}
break;
register int i;
register gbuf_t *m2, *m3;
register int fromUs = FALSE;
- register at_socket ourSkt; /* originating skt */
+ register at_socket ourSkt = 0; /* originating skt */
/* for router & MH local only */
if ((!(MULTIHOME_MODE && FROM_US(ddp))) && !ROUTING_MODE) {
break;
}
- p = nbp2zone(nbp, gbuf_wptr(m));
- if ((p == NULL) || !(zno = zt_find_zname(p))) {
+ p = nbp2zone(nbp, (u_char *)gbuf_wptr(m));
+ if ((p == NULL) || !(zno = zt_find_zname((at_nvestr_t *)p))) {
break;
}
if (MULTIHOME_MODE && ifID->ifRouterState == NO_ROUTER) {
nbp->tuple[0].enu_addr.socket = ourSkt;
ddp->src_socket = NBP_SOCKET;
}
+#if DEBUG
else
dPrintf(D_M_NBP, D_L_USR3,
("nbp_input: BRREQ: not from us\n"));
-
+#endif /* DEBUG */
dPrintf(D_M_NBP, D_L_USR3,
("nbp_input dist:%d\n", rt->NetDist));
if (rt->NetDist == 0) { /* if direct connect, *we* do the LKUP */
nbp->control = NBP_LKUP;
NET_ASSIGN(ddp->dst_net, 0);
ddp->dst_node = 255;
- if (!zt_get_zmcast(ifID, p, &mcastAddr)) {
+ if (!zt_get_zmcast(ifID, (at_nvestr_t*)p, (char *)&mcastAddr)) {
dPrintf(D_M_NBP,D_L_ERROR,
("nbp_input: BRRQ:zt_get_zmcast error\n"));
break;
}
if (FDDI_OR_TOKENRING(ifID->aa_ifp->if_type))
- ddp_bit_reverse(&mcastAddr);
- ddp_router_output(m2, ifID, ET_ADDR, NULL, NULL, &mcastAddr);
+ ddp_bit_reverse((unsigned char *)&mcastAddr);
+ ddp_router_output(m2, ifID, ET_ADDR, 0, 0, &mcastAddr);
}
else { /* else fwd to router */
ddp->dst_node = 0;
if (checkLocal && !isZoneLocal(zone)) {
char str[35];
- strlcpy(str,zone->str,sizeof(str));
+ strlcpy((char *)str,(char *)zone->str,sizeof(str));
dPrintf(D_M_NBP_LOW,D_L_WARNING,
("nbp_val_n_hash bad zone: %s\n", str));
errno = EINVAL;
}
} else{
for (i = part_wild = 0; (unsigned) i<object->len; i++) {
- if (object->str[i] == NBP_SPL_WILDCARD)
- if (wild_ok)
+ if (object->str[i] == NBP_SPL_WILDCARD) {
+ if (wild_ok) {
if (part_wild) {
dPrintf(D_M_NBP_LOW, D_L_WARNING,
("nbp_val_n_hash: too many parts wild\n"));
return (-1);
} else
part_wild++;
- else {
+ } else {
dPrintf(D_M_NBP_LOW, D_L_WARNING,
("nbp_val_n_hash: wild not okay2\n"));
errno = EINVAL;
return (-1);
}
+ }
nbp_req->nve.object.str[i] = object->str[i];
}
if (!part_wild)
}
} else {
for (i = part_wild = 0; (unsigned) i<type->len; i++) {
- if (type->str[i] == NBP_SPL_WILDCARD)
- if (wild_ok)
+ if (type->str[i] == NBP_SPL_WILDCARD) {
+ if (wild_ok) {
if (part_wild) {
dPrintf(D_M_NBP_LOW, D_L_WARNING,
("nbp_val_n_hash: too many parts wild2\n"));
return (-1);
} else
part_wild++;
- else {
+ } else {
errno = EINVAL;
return (-1);
}
+ }
nbp_req->nve.type.str[i] = type->str[i];
}
if (!part_wild)
} un;
for (i=0; (unsigned) i < nvestr->len; i+=sizeof(int)) {
- len = MIN((nvestr->len-i), sizeof(int));
+ len = MIN((size_t)(nvestr->len-i), sizeof(int));
if (len == sizeof(int))
bcopy(&(nvestr->str[i]), &un, sizeof(un));
else {
ifID->ifThisNode.s_net));
continue;
}
+#if DEBUG
if (ifID)
dPrintf(D_M_NBP, D_L_USR4,
("nbp search ifID (%d) & req net (%d) equal\n",
nve_entry->address.net,
ifID->ifThisNode.s_net));
+#endif /* DEBUG */
}
}
at_ifaddr_t *ifID;
{
char data[ETHERNET_ADDR_LEN];
- int i;
if (zone->str[0] == '*')
return;
{
char str[35];
- strlcpy(str,zone->str,sizeof(str));
+ strlcpy((char *)str,(char *)zone->str,sizeof(str));
dPrintf(D_M_NBP_LOW, D_L_USR3,
("nbp_add_multi getting mc for %s\n", str));
}
zt_get_zmcast(ifID, zone, data);
if (FDDI_OR_TOKENRING(ifID->aa_ifp->if_type))
- ddp_bit_reverse(data);
+ ddp_bit_reverse((unsigned char *)data);
dPrintf(D_M_NBP_LOW,D_L_USR3,
("nbp_add_multi adding 0x%x%x port:%d ifID:0x%x if:%s\n",
*(unsigned*)data, (*(unsigned *)(data+2))&0x0000ffff,
- i, (u_int) ifID, ifID->ifName));
+ /*i*/0, (u_int) ifID, ifID->ifName));
bcopy((caddr_t)data, (caddr_t)&ifID->ZoneMcastAddr, ETHERNET_ADDR_LEN);
(void)at_reg_mcast(ifID, (caddr_t)&ifID->ZoneMcastAddr);
}
-
-getNbpTableSize()
+int
+getNbpTableSize(void)
/* for SNMP, returns size in # of entries */
{
return(i);
}
+int
getNbpTable(p, s, c)
snmpNbpEntry_t *p;
int s; /* starting entry */
next = (nve_entry_t*)NULL;
nextNo = 0;
}
+
+ return 0;
}
while (bytesread < size) { /* for each new zone */
{
char str[35];
- strlcpy(str,pnew->str,sizeof(str));
+ strlcpy((char *)str,(char *)pnew->str,sizeof(str));
}
m = lzones;
pnve = (at_nvestr_t*)gbuf_rptr(m);
dupe = 0;
for (i=0; i<lzonecnt && !dupe; i++,pnve++) {
- if (i && !(i%ZONES_PER_BLK))
+ if (i && !(i%ZONES_PER_BLK)) {
if (gbuf_cont(m)) {
m = gbuf_cont(m);
pnve = (at_nvestr_t*)gbuf_rptr(m);
}
else
break;
+ }
if (pnew->len != pnve->len)
continue;
if (pnew->len > NBP_NVE_STR_SIZE) {
return(0);
}
- if (!strncmp(pnew->str, pnve->str, pnew->len)) {
+ if (!strncmp((char *)pnew->str, (char *)pnve->str, pnew->len)) {
dupe=1;
continue;
}
gbuf_wset(gbuf_cont(m),0);
pnve = (at_nvestr_t*)gbuf_rptr(gbuf_cont(m));
}
- strlcpy(pnve->str,pnew->str,sizeof(pnve->str));
+ strlcpy((char *)pnve->str,(char *)pnew->str,sizeof(pnve->str));
pnve->len = pnew->len;
lzonecnt++;
}
*********/
+int
isZoneLocal(zone)
at_nvestr_t *zone;
{