⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ipsec_network_interface.c

📁 ipsec PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 2 页
字号:
STATUS ipsecDFBitMapi    (    WRSEC_INET_ADDR *pAddress,    int dfBitConfig    )    {    void *iterator = (void *)NULL;    IPSEC_NETWORK_INTERFACE *p_ipsec_network_interface;    STATUS return_value;    WRSEC_INET_ADDR_FAMILY wrn_inet_address_family;    DF_BIT_CONFIG df_bit_config;    if (ipsec_global_class.ipsec_enabled == FALSE)        {        return (ERROR);        }    return_value = ERROR;    p_ipsec_network_interface = NULL;    if ((dfBitConfig == 0) || (dfBitConfig == 1) || (dfBitConfig == 2))        {        df_bit_config = dfBitConfig;        }    else        {        ipsec_printf (IPSEC_ERROR_PRINTF, "IPSec: Configuration Error! %s\n", "Invalid DF Bit Configuration");        return (ERROR);        }    /*address unspecified check*/    wrn_inet_address_family = pAddress->type;    if (wrn_inet_address_family == WRSEC_AF_INET4)        {        if (WRSEC_INET4_IS_ADDR_UNSPECIFIED (((WRSEC_INET4_ADDR *)pAddress)))            {            ipsec_printf (IPSEC_ERROR_PRINTF, "IPSec: Invalid IPv4 Address\n");            return (ERROR);            }        }    else if (wrn_inet_address_family == WRSEC_AF_INET6)        {        if (WRSEC_INET6_IS_ADDR_UNSPECIFIED (((WRSEC_INET6_ADDR *)pAddress)))            {            ipsec_printf (IPSEC_ERROR_PRINTF, "IPSec: Invalid IPv6 Address\n");            return (ERROR);            }        }    else        {        ipsec_printf (IPSEC_ERROR_PRINTF, "IPsec: Invalid Address\n");        return (ERROR);        }	wrSecListScanLock( ipsec_global_class.ipsec_network_interface_list );	while ((p_ipsec_network_interface = wrSecListScan(ipsec_global_class.ipsec_network_interface_list,                                                      &iterator)) != NULL)		{		if ((pAddress->type == p_ipsec_network_interface->p_address->type) &&            wrSecInetAddrEquals(pAddress, p_ipsec_network_interface->p_address))			{			p_ipsec_network_interface->df_bit = df_bit_config;			wrSecFree (pAddress);			return_value = OK;			break;			}		}	wrSecListScanUnlock( ipsec_global_class.ipsec_network_interface_list );    return (return_value);    }/******************************************************************************** ipsecSetPMTUAgeMapi - Configures the time untill which the PMTU for a host is  *                       stored .* RETURNS: OK or ERROR* */STATUS ipsecSetPMTUAgeMapi    (    WRSEC_INET_ADDR *pAddress,    UINT minutes    )    {    void *iterator = (void *)NULL;    IPSEC_NETWORK_INTERFACE *p_ipsec_network_interface;    STATUS return_value;    WRSEC_INET_ADDR_FAMILY wrn_inet_address_family;    if (ipsec_global_class.ipsec_enabled == FALSE)        {        return (ERROR);        }    return_value = ERROR;    p_ipsec_network_interface = NULL;    /*address unspecified check*/    wrn_inet_address_family = pAddress->type;    if (wrn_inet_address_family == WRSEC_AF_INET4)        {        if (WRSEC_INET4_IS_ADDR_UNSPECIFIED (((WRSEC_INET4_ADDR *)pAddress)))            {            ipsec_printf (IPSEC_ERROR_PRINTF, "IPSec: Invalid IPv4 Address\n");            return (ERROR);            }        }    else if (wrn_inet_address_family == WRSEC_AF_INET6)        {        if (WRSEC_INET6_IS_ADDR_UNSPECIFIED (((WRSEC_INET6_ADDR *)pAddress)))            {            ipsec_printf (IPSEC_ERROR_PRINTF, "IPSec: Invalid IPv6 Address\n");            return (ERROR);            }        }    else        {        ipsec_printf (IPSEC_ERROR_PRINTF, "IPsec: Invalid Address\n");        return (ERROR);        }	wrSecListScanLock( ipsec_global_class.ipsec_network_interface_list );	while ((p_ipsec_network_interface = wrSecListScan(ipsec_global_class.ipsec_network_interface_list,                                                      &iterator)) != NULL)		{		if ((pAddress->type == p_ipsec_network_interface->p_address->type) &&            wrSecInetAddrEquals(pAddress, p_ipsec_network_interface->p_address))			{			p_ipsec_network_interface->pmtu_age = 60 * minutes;			wrSecFree (pAddress);			return_value = OK;			break;			}		}	wrSecListScanUnlock( ipsec_global_class.ipsec_network_interface_list );    return (return_value);    }/************************************************************************/UINT ipsecPmtuAgeGet    (    WRSEC_INET_ADDR *pAddress    )    {	void *iterator = (void *)NULL;    IPSEC_NETWORK_INTERFACE *p_ipsec_network_interface;    UCHAR addr_equals;    UINT return_value;    return_value = 0;    if (ipsec_global_class.ipsec_enabled == FALSE)        {        return (return_value);        }    p_ipsec_network_interface = NULL;    addr_equals = 0;	wrSecListScanLock( ipsec_global_class.ipsec_network_interface_list );	while ((p_ipsec_network_interface = wrSecListScan(ipsec_global_class.ipsec_network_interface_list,                                                      &iterator)) != NULL)		{		if ((pAddress->type == p_ipsec_network_interface->p_address->type) &&            wrSecInetAddrEquals(pAddress, p_ipsec_network_interface->p_address))			{			return_value = p_ipsec_network_interface->pmtu_age;			break;			}		}	wrSecListScanUnlock( ipsec_global_class.ipsec_network_interface_list );    if (addr_equals == 0)        {        UCHAR addr_string[50];        wrSecInetAddrToString((char *)addr_string, 50, pAddress);        ipsec_printf (IPSEC_WARNING_PRINTF, "IPSec: could not find PMTU age information for %s\n", addr_string);        }    return (return_value);    }/******************************************************************************** ipsec_get_ifnet_handle  - Finds the network interface base on the IP address* ASSUMES: that splimp() is already called before invoking this function* RETURNS: Handle to the network interface structure, otherwise NULL*/struct ifnet *ipsec_get_ifnet_handle    (    WRSEC_INET_ADDR *pAddress    )    {    struct ifnet *sptr_ifnet = (struct ifnet *)NULL;    struct in_addr ip_in_addr;    #if STACK_NAME == STACK_NAME_V4_V6 && defined (INET6)    struct ifnet *ifp;    struct ifaddr *ifa;    struct in6_addr ip_in6_addr;    struct sockaddr_in6 *sockaddr6;    UCHAR *a, *b;    UCHAR len_to_compare;    #endif    WRSEC_INET_ADDR_FAMILY wrn_inet_address_family;    wrn_inet_address_family = pAddress->type;    if (wrn_inet_address_family == WRSEC_AF_INET4)        {        ip_in_addr.s_addr = (((WRSEC_INET4_ADDR *)pAddress)->data._ula1[0]);        INADDR_TO_IFP (ip_in_addr, sptr_ifnet);        }    else if (wrn_inet_address_family == WRSEC_AF_INET6)        {        #if STACK_NAME == STACK_NAME_V4_V6 && defined (INET6)        WRSEC_INET6_SET_IN6_ADDR_A_WITH_STRUCT_B (ip_in6_addr, (*(WRSEC_INET6_ADDR *)pAddress));        for (ifp = ifnet_head.tqh_first; ifp; ifp = ifp->if_list.tqe_next)            {            for (ifa = ifp->if_addrlist.tqh_first; ifa; ifa = ifa->ifa_list.tqe_next)                {                if (ifa->ifa_addr->sa_family != AF_INET6)                    continue;                sockaddr6 = (struct sockaddr_in6 *)ifa->ifa_addr;                /* Kame implementation stores interface index in third and                  * fourth byte of address(link local).                  */                a = (UCHAR *)&sockaddr6->sin6_addr;                b = (UCHAR *)&ip_in6_addr;                len_to_compare = sizeof (struct in6_addr);                if (*a == 0xfe && *(a + 1) == 0x80 && *b == 0xfe && *(b + 1) == 0x80)                    {                    a += 4;                    b += 4;                    len_to_compare -= 4;                    }                if (memcmp (a, b, len_to_compare) == 0)                    {                    sptr_ifnet = ifp;                    }                }            }        #else        ipsec_printf (IPSEC_ERROR_PRINTF, "IPsec: Invalid IP Address format\n");        #endif        }    else        {        ipsec_printf (IPSEC_ERROR_PRINTF, "IPsec: Invalid IP Address\n");        }    return ( sptr_ifnet );    }/******************************************************************************** ipsec_find_network_interface_based_on_ip_address   * Searches for a network interface with matching IP address.* * RETURNS: pointer to IPSEC_NETWORK_INTERFACE on success or NULL on failure*/IPSEC_NETWORK_INTERFACE *ipsec_find_network_interface_based_on_ip_address    (    WRSEC_INET_ADDR *pAddress    )    {    void *iterator = (void *)NULL;    IPSEC_NETWORK_INTERFACE *p_ipsec_network_interface;    IPSEC_NETWORK_INTERFACE *p_target_network_interface;    WRSEC_INET_ADDR_FAMILY wrn_inet_address_family;    p_target_network_interface = NULL;    wrn_inet_address_family = pAddress->type;	wrSecListScanLock( ipsec_global_class.ipsec_network_interface_list );	while ((p_ipsec_network_interface = wrSecListScan(ipsec_global_class.ipsec_network_interface_list,                                                      &iterator)) != NULL)		{		if ((pAddress->type == p_ipsec_network_interface->p_address->type) &&            wrSecInetAddrEquals(pAddress, p_ipsec_network_interface->p_address))			{            p_target_network_interface = p_ipsec_network_interface;            break;			}		}	wrSecListScanUnlock( ipsec_global_class.ipsec_network_interface_list );    return (p_target_network_interface);    }/******************************************************************************/void cleanup_network_interface_container    (    WRSEC_LIST list    )    {    void *iterator = (void *)NULL;    IPSEC_NETWORK_INTERFACE *p_network_interface;	wrSecListScanLock( list );	while ((p_network_interface = wrSecListScan(list, &iterator)) != NULL)		{		if (p_network_interface->p_address != NULL)			{			wrSecFree (p_network_interface->p_address);			}		wrSecFree (p_network_interface);		}	wrSecListScanUnlock( list );    }/******************************************************************************//* Do not un-comment; NOT to be used *//*    Do not un-comment; NOT to be used        {        struct in_ifaddr* sptr_interface_address;        struct ifaddr* sptr_ifaddr;        s = splnet();        for (sptr_ifaddr = sptr_ifnet->if_addrlist; sptr_ifaddr;             sptr_ifaddr = sptr_ifaddr->ifa_next)            {            IFP_TO_IA (sptr_ifnet, sptr_interface_address);            if (sptr_interface_address == NULL)                {                continue;                }            if (sptr_interface_address->ia_addr.sin_family != AF_INET)                {                continue;                }            source = sptr_interface_address->ia_addr.sin_addr.s_addr;            p_network_interface =                 ipsec_find_network_interface_based_on_ip_address (ntohl(source));            if (p_network_interface != NULL)                {                *pp_ipsec_network_interface = p_network_interface;                found = TRUE;                break;                }            }        splx(s);        }*//******************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -