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

📄 ospf_vx_ip_adaptation.c

📁 vxworks下ospf协议栈
💻 C
📖 第 1 页 / 共 2 页
字号:
                    /* Does the interface that matched this? */                    if (intf_addr == destination_address)                        {                        /* There is an interface that matched with this ospf packet, but                           can't use it yet. just saved it */                        sptr_saved_interface = sptr_interface;                                            /* continue to scan through the rest of the interface to see if                           an unnumbered interface also match this packet */                        for (sptr_interface = sptr_saved_interface;                              sptr_interface != NULL;                             sptr_interface = sptr_interface->sptr_forward_link)                             {                             /* if the interface is unnumbered then get the interface */                             if (sptr_interface->unnumbered_dest_ip == source_address)                                 {                                 sptr_saved_interface = sptr_interface;                                 break;                                 }                             }                        /* at this point the interface is either unnumbered or numbered */                        sptr_interface = sptr_saved_interface;                        break;                        }                    }       /* for loop */#else   /* __UNNUMBERED_LINK__ver1.0 */                /* it is unicast - got destination address in the ip header */                for (sptr_interface = ospf.sptr_interface_list;                      sptr_interface != NULL;                     sptr_interface = sptr_next_interface)                    {                    sptr_next_interface = sptr_interface->sptr_forward_link;                    destination_address = ip_header->ip_dst.s_addr;                    destination_address = net_to_host_long (destination_address);                    intf_addr = sptr_interface->address;                                        if (intf_addr == destination_address)                        {                        break;                        }                    }#endif  /* __UNNUMBERED_LINK__ver1.0 */                }   /* if (IN_MULTICAST (destination_address)) */            /* if can't find matching interface, ignore the packet */            if ( sptr_interface == NULL )                {                OSPF_PRINTF_DEBUG(OSPF_ALARM_PRINTF,                        "dropped recvpkt - recvif not found!\n");                semGive (ospf_global_mutex);                continue;                }            /* call ospf_router_rx_packet() to process the packet */            ospf_router_rx_packet (                sptr_interface,                (OSPF_PACKET *)ospf_receive_message_buffer,                (USHORT)ip_header->ip_len, ip_header->ip_src.s_addr,                ip_header->ip_dst.s_addr);            /* release the mutex */            semGive (ospf_global_mutex);            }        }    }/**************************************************************************************** ospf_vx_ip_output - packet send routine** This is packet send routine. If packet needs to be multicast <flag_multicast is set>,* it calls setsockopt() to specify the network interface through which the multicast* packet is sent.** RETURNS: N/A*/void ospf_vx_ip_output (OSPF_HEADER *sptr_packet, ULONG source_address, bool flag_multicast, ULONG destination_address, ULONG length /* in host order */, enum BOOLEAN free_packet){    struct  sockaddr_in dest;    struct  in_addr localIpAddr;        int     status;        ULONG   source_ip_address = 0x00000000;        ULONG   destination_ip_address = 0x00000000;    /* HME Fix SPR#81451 Begin */#if defined(ENABLE_IP_HDRINCL)    struct in_addr src;    unsigned int bOpt=1;           char ospfSignalData [OSPF_MAX_PKT_SIZE];    /* Contents of signal */    int ipPktLength = IPHL + length;    struct ip * 	pIph;    OSPF_HEADER * 	pOspfh;#endif    /* HME Fix SPR#81451 End */    /* asr: set virtual stack context */    #if defined (VIRTUAL_STACK)        virtualStackNumTaskIdSet (ospf.ospf_vsid);    #endif /* VIRTUAL_STACK */        if ( sptr_packet == NULL )    {        OSPF_PRINTF_ALARM (OSPF_ALARM_PRINTF,"OSPF:invalid transmit data\n");        return;    }    /* HME Fix SPR#81451 Begin */    source_ip_address = source_address;    source_ip_address = host_to_net_long(source_ip_address);    /* HME Fix SPR#81451 End */    if (flag_multicast == true)    {        localIpAddr.s_addr = source_ip_address;        /* call setsockopt to select an outgoing interface for multicasting the packet */        if (setsockopt (ipSock, IPPROTO_IP, IP_MULTICAST_IF, (char *)&localIpAddr,                        sizeof(localIpAddr)) != OK)        {            OSPF_PRINTF_ALARM (OSPF_ALARM_PRINTF, "OSPF:setsockopt failed for tranmit\n");            if (free_packet)            {                buffer_free(sptr_packet);                                sptr_packet = NULL;            }            return;        }    }    /* send the packet using the raw socket */    destination_ip_address = destination_address;    destination_ip_address = host_to_net_long(destination_ip_address);    dest.sin_addr.s_addr = destination_ip_address;    dest.sin_family = AF_INET;/* HME Fix SPR#81451 Begin */   #if defined(ENABLE_IP_HDRINCL)    /* enable IP_HDRINCL option */    if (setsockopt(ipSock, IPPROTO_IP, IP_HDRINCL, (char *)&bOpt, sizeof(bOpt)) != OK) {                OSPF_PRINTF_ALARM (OSPF_ALARM_PRINTF, "OSPF:setsockopt IP_HDRINCL failed \n");        return;    }    /* Check whether the size of ospfSignalData is larger than ipPktLength */    if (ipPktLength > OSPF_MAX_PKT_SIZE)     {        OSPF_PRINTF_ALARM (OSPF_ALARM_PRINTF, "OSPF: Ospf pkt size is too big (ipPktLength > OSPF_MAX_PKT_SIZE) \n");        return;    }        /* Create an IP packet and copy the OSPF packet to it*/    bzero (ospfSignalData, ipPktLength);    pIph = (struct ip *)ospfSignalData;    src.s_addr = source_ip_address;    ipHeaderCreate(IPPROTO_OSPF, &src, &dest.sin_addr, (struct ip *)pIph, htons(ipPktLength)); /* HME Fix SPR#69807 & SPR#72167  Begin*/    pIph->ip_tos = TOS_BYTE_VALUE;/* HME Fix SPR#69807 & SPR#72167  End*/        /* copy original OSPF data into the IP packet */    pOspfh = (OSPF_HEADER *) (ospfSignalData + IPHL);    bcopy( (const char *)sptr_packet, (char *) pOspfh, length);       /* send the IP packet */    status = sendto(ipSock, (void *)pIph, ipPktLength, 0, (struct sockaddr *)&dest,                   sizeof(dest));#else        status = sendto(ipSock, (void *)sptr_packet, length, 0, (struct sockaddr *)&dest,                    sizeof(dest));#endif/* HME Fix SPR#81451 End */    if (free_packet)    {        buffer_free(sptr_packet);                sptr_packet = NULL;    }    return;}/************************************************************************/#if defined (__OSPF_ROUTER_STACK__)void ospf_ctlinput    (    unsigned long intf,     unsigned short intf_index,     int intf_flags    )    {        bool interface_found;#if defined (NOT_SUPPORTED_YET)        ULONG port_number;#endif /* NOT_SUPPORTED_YET */        OSPF_INTERFACE *sptr_interface = NULL;        OSPF_INTERFACE *sptr_next_interface = NULL;        ULONG ip_address = 0x00000000;        interface_found = false;        for (sptr_interface = ospf.sptr_interface_list;              sptr_interface != NULL;              sptr_interface = sptr_next_interface)            {            sptr_next_interface = sptr_interface->sptr_forward_link;            ip_address = sptr_interface->address;            ip_address = host_to_net_long(ip_address);            if(intf_index == sptr_interface->ifnet_index)                {                if( intf_flags & IFF_UP )                    {                    semTake (ospf_global_mutex, WAIT_FOREVER);                    ospf_indicate_lower_level_interface_state_change (                        sptr_interface,                         true);                    semGive (ospf_global_mutex);                    interface_found = true;                    break;                    }                else                    {                    semTake (ospf_global_mutex, WAIT_FOREVER);                    ospf_indicate_lower_level_interface_state_change (                        sptr_interface,                         false);                    semGive (ospf_global_mutex);                    interface_found = true;                    break;                    }                }            }    if (interface_found  == false)        {        OSPF_PRINTF_ALARM (            OSPF_ALARM_PRINTF,             "OSPF: ospf_ctlinput() called, but interface is not found \r\n");        }    }/*********************************************************************************************************************************************************************/#else /* __OSPF_ROUTER_STACK__ */void ospf_ctlinput (int command, struct sockaddr *sa,register struct ip *ip){        ULONG interface_address;        bool interface_found;    OSPF_INTERFACE *sptr_interface = NULL;        OSPF_INTERFACE *sptr_next_interface = NULL;        struct sockaddr_in *address;        PARAMETER_NOT_USED (ip);        interface_found = false;        if (command == PRC_IFDOWN)                {                address = (struct sockaddr_in *) sa;                interface_address = (ULONG) (address->sin_addr.s_addr);                interface_address = ntohl (interface_address);                OSPF_PRINTF_ALARM (OSPF_ALARM_PRINTF, "OSPF: ospf_ctlinput() called, %lx \r\n", interface_address);        interface_found = false;        semTake (ospf_global_mutex, WAIT_FOREVER);         for ( sptr_interface = ospf.sptr_interface_list; sptr_interface != NULL;              sptr_interface = sptr_next_interface)        {                        sptr_next_interface = sptr_interface->sptr_forward_link;            if ( sptr_interface->address == interface_address)            {                ospf_indicate_lower_level_interface_state_change (sptr_interface, false);                interface_found = true;                break;            }        }                semGive (ospf_global_mutex);                if (interface_found  == false)                        {                        OSPF_PRINTF_ALARM (OSPF_ALARM_PRINTF, "OSPF: ospf_ctlinput() called, but interface is not found \r\n");                        }                }#if defined (NOT_SUPPORTED_YET)        if (command == PRC_IFUP)                {                address = (struct sockaddr_in *) sa;                interface_address = (ULONG) (address->sin_addr.s_addr);                interface_address = ntohl (interface_address);                OSPF_PRINTF_ALARM (OSPF_ALARM_PRINTF, "OSPF: ospf_ctlinput() called, %lx \r\n", interface_address);        interface_found = false;                semTake (ospf_global_mutex, WAIT_FOREVER);                for (sptr_interface = ospf.sptr_interface_list; sptr_interface != NULL;              sptr_interface = sptr_next_interface)        {                        sptr_next_interface = sptr_interface->sptr_forward_link;            if (sptr_interface->address == interface_address)            {                ospf_indicate_lower_level_interface_state_change (sptr_interface, true);                interface_found = true;                break;            }        }                 semGive (ospf_global_mutex);                if (interface_found  == false)                        {                        OSPF_PRINTF_ALARM (OSPF_ALARM_PRINTF, "OSPF: ospf_ctlinput() called, but interface is not found \r\n");                        }                }#endif        /* More commands - PRC_XXX will be supported in future */        return;}#endif /* __OSPF_ROUTER_STACK__ *//************************************************************************/void ospf_indicate_lower_level_interface_state_change (OSPF_INTERFACE* sptr_ospf_interface, bool new_state){        if (sptr_ospf_interface == NULL)                {                OSPF_PRINTF_ALARM (OSPF_ALARM_PRINTF, "OSPF: ospf_indicate_lower_level_interface_state_change() called, but interface is NULL \r\n");                return;                }        if (new_state == false /* down */)                {                if (sptr_ospf_interface->state != OSPF_INTERFACE_IS_DOWN)                        {                        ospf_execute_interface_state_machine( OSPF_INTERFACE_DOWN,                                sptr_ospf_interface->state, sptr_ospf_interface );                        sptr_ospf_interface->sptr_area->build_router = TRUE;                        ospf_generate_network_and_router_link_state_advertisements (sptr_ospf_interface);                        OSPF_PRINTF_ALARM (OSPF_ALARM_PRINTF, "OSPF: INTERFACE DOWN with address (HEX) %lx\r\n", sptr_ospf_interface->address);                        }                }        else if (new_state == true /* up */)                {                if (sptr_ospf_interface->state == OSPF_INTERFACE_IS_DOWN)                        {                        sptr_ospf_interface->state = OSPF_INTERFACE_WAITING;                        ospf_execute_interface_state_machine (OSPF_INTERFACE_UP, OSPF_INTERFACE_IS_DOWN, sptr_ospf_interface);                        sptr_ospf_interface->sptr_area->build_router = TRUE;                        ospf_generate_network_and_router_link_state_advertisements (sptr_ospf_interface);                        OSPF_PRINTF_ALARM (OSPF_ALARM_PRINTF, "OSPF: INTERFACE UP with address (HEX) %lx\r\n", sptr_ospf_interface->address);                        }                }        return;}

⌨️ 快捷键说明

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