X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/ff6e181ae92fc6f1e89841290f461d1f2f9badd9..e2fac8b15b12a7979f72090454d850e612fc5b13:/bsd/netat/ddp.c diff --git a/bsd/netat/ddp.c b/bsd/netat/ddp.c index 595307d59..31467fa6b 100644 --- a/bsd/netat/ddp.c +++ b/bsd/netat/ddp.c @@ -1,14 +1,19 @@ /* - * 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@ * * 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. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * 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. + * + * 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 @@ -18,12 +23,9 @@ * 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. @@ -52,13 +54,13 @@ #include #include +#include #include #include #include #include #include #include -#include #include #include #include @@ -67,13 +69,16 @@ #include #include #include +#include +#include + +#include /* 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 */ @@ -85,37 +90,35 @@ extern aarp_amt_array *aarp_table[]; 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; } @@ -387,10 +390,8 @@ void ddp_rem_if(ifID) ifa->ifa_addr = NULL; 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() */ @@ -423,7 +424,7 @@ void ddp_rem_if(ifID) */ /* *** 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; { @@ -443,17 +444,15 @@ int ot_ddp_check_socket(socket, 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 && @@ -465,7 +464,6 @@ void ddp_notify_nbp(socket, pid, ddptype) nbp_delete_entry(nve_entry); } } - ATENABLE(nve_lock, NVE_LOCK); } } /* ddp_notify_nbp */ @@ -480,12 +478,12 @@ static void fillin_pkt_chain(m) 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); @@ -493,7 +491,7 @@ static void fillin_pkt_chain(m) 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); } } } @@ -524,7 +522,7 @@ int ddp_output(mp, src_socket, src_addr_included) { 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; @@ -532,7 +530,7 @@ int ddp_output(mp, src_socket, src_addr_included) 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; @@ -574,7 +572,7 @@ int ddp_output(mp, src_socket, src_addr_included) at_ddp_stats.xmit_bytes += len; at_ddp_stats.xmit_packets++; - ddp->length = len; + DDPLEN_ASSIGN(ddp, len); ddp->hopcount = ddp->unused = 0; @@ -784,7 +782,8 @@ int ddp_output(mp, src_socket, src_addr_included) { /* 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; @@ -854,10 +853,10 @@ int ddp_output(mp, src_socket, src_addr_included) * 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 */ @@ -937,10 +936,10 @@ void ddp_input(mp, ifID) * {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", @@ -986,10 +985,10 @@ void ddp_input(mp, ifID) * 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); @@ -1010,7 +1009,7 @@ void ddp_input(mp, ifID) 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++; @@ -1137,7 +1136,7 @@ int ddp_router_output(mp, ifID, addr_type, router_net, router_node, enet_addr) { register at_ddp_t *ddp; struct atalk_addr at_dest; - int addr_flag; + int addr_flag = 0; char *addr = NULL; register gbuf_t *m; @@ -1148,6 +1147,7 @@ int ddp_router_output(mp, ifID, addr_type, router_net, router_node, enet_addr) } 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); @@ -1160,6 +1160,7 @@ int ddp_router_output(mp, ifID, addr_type, router_net, router_node, enet_addr) return EPROTOTYPE; } } +#endif /* keep some of the tests for now ####### */ @@ -1295,7 +1296,7 @@ int ddp_router_output(mp, ifID, addr_type, router_net, router_node, enet_addr) 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 */ @@ -1305,20 +1306,19 @@ int ddp_router_output(mp, ifID, addr_type, router_net, router_node, enet_addr) /*****************************************/ +#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) @@ -1326,8 +1326,6 @@ 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; @@ -1392,7 +1390,7 @@ int ddp_AURPfuncx(code, param, node) 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