/*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-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) 1987, 1988, 1989 Apple Computer, Inc.
- *
- *
* Modified for MP, 1996 by Tuyen Nguyen
* Added AURP support, April 8, 1996 by Tuyen Nguyen
* 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/ep.h>
#include <netat/nbp.h>
#include <netat/rtmp.h>
#include <netat/zip.h>
-#include <netat/at_pcb.h>
#include <netat/routing_tables.h>
#include <netat/at_snmp.h>
#include <netat/aurp.h>
#include <netat/at_aarp.h>
#include <netat/adsp.h>
#include <netat/adsp_internal.h>
+#include <netat/at_pat.h>
+#include <netat/atp.h>
+
+#include <net/kpi_protocol.h>
/* globals */
/* Queue of LAP interfaces which have registered themselves with DDP */
struct at_ifQueueHd at_ifQueueHd;
-extern at_state_t at_state;
extern TAILQ_HEAD(name_registry, _nve_) name_registry;
snmpStats_t snmpStats; /* snmp ddp & echo stats */
extern at_ifaddr_t at_interfaces[];
/* routing mode special */
-void (*ddp_AURPsendx)();
+void (*ddp_AURPsendx)(void) = NULL;
at_ifaddr_t *aurp_ifID = 0;
-extern pktsIn,pktsOut;
-int pktsDropped,pktsHome;
-atlock_t ddpall_lock;
-atlock_t ddpinp_lock;
+
+int pktsIn = 0;
+int pktsOut = 0;
+int pktsDropped = 0;
+int pktsHome = 0;
extern int *atp_pidM;
extern int *adsp_pidM;
extern struct atpcb *atp_inputQ[];
extern CCB *adsp_inputQ[];
-at_ifaddr_t *forUs(at_ddp_t *);
+static void fillin_pkt_chain(gbuf_t *);
+static int ot_ddp_check_socket(unsigned char ,int pid);
-void ddp_input(), ddp_notify_nbp();
-
-extern void routing_needed();
-extern void ddp_brt_sweep();
struct {
- void (*func)();
+ ddp_handler_func func;
} ddp_handler[256];
-void init_ddp_handler()
+void init_ddp_handler(void)
{
bzero(ddp_handler, sizeof(ddp_handler));
}
void add_ddp_handler(ddp_socket, input_func)
u_char ddp_socket;
- void (*input_func)();
+ ddp_handler_func input_func;
{
ddp_handler[ddp_socket].func = input_func;
}
/* un-do processing done in SIOCSIFADDR */
if (ifa->ifa_addr) {
- int s = splnet();
- TAILQ_REMOVE(&ifID->aa_ifp->if_addrhead, ifa, ifa_link);
+ ifnet_lock_exclusive(ifID->aa_ifp);
+ if_detach_ifa(ifID->aa_ifp, ifa);
ifa->ifa_addr = NULL;
- splx(s);
+ ifnet_lock_done(ifID->aa_ifp);
}
- if (ifID->at_dl_tag) {
-/* dlil_detach_protocol(ifID->at_dl_tag); */
- ether_detach_at(ifID->aa_ifp);
- ifID->at_dl_tag = 0;
+ if (ifID->at_was_attached == 0 && ifID->aa_ifp != NULL) {
+ (void)proto_unplumb(PF_APPLETALK, ifID->aa_ifp);
}
/* un-do processing done in ddp_add_if() */
*/
/* *** Do we still need to do this? *** */
-int ot_ddp_check_socket(socket, pid)
+static int ot_ddp_check_socket(socket, pid)
unsigned char socket;
int pid;
{
return(cnt);
}
-void ddp_notify_nbp(socket, pid, ddptype)
- unsigned char socket;
- int pid;
- unsigned char ddptype; /* not used */
+void ddp_notify_nbp(
+ unsigned char socket,
+ int pid,
+ __unused unsigned char ddptype)
{
- extern int nve_lock;
nve_entry_t *nve_entry, *nve_next;
if (at_state.flags & AT_ST_STARTED) {
/* *** NBP_CLOSE_NOTE processing (from ddp_nbp.c) *** */
- ATDISABLE(nve_lock, NVE_LOCK);
for ((nve_entry = TAILQ_FIRST(&name_registry)); nve_entry; nve_entry = nve_next) {
nve_next = TAILQ_NEXT(nve_entry, nve_link);
if ((at_socket)socket == nve_entry->address.socket &&
nbp_delete_entry(nve_entry);
}
}
- ATENABLE(nve_lock, NVE_LOCK);
}
} /* ddp_notify_nbp */
if (UAS_VALUE(ddp->checksum)) {
tmp = ddp_checksum(m, 4);
- UAS_ASSIGN(ddp->checksum, tmp);
+ UAS_ASSIGN_HTON(ddp->checksum, tmp);
}
for (tmp_m=gbuf_next(tmp_m); tmp_m; tmp_m=gbuf_next(tmp_m)) {
tmp_ddp = (at_ddp_t *)gbuf_rptr(tmp_m);
- tmp_ddp->length = gbuf_msgsize(tmp_m);
+ DDPLEN_ASSIGN(tmp_ddp, gbuf_msgsize(tmp_m));
tmp_ddp->hopcount =
tmp_ddp->unused = 0;
NET_NET(tmp_ddp->src_net, ddp->src_net);
tmp_ddp->src_socket = ddp->src_socket;
if (UAS_VALUE(tmp_ddp->checksum)) {
tmp = ddp_checksum(tmp_m, 4);
- UAS_ASSIGN(tmp_ddp->checksum, tmp);
+ UAS_ASSIGN_HTON(ddp->checksum, tmp);
}
}
}
{
register at_ifaddr_t *ifID = ifID_home, *ifIDTmp = NULL;
register at_ddp_t *ddp;
- register ddp_brt_t *brt;
+ register ddp_brt_t *brt = NULL;
register at_net_al dst_net;
register int len;
struct atalk_addr at_dest;
int loop = 0;
int error = 0;
int addr_type;
- u_char addr_flag;
+ u_char addr_flag = 0;
char *addr = NULL;
register gbuf_t *m;
at_ddp_stats.xmit_bytes += len;
at_ddp_stats.xmit_packets++;
- ddp->length = len;
+ DDPLEN_ASSIGN(ddp, len);
ddp->hopcount =
ddp->unused = 0;
{ /* begin block */
struct etalk_addr dest_addr;
struct atalk_addr dest_at_addr;
- int loop = TRUE; /* flag to aarp to loopback (default) */
+
+ loop = TRUE; /* flag to aarp to loopback (default) */
m = *mp;
* it doesn't know net#, consequently can't do
* AMT_LOOKUP. That task left to aarp now.
*/
- aarp_send_data(m,ifID,&dest_at_addr, loop);
+ aarp_send_data(m,ifID, &dest_at_addr, loop);
break;
case ET_ADDR :
- pat_output(ifID, m, &dest_addr, 0);
+ pat_output(ifID, m, (unsigned char *)&dest_addr, 0);
break;
}
} /* end block */
* {extended ddp, ... }.
*/
ddp = (at_ddp_t *)gbuf_rptr(mp);
- len = ddp->length;
+ len = DDPLEN_VALUE(ddp);
if (msgsize != len) {
- if ((unsigned) msgsize > len) {
+ if (msgsize > len) {
if (len < DDP_X_HDR_SIZE) {
dPrintf(D_M_DDP, D_L_ERROR,
("Length problems, ddp length %d, buffer length %d",
* if the checksum is true, then upstream wants us to calc
*/
if (UAS_VALUE(ddp->checksum) &&
- (UAS_VALUE(ddp->checksum) != ddp_checksum(mp, 4))) {
+ (UAS_VALUE_NTOH(ddp->checksum) != ddp_checksum(mp, 4))) {
dPrintf(D_M_DDP, D_L_WARNING,
("Checksum error on incoming pkt, calc 0x%x, exp 0x%x",
- ddp_checksum(mp, 4), UAS_VALUE(ddp->checksum)));
+ ddp_checksum(mp, 4), UAS_VALUE_NTOH(ddp->checksum)));
snmpStats.dd_checkSum++;
at_ddp_stats.rcv_bad_checksum++;
gbuf_freem(mp);
for packets of this type on a raw DDP socket *** */
if (ddp_handler[socket].func) {
dPrintf(D_M_DDP,D_L_INPUT,
- ("ddp_input: skt %d hdnlr:0x%x\n",
+ ("ddp_input: skt %u hdnlr:0x%p\n",
(u_int) socket, ddp_handler[socket].func));
pktsHome++;
snmpStats.dd_inLocal++;
if (sbappendaddr(&((gref->atpcb_socket)->so_rcv),
(struct sockaddr *)&ddp_in,
- mp, 0) == 0)
- gbuf_freem(mp);
- else
+ mp, 0, NULL) != 0) {
sorwakeup(gref->atpcb_socket);
+ }
} else {
atalk_putnext(gref, mp);
}
{
register at_ddp_t *ddp;
struct atalk_addr at_dest;
- int addr_flag;
+ int addr_flag = 0;
char *addr = NULL;
register gbuf_t *m;
}
ddp = (at_ddp_t *)gbuf_rptr(mp);
+#ifdef AURP_SUPPORT
if (ifID->ifFlags & AT_IFF_AURP) { /* AURP link? */
if (ddp_AURPsendx) {
fillin_pkt_chain(mp);
return EPROTOTYPE;
}
}
+#endif
/* keep some of the tests for now ####### */
aarp_send_data(m,ifID,&dest_at_addr, loop);
break;
case ET_ADDR :
- pat_output(ifID, m, &dest_addr, 0);
+ pat_output(ifID, m, (unsigned char *)&dest_addr, 0);
break;
}
} /* end block */
/*****************************************/
+#ifdef AURP_SUPPORT
+
void rt_delete(NetStop, NetStart)
unsigned short NetStop;
unsigned short NetStart;
{
RT_entry *found;
- int s;
- ATDISABLE(s, ddpinp_lock);
if ((found = rt_bdelete(NetStop, NetStart)) != 0) {
bzero(found, sizeof(RT_entry));
found->right = RT_table_freelist;
RT_table_freelist = found;
}
- ATENABLE(s, ddpinp_lock);
}
int ddp_AURPfuncx(code, param, node)
void *param;
unsigned char node;
{
- extern void rtmp_timeout();
- extern void rtmp_send_port();
at_ifaddr_t *ifID;
int k;
return 0;
}
-
+#endif
/* checks to see if address of packet is for one of our interfaces
returns *ifID if it's for us, NULL if not