michael@0: /*- michael@0: * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. michael@0: * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved. michael@0: * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions are met: michael@0: * michael@0: * a) Redistributions of source code must retain the above copyright notice, michael@0: * this list of conditions and the following disclaimer. michael@0: * michael@0: * b) Redistributions in binary form must reproduce the above copyright michael@0: * notice, this list of conditions and the following disclaimer in michael@0: * the documentation and/or other materials provided with the distribution. michael@0: * michael@0: * c) Neither the name of Cisco Systems, Inc. nor the names of its michael@0: * contributors may be used to endorse or promote products derived michael@0: * from this software without specific prior written permission. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, michael@0: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE michael@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE michael@0: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR michael@0: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF michael@0: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS michael@0: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN michael@0: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) michael@0: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF michael@0: * THE POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: michael@0: #ifdef __FreeBSD__ michael@0: #include michael@0: __FBSDID("$FreeBSD: head/sys/netinet/sctp_bsd_addr.c 258765 2013-11-30 12:51:19Z tuexen $"); michael@0: #endif michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #if defined(ANDROID) michael@0: #include michael@0: #include michael@0: #else michael@0: #if defined(__FreeBSD__) michael@0: #include michael@0: #endif michael@0: #endif michael@0: michael@0: /* Declare all of our malloc named types */ michael@0: #ifndef __Panda__ michael@0: MALLOC_DEFINE(SCTP_M_MAP, "sctp_map", "sctp asoc map descriptor"); michael@0: MALLOC_DEFINE(SCTP_M_STRMI, "sctp_stri", "sctp stream in array"); michael@0: MALLOC_DEFINE(SCTP_M_STRMO, "sctp_stro", "sctp stream out array"); michael@0: MALLOC_DEFINE(SCTP_M_ASC_ADDR, "sctp_aadr", "sctp asconf address"); michael@0: MALLOC_DEFINE(SCTP_M_ASC_IT, "sctp_a_it", "sctp asconf iterator"); michael@0: MALLOC_DEFINE(SCTP_M_AUTH_CL, "sctp_atcl", "sctp auth chunklist"); michael@0: MALLOC_DEFINE(SCTP_M_AUTH_KY, "sctp_atky", "sctp auth key"); michael@0: MALLOC_DEFINE(SCTP_M_AUTH_HL, "sctp_athm", "sctp auth hmac list"); michael@0: MALLOC_DEFINE(SCTP_M_AUTH_IF, "sctp_athi", "sctp auth info"); michael@0: MALLOC_DEFINE(SCTP_M_STRESET, "sctp_stre", "sctp stream reset"); michael@0: MALLOC_DEFINE(SCTP_M_CMSG, "sctp_cmsg", "sctp CMSG buffer"); michael@0: MALLOC_DEFINE(SCTP_M_COPYAL, "sctp_cpal", "sctp copy all"); michael@0: MALLOC_DEFINE(SCTP_M_VRF, "sctp_vrf", "sctp vrf struct"); michael@0: MALLOC_DEFINE(SCTP_M_IFA, "sctp_ifa", "sctp ifa struct"); michael@0: MALLOC_DEFINE(SCTP_M_IFN, "sctp_ifn", "sctp ifn struct"); michael@0: MALLOC_DEFINE(SCTP_M_TIMW, "sctp_timw", "sctp time block"); michael@0: MALLOC_DEFINE(SCTP_M_MVRF, "sctp_mvrf", "sctp mvrf pcb list"); michael@0: MALLOC_DEFINE(SCTP_M_ITER, "sctp_iter", "sctp iterator control"); michael@0: MALLOC_DEFINE(SCTP_M_SOCKOPT, "sctp_socko", "sctp socket option"); michael@0: MALLOC_DEFINE(SCTP_M_MCORE, "sctp_mcore", "sctp mcore queue"); michael@0: #endif michael@0: michael@0: /* Global NON-VNET structure that controls the iterator */ michael@0: struct iterator_control sctp_it_ctl; michael@0: michael@0: #if !defined(__FreeBSD__) michael@0: static void michael@0: sctp_cleanup_itqueue(void) michael@0: { michael@0: struct sctp_iterator *it, *nit; michael@0: michael@0: TAILQ_FOREACH_SAFE(it, &sctp_it_ctl.iteratorhead, sctp_nxt_itr, nit) { michael@0: if (it->function_atend != NULL) { michael@0: (*it->function_atend) (it->pointer, it->val); michael@0: } michael@0: TAILQ_REMOVE(&sctp_it_ctl.iteratorhead, it, sctp_nxt_itr); michael@0: SCTP_FREE(it, SCTP_M_ITER); michael@0: } michael@0: } michael@0: #endif michael@0: #if defined(__Userspace__) michael@0: /*__Userspace__ TODO if we use thread based iterator michael@0: * then the implementation of wakeup will need to change. michael@0: * Currently we are using timeo_cond for ident so_timeo michael@0: * but that is not sufficient if we need to use another ident michael@0: * like wakeup(&sctppcbinfo.iterator_running); michael@0: */ michael@0: #endif michael@0: michael@0: void michael@0: sctp_wakeup_iterator(void) michael@0: { michael@0: #if defined(SCTP_PROCESS_LEVEL_LOCKS) michael@0: #if defined(__Userspace_os_Windows) michael@0: WakeAllConditionVariable(&sctp_it_ctl.iterator_wakeup); michael@0: #else michael@0: pthread_cond_broadcast(&sctp_it_ctl.iterator_wakeup); michael@0: #endif michael@0: #else michael@0: wakeup(&sctp_it_ctl.iterator_running); michael@0: #endif michael@0: } michael@0: michael@0: #if defined(__Userspace__) michael@0: static void * michael@0: #else michael@0: static void michael@0: #endif michael@0: sctp_iterator_thread(void *v SCTP_UNUSED) michael@0: { michael@0: SCTP_IPI_ITERATOR_WQ_LOCK(); michael@0: /* In FreeBSD this thread never terminates. */ michael@0: #if defined(__FreeBSD__) michael@0: for (;;) { michael@0: #else michael@0: while ((sctp_it_ctl.iterator_flags & SCTP_ITERATOR_MUST_EXIT) == 0) { michael@0: #endif michael@0: #if !defined(__Userspace__) michael@0: msleep(&sctp_it_ctl.iterator_running, michael@0: #if defined(__FreeBSD__) michael@0: &sctp_it_ctl.ipi_iterator_wq_mtx, michael@0: #elif defined(__APPLE__) || defined(__Userspace_os_Darwin) michael@0: sctp_it_ctl.ipi_iterator_wq_mtx, michael@0: #endif michael@0: 0, "waiting_for_work", 0); michael@0: #else michael@0: #if defined(__Userspace_os_Windows) michael@0: SleepConditionVariableCS(&sctp_it_ctl.iterator_wakeup, &sctp_it_ctl.ipi_iterator_wq_mtx, INFINITE); michael@0: #else michael@0: pthread_cond_wait(&sctp_it_ctl.iterator_wakeup, &sctp_it_ctl.ipi_iterator_wq_mtx); michael@0: #endif michael@0: #endif michael@0: #if !defined(__FreeBSD__) michael@0: if (sctp_it_ctl.iterator_flags & SCTP_ITERATOR_MUST_EXIT) { michael@0: break; michael@0: } michael@0: #endif michael@0: sctp_iterator_worker(); michael@0: } michael@0: #if !defined(__FreeBSD__) michael@0: /* Now this thread needs to be terminated */ michael@0: sctp_cleanup_itqueue(); michael@0: sctp_it_ctl.iterator_flags |= SCTP_ITERATOR_EXITED; michael@0: SCTP_IPI_ITERATOR_WQ_UNLOCK(); michael@0: #if defined(__Userspace__) michael@0: sctp_wakeup_iterator(); michael@0: return (NULL); michael@0: #else michael@0: wakeup(&sctp_it_ctl.iterator_flags); michael@0: thread_terminate(current_thread()); michael@0: #ifdef INVARIANTS michael@0: panic("Hmm. thread_terminate() continues..."); michael@0: #endif michael@0: #endif michael@0: #endif michael@0: } michael@0: michael@0: void michael@0: sctp_startup_iterator(void) michael@0: { michael@0: if (sctp_it_ctl.thread_proc) { michael@0: /* You only get one */ michael@0: return; michael@0: } michael@0: /* Initialize global locks here, thus only once. */ michael@0: SCTP_ITERATOR_LOCK_INIT(); michael@0: SCTP_IPI_ITERATOR_WQ_INIT(); michael@0: TAILQ_INIT(&sctp_it_ctl.iteratorhead); michael@0: #if defined(__FreeBSD__) michael@0: #if __FreeBSD_version <= 701000 michael@0: kthread_create(sctp_iterator_thread, michael@0: #else michael@0: kproc_create(sctp_iterator_thread, michael@0: #endif michael@0: (void *)NULL, michael@0: &sctp_it_ctl.thread_proc, michael@0: RFPROC, michael@0: SCTP_KTHREAD_PAGES, michael@0: SCTP_KTRHEAD_NAME); michael@0: #elif defined(__APPLE__) michael@0: kernel_thread_start((thread_continue_t)sctp_iterator_thread, NULL, &sctp_it_ctl.thread_proc); michael@0: #elif defined(__Userspace__) michael@0: #if defined(__Userspace_os_Windows) michael@0: if ((sctp_it_ctl.thread_proc = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&sctp_iterator_thread, NULL, 0, NULL)) == NULL) { michael@0: #else michael@0: if (pthread_create(&sctp_it_ctl.thread_proc, NULL, &sctp_iterator_thread, NULL)) { michael@0: #endif michael@0: SCTP_PRINTF("ERROR: Creating sctp_iterator_thread failed.\n"); michael@0: } michael@0: #endif michael@0: } michael@0: michael@0: #ifdef INET6 michael@0: michael@0: #if defined(__Userspace__) michael@0: /* __Userspace__ TODO. struct in6_ifaddr is defined in sys/netinet6/in6_var.h michael@0: ip6_use_deprecated is defined as int ip6_use_deprecated = 1; in /src/sys/netinet6/in6_proto.c michael@0: */ michael@0: void michael@0: sctp_gather_internal_ifa_flags(struct sctp_ifa *ifa) michael@0: { michael@0: return; /* stub */ michael@0: } michael@0: #else michael@0: void michael@0: sctp_gather_internal_ifa_flags(struct sctp_ifa *ifa) michael@0: { michael@0: struct in6_ifaddr *ifa6; michael@0: michael@0: ifa6 = (struct in6_ifaddr *)ifa->ifa; michael@0: ifa->flags = ifa6->ia6_flags; michael@0: if (!MODULE_GLOBAL(ip6_use_deprecated)) { michael@0: if (ifa->flags & michael@0: IN6_IFF_DEPRECATED) { michael@0: ifa->localifa_flags |= SCTP_ADDR_IFA_UNUSEABLE; michael@0: } else { michael@0: ifa->localifa_flags &= ~SCTP_ADDR_IFA_UNUSEABLE; michael@0: } michael@0: } else { michael@0: ifa->localifa_flags &= ~SCTP_ADDR_IFA_UNUSEABLE; michael@0: } michael@0: if (ifa->flags & michael@0: (IN6_IFF_DETACHED | michael@0: IN6_IFF_ANYCAST | michael@0: IN6_IFF_NOTREADY)) { michael@0: ifa->localifa_flags |= SCTP_ADDR_IFA_UNUSEABLE; michael@0: } else { michael@0: ifa->localifa_flags &= ~SCTP_ADDR_IFA_UNUSEABLE; michael@0: } michael@0: } michael@0: #endif /* __Userspace__ */ michael@0: #endif /* INET6 */ michael@0: michael@0: michael@0: #if !defined(__Userspace__) michael@0: static uint32_t michael@0: sctp_is_desired_interface_type(struct ifnet *ifn) michael@0: { michael@0: int result; michael@0: michael@0: /* check the interface type to see if it's one we care about */ michael@0: #if defined(__APPLE__) michael@0: switch(ifnet_type(ifn)) { michael@0: #else michael@0: switch (ifn->if_type) { michael@0: #endif michael@0: case IFT_ETHER: michael@0: case IFT_ISO88023: michael@0: case IFT_ISO88024: michael@0: case IFT_ISO88025: michael@0: case IFT_ISO88026: michael@0: case IFT_STARLAN: michael@0: case IFT_P10: michael@0: case IFT_P80: michael@0: case IFT_HY: michael@0: case IFT_FDDI: michael@0: case IFT_XETHER: michael@0: case IFT_ISDNBASIC: michael@0: case IFT_ISDNPRIMARY: michael@0: case IFT_PTPSERIAL: michael@0: case IFT_OTHER: michael@0: case IFT_PPP: michael@0: case IFT_LOOP: michael@0: case IFT_SLIP: michael@0: case IFT_GIF: michael@0: case IFT_L2VLAN: michael@0: case IFT_STF: michael@0: #if !defined(__APPLE__) michael@0: case IFT_IP: michael@0: case IFT_IPOVERCDLC: michael@0: case IFT_IPOVERCLAW: michael@0: case IFT_PROPVIRTUAL: /* NetGraph Virtual too */ michael@0: case IFT_VIRTUALIPADDRESS: michael@0: #endif michael@0: result = 1; michael@0: break; michael@0: default: michael@0: result = 0; michael@0: } michael@0: michael@0: return (result); michael@0: } michael@0: #endif michael@0: michael@0: #if defined(__APPLE__) michael@0: int michael@0: sctp_is_vmware_interface(struct ifnet *ifn) michael@0: { michael@0: return (strncmp(ifnet_name(ifn), "vmnet", 5) == 0); michael@0: } michael@0: #endif michael@0: michael@0: #if defined(__Userspace_os_Windows) michael@0: #ifdef MALLOC michael@0: #undef MALLOC michael@0: #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x)) michael@0: #endif michael@0: #ifdef FREE michael@0: #undef FREE michael@0: #define FREE(x) HeapFree(GetProcessHeap(), 0, (x)) michael@0: #endif michael@0: static void michael@0: sctp_init_ifns_for_vrf(int vrfid) michael@0: { michael@0: #if defined(INET) || defined(INET6) michael@0: struct ifaddrs *ifa; michael@0: struct sctp_ifa *sctp_ifa; michael@0: DWORD Err, AdapterAddrsSize; michael@0: PIP_ADAPTER_ADDRESSES pAdapterAddrs, pAdapt; michael@0: PIP_ADAPTER_UNICAST_ADDRESS pUnicast; michael@0: #endif michael@0: michael@0: #ifdef INET michael@0: AdapterAddrsSize = 0; michael@0: michael@0: if ((Err = GetAdaptersAddresses(AF_INET, 0, NULL, NULL, &AdapterAddrsSize)) != 0) { michael@0: if ((Err != ERROR_BUFFER_OVERFLOW) && (Err != ERROR_INSUFFICIENT_BUFFER)) { michael@0: SCTP_PRINTF("GetAdaptersV4Addresses() sizing failed with error code %d\n", Err); michael@0: SCTP_PRINTF("err = %d; AdapterAddrsSize = %d\n", Err, AdapterAddrsSize); michael@0: return; michael@0: } michael@0: } michael@0: michael@0: /* Allocate memory from sizing information */ michael@0: if ((pAdapterAddrs = (PIP_ADAPTER_ADDRESSES) GlobalAlloc(GPTR, AdapterAddrsSize)) == NULL) { michael@0: SCTP_PRINTF("Memory allocation error!\n"); michael@0: return; michael@0: } michael@0: /* Get actual adapter information */ michael@0: if ((Err = GetAdaptersAddresses(AF_INET, 0, NULL, pAdapterAddrs, &AdapterAddrsSize)) != ERROR_SUCCESS) { michael@0: SCTP_PRINTF("GetAdaptersV4Addresses() failed with error code %d\n", Err); michael@0: return; michael@0: } michael@0: /* Enumerate through each returned adapter and save its information */ michael@0: for (pAdapt = pAdapterAddrs; pAdapt; pAdapt = pAdapt->Next) { michael@0: if (pAdapt->IfType == IF_TYPE_IEEE80211 || pAdapt->IfType == IF_TYPE_ETHERNET_CSMACD) { michael@0: for (pUnicast = pAdapt->FirstUnicastAddress; pUnicast; pUnicast = pUnicast->Next) { michael@0: if (IN4_ISLINKLOCAL_ADDRESS(&(((struct sockaddr_in *)(pUnicast->Address.lpSockaddr))->sin_addr))) { michael@0: continue; michael@0: } michael@0: ifa = (struct ifaddrs*)malloc(sizeof(struct ifaddrs)); michael@0: ifa->ifa_name = strdup(pAdapt->AdapterName); michael@0: ifa->ifa_flags = pAdapt->Flags; michael@0: ifa->ifa_addr = (struct sockaddr *)malloc(sizeof(struct sockaddr_in)); michael@0: memcpy(ifa->ifa_addr, pUnicast->Address.lpSockaddr, sizeof(struct sockaddr_in)); michael@0: michael@0: sctp_ifa = sctp_add_addr_to_vrf(0, michael@0: ifa, michael@0: pAdapt->IfIndex, michael@0: (pAdapt->IfType == IF_TYPE_IEEE80211)?MIB_IF_TYPE_ETHERNET:pAdapt->IfType, michael@0: ifa->ifa_name, michael@0: (void *)ifa, michael@0: ifa->ifa_addr, michael@0: ifa->ifa_flags, michael@0: 0); michael@0: if (sctp_ifa) { michael@0: sctp_ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: if (pAdapterAddrs) michael@0: FREE(pAdapterAddrs); michael@0: #endif michael@0: #ifdef INET6 michael@0: AdapterAddrsSize = 0; michael@0: michael@0: if ((Err = GetAdaptersAddresses(AF_INET6, 0, NULL, NULL, &AdapterAddrsSize)) != 0) { michael@0: if ((Err != ERROR_BUFFER_OVERFLOW) && (Err != ERROR_INSUFFICIENT_BUFFER)) { michael@0: SCTP_PRINTF("GetAdaptersV6Addresses() sizing failed with error code %d\n", Err); michael@0: SCTP_PRINTF("err = %d; AdapterAddrsSize = %d\n", Err, AdapterAddrsSize); michael@0: return; michael@0: } michael@0: } michael@0: /* Allocate memory from sizing information */ michael@0: if ((pAdapterAddrs = (PIP_ADAPTER_ADDRESSES) GlobalAlloc(GPTR, AdapterAddrsSize)) == NULL) { michael@0: SCTP_PRINTF("Memory allocation error!\n"); michael@0: return; michael@0: } michael@0: /* Get actual adapter information */ michael@0: if ((Err = GetAdaptersAddresses(AF_INET6, 0, NULL, pAdapterAddrs, &AdapterAddrsSize)) != ERROR_SUCCESS) { michael@0: SCTP_PRINTF("GetAdaptersV6Addresses() failed with error code %d\n", Err); michael@0: return; michael@0: } michael@0: /* Enumerate through each returned adapter and save its information */ michael@0: for (pAdapt = pAdapterAddrs; pAdapt; pAdapt = pAdapt->Next) { michael@0: if (pAdapt->IfType == IF_TYPE_IEEE80211 || pAdapt->IfType == IF_TYPE_ETHERNET_CSMACD) { michael@0: for (pUnicast = pAdapt->FirstUnicastAddress; pUnicast; pUnicast = pUnicast->Next) { michael@0: ifa = (struct ifaddrs*)malloc(sizeof(struct ifaddrs)); michael@0: ifa->ifa_name = strdup(pAdapt->AdapterName); michael@0: ifa->ifa_flags = pAdapt->Flags; michael@0: ifa->ifa_addr = (struct sockaddr *)malloc(sizeof(struct sockaddr_in6)); michael@0: memcpy(ifa->ifa_addr, pUnicast->Address.lpSockaddr, sizeof(struct sockaddr_in6)); michael@0: sctp_ifa = sctp_add_addr_to_vrf(0, michael@0: ifa, michael@0: pAdapt->Ipv6IfIndex, michael@0: (pAdapt->IfType == IF_TYPE_IEEE80211)?MIB_IF_TYPE_ETHERNET:pAdapt->IfType, michael@0: ifa->ifa_name, michael@0: (void *)ifa, michael@0: ifa->ifa_addr, michael@0: ifa->ifa_flags, michael@0: 0); michael@0: if (sctp_ifa) { michael@0: sctp_ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: if (pAdapterAddrs) michael@0: FREE(pAdapterAddrs); michael@0: #endif michael@0: } michael@0: #elif defined(__Userspace__) michael@0: static void michael@0: sctp_init_ifns_for_vrf(int vrfid) michael@0: { michael@0: #if defined(INET) || defined(INET6) michael@0: int rc; michael@0: struct ifaddrs *ifa = NULL; michael@0: struct sctp_ifa *sctp_ifa; michael@0: uint32_t ifa_flags; michael@0: michael@0: rc = getifaddrs(&g_interfaces); michael@0: if (rc != 0) { michael@0: return; michael@0: } michael@0: for (ifa = g_interfaces; ifa; ifa = ifa->ifa_next) { michael@0: if (ifa->ifa_addr == NULL) { michael@0: continue; michael@0: } michael@0: #if !defined(INET) michael@0: if (ifa->ifa_addr->sa_family != AF_INET6) { michael@0: /* non inet6 skip */ michael@0: continue; michael@0: } michael@0: #elif !defined(INET6) michael@0: if (ifa->ifa_addr->sa_family != AF_INET) { michael@0: /* non inet skip */ michael@0: continue; michael@0: } michael@0: #else michael@0: if ((ifa->ifa_addr->sa_family != AF_INET) && (ifa->ifa_addr->sa_family != AF_INET6)) { michael@0: /* non inet/inet6 skip */ michael@0: continue; michael@0: } michael@0: #endif michael@0: #if defined(INET6) michael@0: if ((ifa->ifa_addr->sa_family == AF_INET6) && michael@0: IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr)) { michael@0: /* skip unspecifed addresses */ michael@0: continue; michael@0: } michael@0: #endif michael@0: #if defined(INET) michael@0: if (ifa->ifa_addr->sa_family == AF_INET && michael@0: ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr == 0) { michael@0: continue; michael@0: } michael@0: #endif michael@0: ifa_flags = 0; michael@0: sctp_ifa = sctp_add_addr_to_vrf(vrfid, michael@0: ifa, michael@0: if_nametoindex(ifa->ifa_name), michael@0: 0, michael@0: ifa->ifa_name, michael@0: (void *)ifa, michael@0: ifa->ifa_addr, michael@0: ifa_flags, michael@0: 0); michael@0: if (sctp_ifa) { michael@0: sctp_ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE; michael@0: } michael@0: } michael@0: #endif michael@0: } michael@0: #endif michael@0: michael@0: #if defined(__APPLE__) michael@0: static void michael@0: sctp_init_ifns_for_vrf(int vrfid) michael@0: { michael@0: /* Here we must apply ANY locks needed by the michael@0: * IFN we access and also make sure we lock michael@0: * any IFA that exists as we float through the michael@0: * list of IFA's michael@0: */ michael@0: struct ifnet **ifnetlist; michael@0: uint32_t i, j, count; michael@0: char name[SCTP_IFNAMSIZ]; michael@0: struct ifnet *ifn; michael@0: struct ifaddr **ifaddrlist; michael@0: struct ifaddr *ifa; michael@0: struct in6_ifaddr *ifa6; michael@0: struct sctp_ifa *sctp_ifa; michael@0: uint32_t ifa_flags; michael@0: michael@0: if (ifnet_list_get(IFNET_FAMILY_ANY, &ifnetlist, &count) != 0) { michael@0: return; michael@0: } michael@0: for (i = 0; i < count; i++) { michael@0: ifn = ifnetlist[i]; michael@0: if (SCTP_BASE_SYSCTL(sctp_ignore_vmware_interfaces) && sctp_is_vmware_interface(ifn)) { michael@0: continue; michael@0: } michael@0: if (sctp_is_desired_interface_type(ifn) == 0) { michael@0: /* non desired type */ michael@0: continue; michael@0: } michael@0: if (ifnet_get_address_list(ifn, &ifaddrlist) != 0) { michael@0: continue; michael@0: } michael@0: for (j = 0; ifaddrlist[j] != NULL; j++) { michael@0: ifa = ifaddrlist[j]; michael@0: if (ifa->ifa_addr == NULL) { michael@0: continue; michael@0: } michael@0: if ((ifa->ifa_addr->sa_family != AF_INET) && (ifa->ifa_addr->sa_family != AF_INET6)) { michael@0: /* non inet/inet6 skip */ michael@0: continue; michael@0: } michael@0: if (ifa->ifa_addr->sa_family == AF_INET6) { michael@0: if (IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr)) { michael@0: /* skip unspecifed addresses */ michael@0: continue; michael@0: } michael@0: } else { michael@0: if (((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr == INADDR_ANY) { michael@0: continue; michael@0: } michael@0: } michael@0: if (ifa->ifa_addr->sa_family == AF_INET6) { michael@0: ifa6 = (struct in6_ifaddr *)ifa; michael@0: ifa_flags = ifa6->ia6_flags; michael@0: } else { michael@0: ifa_flags = 0; michael@0: } michael@0: snprintf(name, SCTP_IFNAMSIZ, "%s%d", ifnet_name(ifn), ifnet_unit(ifn)); michael@0: sctp_ifa = sctp_add_addr_to_vrf(vrfid, michael@0: (void *)ifn, michael@0: ifnet_index(ifn), michael@0: ifnet_type(ifn), michael@0: name, michael@0: (void *)ifa, michael@0: ifa->ifa_addr, michael@0: ifa_flags, michael@0: 0); michael@0: if (sctp_ifa) { michael@0: sctp_ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE; michael@0: } michael@0: } michael@0: ifnet_free_address_list(ifaddrlist); michael@0: } michael@0: ifnet_list_free(ifnetlist); michael@0: } michael@0: #endif michael@0: michael@0: #if defined(__FreeBSD__) michael@0: static void michael@0: sctp_init_ifns_for_vrf(int vrfid) michael@0: { michael@0: /* Here we must apply ANY locks needed by the michael@0: * IFN we access and also make sure we lock michael@0: * any IFA that exists as we float through the michael@0: * list of IFA's michael@0: */ michael@0: struct ifnet *ifn; michael@0: struct ifaddr *ifa; michael@0: struct sctp_ifa *sctp_ifa; michael@0: uint32_t ifa_flags; michael@0: #ifdef INET6 michael@0: struct in6_ifaddr *ifa6; michael@0: #endif michael@0: michael@0: IFNET_RLOCK(); michael@0: TAILQ_FOREACH(ifn, &MODULE_GLOBAL(ifnet), if_list) { michael@0: if (sctp_is_desired_interface_type(ifn) == 0) { michael@0: /* non desired type */ michael@0: continue; michael@0: } michael@0: #if (__FreeBSD_version >= 803000 && __FreeBSD_version < 900000) || __FreeBSD_version > 900000 michael@0: IF_ADDR_RLOCK(ifn); michael@0: #else michael@0: IF_ADDR_LOCK(ifn); michael@0: #endif michael@0: TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) { michael@0: if (ifa->ifa_addr == NULL) { michael@0: continue; michael@0: } michael@0: switch (ifa->ifa_addr->sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: if (((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr == 0) { michael@0: continue; michael@0: } michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: if (IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr)) { michael@0: /* skip unspecifed addresses */ michael@0: continue; michael@0: } michael@0: break; michael@0: #endif michael@0: default: michael@0: continue; michael@0: } michael@0: switch (ifa->ifa_addr->sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: ifa_flags = 0; michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: ifa6 = (struct in6_ifaddr *)ifa; michael@0: ifa_flags = ifa6->ia6_flags; michael@0: break; michael@0: #endif michael@0: default: michael@0: ifa_flags = 0; michael@0: break; michael@0: } michael@0: sctp_ifa = sctp_add_addr_to_vrf(vrfid, michael@0: (void *)ifn, michael@0: ifn->if_index, michael@0: ifn->if_type, michael@0: ifn->if_xname, michael@0: (void *)ifa, michael@0: ifa->ifa_addr, michael@0: ifa_flags, michael@0: 0); michael@0: if (sctp_ifa) { michael@0: sctp_ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE; michael@0: } michael@0: } michael@0: #if (__FreeBSD_version >= 803000 && __FreeBSD_version < 900000) || __FreeBSD_version > 900000 michael@0: IF_ADDR_RUNLOCK(ifn); michael@0: #else michael@0: IF_ADDR_UNLOCK(ifn); michael@0: #endif michael@0: } michael@0: IFNET_RUNLOCK(); michael@0: } michael@0: #endif michael@0: michael@0: void michael@0: sctp_init_vrf_list(int vrfid) michael@0: { michael@0: if (vrfid > SCTP_MAX_VRF_ID) michael@0: /* can't do that */ michael@0: return; michael@0: michael@0: /* Don't care about return here */ michael@0: (void)sctp_allocate_vrf(vrfid); michael@0: michael@0: /* Now we need to build all the ifn's michael@0: * for this vrf and there addresses michael@0: */ michael@0: sctp_init_ifns_for_vrf(vrfid); michael@0: } michael@0: michael@0: void michael@0: sctp_addr_change(struct ifaddr *ifa, int cmd) michael@0: { michael@0: #if defined(__Userspace__) michael@0: return; michael@0: #else michael@0: uint32_t ifa_flags = 0; michael@0: /* BSD only has one VRF, if this changes michael@0: * we will need to hook in the right michael@0: * things here to get the id to pass to michael@0: * the address managment routine. michael@0: */ michael@0: if (SCTP_BASE_VAR(first_time) == 0) { michael@0: /* Special test to see if my ::1 will showup with this */ michael@0: SCTP_BASE_VAR(first_time) = 1; michael@0: sctp_init_ifns_for_vrf(SCTP_DEFAULT_VRFID); michael@0: } michael@0: michael@0: if ((cmd != RTM_ADD) && (cmd != RTM_DELETE)) { michael@0: /* don't know what to do with this */ michael@0: return; michael@0: } michael@0: michael@0: if (ifa->ifa_addr == NULL) { michael@0: return; michael@0: } michael@0: if (sctp_is_desired_interface_type(ifa->ifa_ifp) == 0) { michael@0: /* non desired type */ michael@0: return; michael@0: } michael@0: switch (ifa->ifa_addr->sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: if (((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr == 0) { michael@0: return; michael@0: } michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: ifa_flags = ((struct in6_ifaddr *)ifa)->ia6_flags; michael@0: if (IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr)) { michael@0: /* skip unspecifed addresses */ michael@0: return; michael@0: } michael@0: break; michael@0: #endif michael@0: default: michael@0: /* non inet/inet6 skip */ michael@0: return; michael@0: } michael@0: if (cmd == RTM_ADD) { michael@0: (void)sctp_add_addr_to_vrf(SCTP_DEFAULT_VRFID, (void *)ifa->ifa_ifp, michael@0: #if defined(__APPLE__) michael@0: ifnet_index(ifa->ifa_ifp), ifnet_type(ifa->ifa_ifp), ifnet_name(ifa->ifa_ifp), michael@0: #else michael@0: ifa->ifa_ifp->if_index, ifa->ifa_ifp->if_type, ifa->ifa_ifp->if_xname, michael@0: #endif michael@0: (void *)ifa, ifa->ifa_addr, ifa_flags, 1); michael@0: } else { michael@0: michael@0: sctp_del_addr_from_vrf(SCTP_DEFAULT_VRFID, ifa->ifa_addr, michael@0: #if defined(__APPLE__) michael@0: ifnet_index(ifa->ifa_ifp), michael@0: ifnet_name(ifa->ifa_ifp)); michael@0: #else michael@0: ifa->ifa_ifp->if_index, michael@0: ifa->ifa_ifp->if_xname); michael@0: #endif michael@0: michael@0: /* We don't bump refcount here so when it completes michael@0: * the final delete will happen. michael@0: */ michael@0: } michael@0: #endif michael@0: } michael@0: michael@0: #if defined(__FreeBSD__) michael@0: void michael@0: sctp_add_or_del_interfaces(int (*pred)(struct ifnet *), int add) michael@0: { michael@0: struct ifnet *ifn; michael@0: struct ifaddr *ifa; michael@0: michael@0: IFNET_RLOCK(); michael@0: TAILQ_FOREACH(ifn, &MODULE_GLOBAL(ifnet), if_list) { michael@0: if (!(*pred)(ifn)) { michael@0: continue; michael@0: } michael@0: TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) { michael@0: sctp_addr_change(ifa, add ? RTM_ADD : RTM_DELETE); michael@0: } michael@0: } michael@0: IFNET_RUNLOCK(); michael@0: } michael@0: #endif michael@0: #if defined(__APPLE__) michael@0: void michael@0: sctp_add_or_del_interfaces(int (*pred)(struct ifnet *), int add) michael@0: { michael@0: struct ifnet **ifnetlist; michael@0: struct ifaddr **ifaddrlist; michael@0: uint32_t i, j, count; michael@0: michael@0: if (ifnet_list_get(IFNET_FAMILY_ANY, &ifnetlist, &count) != 0) { michael@0: return; michael@0: } michael@0: for (i = 0; i < count; i++) { michael@0: if (!(*pred)(ifnetlist[i])) { michael@0: continue; michael@0: } michael@0: if (ifnet_get_address_list(ifnetlist[i], &ifaddrlist) != 0) { michael@0: continue; michael@0: } michael@0: for (j = 0; ifaddrlist[j] != NULL; j++) { michael@0: sctp_addr_change(ifaddrlist[j], add ? RTM_ADD : RTM_DELETE); michael@0: } michael@0: ifnet_free_address_list(ifaddrlist); michael@0: } michael@0: ifnet_list_free(ifnetlist); michael@0: return; michael@0: } michael@0: #endif michael@0: michael@0: struct mbuf * michael@0: sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header, michael@0: int how, int allonebuf, int type) michael@0: { michael@0: struct mbuf *m = NULL; michael@0: #if defined(__Userspace__) michael@0: michael@0: /* michael@0: * __Userspace__ michael@0: * Using m_clget, which creates and mbuf and a cluster and michael@0: * hooks those together. michael@0: * TODO: This does not yet have functionality for jumbo packets. michael@0: * michael@0: */ michael@0: michael@0: int mbuf_threshold; michael@0: if (want_header) { michael@0: MGETHDR(m, how, type); michael@0: } else { michael@0: MGET(m, how, type); michael@0: } michael@0: if (m == NULL) { michael@0: return (NULL); michael@0: } michael@0: if (allonebuf == 0) michael@0: mbuf_threshold = SCTP_BASE_SYSCTL(sctp_mbuf_threshold_count); michael@0: else michael@0: mbuf_threshold = 1; michael@0: michael@0: michael@0: if ((int)space_needed > (((mbuf_threshold - 1) * MLEN) + MHLEN)) { michael@0: MCLGET(m, how); michael@0: if (m == NULL) { michael@0: return (NULL); michael@0: } michael@0: michael@0: if (SCTP_BUF_IS_EXTENDED(m) == 0) { michael@0: sctp_m_freem(m); michael@0: return (NULL); michael@0: } michael@0: } michael@0: SCTP_BUF_LEN(m) = 0; michael@0: SCTP_BUF_NEXT(m) = SCTP_BUF_NEXT_PKT(m) = NULL; michael@0: michael@0: #if defined(__Userspace__) michael@0: /* __Userspace__ michael@0: * Check if anything need to be done to ensure logging works michael@0: */ michael@0: #endif michael@0: #ifdef SCTP_MBUF_LOGGING michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) { michael@0: if (SCTP_BUF_IS_EXTENDED(m)) { michael@0: sctp_log_mb(m, SCTP_MBUF_IALLOC); michael@0: } michael@0: } michael@0: #endif michael@0: #elif defined(__FreeBSD__) && __FreeBSD_version > 602000 michael@0: m = m_getm2(NULL, space_needed, how, type, want_header ? M_PKTHDR : 0); michael@0: if (m == NULL) { michael@0: /* bad, no memory */ michael@0: return (m); michael@0: } michael@0: if (allonebuf) { michael@0: int siz; michael@0: if (SCTP_BUF_IS_EXTENDED(m)) { michael@0: siz = SCTP_BUF_EXTEND_SIZE(m); michael@0: } else { michael@0: if (want_header) michael@0: siz = MHLEN; michael@0: else michael@0: siz = MLEN; michael@0: } michael@0: if (siz < space_needed) { michael@0: m_freem(m); michael@0: return (NULL); michael@0: } michael@0: } michael@0: if (SCTP_BUF_NEXT(m)) { michael@0: sctp_m_freem( SCTP_BUF_NEXT(m)); michael@0: SCTP_BUF_NEXT(m) = NULL; michael@0: } michael@0: #ifdef SCTP_MBUF_LOGGING michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) { michael@0: if (SCTP_BUF_IS_EXTENDED(m)) { michael@0: sctp_log_mb(m, SCTP_MBUF_IALLOC); michael@0: } michael@0: } michael@0: #endif michael@0: #else michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 601000 michael@0: int aloc_size; michael@0: int index = 0; michael@0: #endif michael@0: int mbuf_threshold; michael@0: if (want_header) { michael@0: MGETHDR(m, how, type); michael@0: } else { michael@0: MGET(m, how, type); michael@0: } michael@0: if (m == NULL) { michael@0: return (NULL); michael@0: } michael@0: if (allonebuf == 0) michael@0: mbuf_threshold = SCTP_BASE_SYSCTL(sctp_mbuf_threshold_count); michael@0: else michael@0: mbuf_threshold = 1; michael@0: michael@0: michael@0: if (space_needed > (((mbuf_threshold - 1) * MLEN) + MHLEN)) { michael@0: #if defined(__FreeBSD__) && __FreeBSD_version >= 601000 michael@0: try_again: michael@0: index = 4; michael@0: if (space_needed <= MCLBYTES) { michael@0: aloc_size = MCLBYTES; michael@0: } else { michael@0: aloc_size = MJUMPAGESIZE; michael@0: index = 5; michael@0: } michael@0: m_cljget(m, how, aloc_size); michael@0: if (m == NULL) { michael@0: return (NULL); michael@0: } michael@0: if (SCTP_BUF_IS_EXTENDED(m) == 0) { michael@0: if ((aloc_size != MCLBYTES) && michael@0: (allonebuf == 0)) { michael@0: aloc_size -= 10; michael@0: goto try_again; michael@0: } michael@0: sctp_m_freem(m); michael@0: return (NULL); michael@0: } michael@0: #else michael@0: MCLGET(m, how); michael@0: if (m == NULL) { michael@0: return (NULL); michael@0: } michael@0: if (SCTP_BUF_IS_EXTENDED(m) == 0) { michael@0: sctp_m_freem(m); michael@0: return (NULL); michael@0: } michael@0: #endif michael@0: } michael@0: SCTP_BUF_LEN(m) = 0; michael@0: SCTP_BUF_NEXT(m) = SCTP_BUF_NEXT_PKT(m) = NULL; michael@0: #ifdef SCTP_MBUF_LOGGING michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) { michael@0: if (SCTP_BUF_IS_EXTENDED(m)) { michael@0: sctp_log_mb(m, SCTP_MBUF_IALLOC); michael@0: } michael@0: } michael@0: #endif michael@0: #endif michael@0: return (m); michael@0: } michael@0: michael@0: michael@0: #ifdef SCTP_PACKET_LOGGING michael@0: void michael@0: sctp_packet_log(struct mbuf *m) michael@0: { michael@0: int *lenat, thisone; michael@0: void *copyto; michael@0: uint32_t *tick_tock; michael@0: int length; michael@0: int total_len; michael@0: int grabbed_lock = 0; michael@0: int value, newval, thisend, thisbegin; michael@0: /* michael@0: * Buffer layout. michael@0: * -sizeof this entry (total_len) michael@0: * -previous end (value) michael@0: * -ticks of log (ticks) michael@0: * o -ip packet michael@0: * o -as logged michael@0: * - where this started (thisbegin) michael@0: * x <--end points here michael@0: */ michael@0: length = SCTP_HEADER_LEN(m); michael@0: total_len = SCTP_SIZE32((length + (4 * sizeof(int)))); michael@0: /* Log a packet to the buffer. */ michael@0: if (total_len> SCTP_PACKET_LOG_SIZE) { michael@0: /* Can't log this packet I have not a buffer big enough */ michael@0: return; michael@0: } michael@0: if (length < (int)(SCTP_MIN_V4_OVERHEAD + sizeof(struct sctp_cookie_ack_chunk))) { michael@0: return; michael@0: } michael@0: atomic_add_int(&SCTP_BASE_VAR(packet_log_writers), 1); michael@0: try_again: michael@0: if (SCTP_BASE_VAR(packet_log_writers) > SCTP_PKTLOG_WRITERS_NEED_LOCK) { michael@0: SCTP_IP_PKTLOG_LOCK(); michael@0: grabbed_lock = 1; michael@0: again_locked: michael@0: value = SCTP_BASE_VAR(packet_log_end); michael@0: newval = SCTP_BASE_VAR(packet_log_end) + total_len; michael@0: if (newval >= SCTP_PACKET_LOG_SIZE) { michael@0: /* we wrapped */ michael@0: thisbegin = 0; michael@0: thisend = total_len; michael@0: } else { michael@0: thisbegin = SCTP_BASE_VAR(packet_log_end); michael@0: thisend = newval; michael@0: } michael@0: if (!(atomic_cmpset_int(&SCTP_BASE_VAR(packet_log_end), value, thisend))) { michael@0: goto again_locked; michael@0: } michael@0: } else { michael@0: value = SCTP_BASE_VAR(packet_log_end); michael@0: newval = SCTP_BASE_VAR(packet_log_end) + total_len; michael@0: if (newval >= SCTP_PACKET_LOG_SIZE) { michael@0: /* we wrapped */ michael@0: thisbegin = 0; michael@0: thisend = total_len; michael@0: } else { michael@0: thisbegin = SCTP_BASE_VAR(packet_log_end); michael@0: thisend = newval; michael@0: } michael@0: if (!(atomic_cmpset_int(&SCTP_BASE_VAR(packet_log_end), value, thisend))) { michael@0: goto try_again; michael@0: } michael@0: } michael@0: /* Sanity check */ michael@0: if (thisend >= SCTP_PACKET_LOG_SIZE) { michael@0: SCTP_PRINTF("Insanity stops a log thisbegin:%d thisend:%d writers:%d lock:%d end:%d\n", michael@0: thisbegin, michael@0: thisend, michael@0: SCTP_BASE_VAR(packet_log_writers), michael@0: grabbed_lock, michael@0: SCTP_BASE_VAR(packet_log_end)); michael@0: SCTP_BASE_VAR(packet_log_end) = 0; michael@0: goto no_log; michael@0: michael@0: } michael@0: lenat = (int *)&SCTP_BASE_VAR(packet_log_buffer)[thisbegin]; michael@0: *lenat = total_len; michael@0: lenat++; michael@0: *lenat = value; michael@0: lenat++; michael@0: tick_tock = (uint32_t *)lenat; michael@0: lenat++; michael@0: *tick_tock = sctp_get_tick_count(); michael@0: copyto = (void *)lenat; michael@0: thisone = thisend - sizeof(int); michael@0: lenat = (int *)&SCTP_BASE_VAR(packet_log_buffer)[thisone]; michael@0: *lenat = thisbegin; michael@0: if (grabbed_lock) { michael@0: SCTP_IP_PKTLOG_UNLOCK(); michael@0: grabbed_lock = 0; michael@0: } michael@0: m_copydata(m, 0, length, (caddr_t)copyto); michael@0: no_log: michael@0: if (grabbed_lock) { michael@0: SCTP_IP_PKTLOG_UNLOCK(); michael@0: } michael@0: atomic_subtract_int(&SCTP_BASE_VAR(packet_log_writers), 1); michael@0: } michael@0: michael@0: michael@0: int michael@0: sctp_copy_out_packet_log(uint8_t *target, int length) michael@0: { michael@0: /* We wind through the packet log starting at michael@0: * start copying up to length bytes out. michael@0: * We return the number of bytes copied. michael@0: */ michael@0: int tocopy, this_copy; michael@0: int *lenat; michael@0: int did_delay = 0; michael@0: michael@0: tocopy = length; michael@0: if (length < (int)(2 * sizeof(int))) { michael@0: /* not enough room */ michael@0: return (0); michael@0: } michael@0: if (SCTP_PKTLOG_WRITERS_NEED_LOCK) { michael@0: atomic_add_int(&SCTP_BASE_VAR(packet_log_writers), SCTP_PKTLOG_WRITERS_NEED_LOCK); michael@0: again: michael@0: if ((did_delay == 0) && (SCTP_BASE_VAR(packet_log_writers) != SCTP_PKTLOG_WRITERS_NEED_LOCK)) { michael@0: /* we delay here for just a moment hoping the writer(s) that were michael@0: * present when we entered will have left and we only have michael@0: * locking ones that will contend with us for the lock. This michael@0: * does not assure 100% access, but its good enough for michael@0: * a logging facility like this. michael@0: */ michael@0: did_delay = 1; michael@0: DELAY(10); michael@0: goto again; michael@0: } michael@0: } michael@0: SCTP_IP_PKTLOG_LOCK(); michael@0: lenat = (int *)target; michael@0: *lenat = SCTP_BASE_VAR(packet_log_end); michael@0: lenat++; michael@0: this_copy = min((length - sizeof(int)), SCTP_PACKET_LOG_SIZE); michael@0: memcpy((void *)lenat, (void *)SCTP_BASE_VAR(packet_log_buffer), this_copy); michael@0: if (SCTP_PKTLOG_WRITERS_NEED_LOCK) { michael@0: atomic_subtract_int(&SCTP_BASE_VAR(packet_log_writers), michael@0: SCTP_PKTLOG_WRITERS_NEED_LOCK); michael@0: } michael@0: SCTP_IP_PKTLOG_UNLOCK(); michael@0: return (this_copy + sizeof(int)); michael@0: } michael@0: michael@0: #endif