?? ospf_hello.c
字號:
/* ospf_hello.c - used for sending, receiving and processing Hello packets *//* Copyright 1998 - 2003 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02i,26may03,agi Changed rwos_get_system_elapsed_time_second() to ospf_get_system_elapsed_time_second() Added code inspection changes02h,20may03,agi Removed dependency on RWOS02g,22apr03,ram SPR#76812 Modifications for OSPF performance enhancements02f,26feb03,kkz SPR 86263 - Don't recalc DR unless necessary02e,06jan03,ram SPR 85432 Changes to allow more OSPF external route processing02d,11dec02,fli SPR 81628 - Fixes for ANVL 13.6 to pass on MIPS board02c,03dec02,ram SPR 84312 - Change elapsed time to return seconds02b,22nov02,dsk SPR 76417, ANVL 13.17 DUT is not setting ANVL as a correct BDR router.02a,19nov02,mwv merge TMS code SPR 8428401z,22oct02,hme Fix SPR #294168 not able detect and handle on-way links using HELLO packets01y,09oct02,hme Fix TSR #29146801x,25apr02,jkw Change displaying of interface from hex to decimal.01w,13oct01,kc Dynamic configuration changes.01v,26sep01,kc Don't determine destination neighbor id for ppp or vl if interface is going down in ospf_set_destination_and_neighbor_information()01u,26sep01,kc Skip ospf_determine_number_of_neighbors_for_hello_packet() in ospf_send_hello() if interface is going down01t,11may01,aos Added null pointer checks01s,3may01,jkw Added checks for NULL pointers and alarm messages01r,26sep00,reshma Added WindRiver CopyRight01q,25sep00,reshma RFC-1587 implementation for OSPF NSSA Option, also tested against ANVL.01p,07jul00,reshma Unix compatibility related changes.01o,04apr00,reshma Added some MIB support (Read only).Passed all important ANVL OSPF tests.01n,23dec99,reshma Compatibility with VxWorks-IP and VxWorks RTM-interface01m,06jan99,jack Change in setting sest router on virtual links and point to point in function ospf_set_destination_and_neighbor_information01l,13aug98,jack ifdefed lsl control calls01k,28dec98,jack Compiled and added some comments01j,11nov98,jack Config changes, linted and big endian changes01i,30oct98,jack Incorporate changes for compilation on Vxworks01h,23aug98,jack ANVL tested OSPF with PATRICIA tree route table and no recursion01g,10aug98,jack PATRICIA Route Table Based OSPF Code Base01f,04jun98,jack Integration with RTM and BGP01e,24apr98,jack RTM changes01d,10jul97,cindy Pre-release v1.52b01c,02oct97,cindy Release Version 1.5201b,22oct96,cindy Release Version 1.5001a,05jun96,cindy First Beta Release*//*DESCRIPTIONospf_hello.c is used for sending and receiving hello packets. This file will extract informationfrom the hello packet and validate whether the hello packet is valid or not. This file willsend create hello packets to be sent to other OSPF routers.This file is used from the timer task to send hello packets and on the receive task when receivinghello packets.*/#include "ospf.h"#if defined (__OSPF_VIRTUAL_STACK__)#include "ospf_vs_lib.h"#endif /* __OSPF_VIRTUAL_STACK__ *//***********************************************************************************************************************************/static ULONG ospf_determine_number_of_neighbors_for_hello_packet (OSPF_INTERFACE *sptr_interface);static OSPF_HEADER *ospf_new_hello (ULONG number_of_neighbors,ULONG authentication_size);static void ospf_initialize_hello_packet_header (OSPF_HELLO_HEADER *sptr_hello,OSPF_INTERFACE *sptr_interface,enum BOOLEAN goingdown);static void ospf_set_destination_and_neighbor_information (OSPF_INTERFACE *sptr_interface,OSPF_NEIGHBOR *sptr_neighbor,enum BOOLEAN goingdown, ULONG *sptr_destination_router,ULONG *ulptr_recently_seen_neighbor,OSPF_HEADER *sptr_packet,ULONG *ulptr_length_of_packet);static void ospf_setup_to_send_on_an_NBMA_network (OSPF_INTERFACE *sptr_interface,OSPF_NEIGHBOR *sptr_neighbor,enum BOOLEAN goingdown, ULONG *sptr_destination_router,ULONG *ulptr_recently_seen_neighbor,OSPF_HEADER *sptr_packet,ULONG *ulptr_length_of_packet);#if defined (__RFC_2328__)static void ospf_setup_to_send_on_a_point_to_multipoint_network (OSPF_INTERFACE *sptr_interface,OSPF_NEIGHBOR *sptr_neighbor,enum BOOLEAN goingdown, ULONG *sptr_destination_router,ULONG *ulptr_recently_seen_neighbor,OSPF_HEADER *sptr_packet,ULONG *ulptr_length_of_packet);#endif /* __RFC_2328__ */static void ospf_setup_to_send_to_designated_router_and_backup_designated_router (OSPF_INTERFACE *sptr_interface,ULONG *sptr_destination_router, ULONG *ulptr_recently_seen_neighbor,enum BOOLEAN goingdown,ULONG *ulptr_length_of_packet);static void ospf_setup_to_send_to_all_eligible_neighbors (OSPF_INTERFACE *sptr_interface,ULONG *sptr_destination_router, ULONG *ulptr_recently_seen_neighbor,enum BOOLEAN goingdown,OSPF_NEIGHBOR *sptr_neighbor,ULONG *ulptr_length_of_packet);static void ospf_setup_to_send_to_all_neighbors_in_up_state (OSPF_INTERFACE *sptr_interface,ULONG *sptr_destination_router, ULONG *ulptr_recently_seen_neighbor,enum BOOLEAN goingdown,OSPF_NEIGHBOR *sptr_neighbor,OSPF_HEADER *sptr_packet, ULONG *ulptr_length_of_packet);#if defined (__RFC_2328__)static void ospf_setup_to_send_to_all_neighbors_in_exchange_state (OSPF_INTERFACE *sptr_interface,ULONG *sptr_destination_router, ULONG *ulptr_recently_seen_neighbor,enum BOOLEAN goingdown,OSPF_NEIGHBOR *sptr_neighbor,OSPF_HEADER *sptr_packet, ULONG *ulptr_length_of_packet);#endif /* __RFC_2328__ */static ULONG* ospf_add_neighbor_to_end_of_hello_packet (ULONG *ulptr_end_of_hello_packet,ULONG neighbor_id,ULONG *ulptr_length_of_packet);static enum OSPF_PACKET_STATE ospf_check_hello_packet_validity (OSPF_HELLO_HEADER *sptr_hello,OSPF_INTERFACE *sptr_interface, ULONG router_id);static OSPF_NEIGHBOR *ospf_extract_neighbor_information_from_hello_packet (OSPF_HELLO_HEADER *sptr_hello,OSPF_NEIGHBOR *sptr_new_neighbor, OSPF_INTERFACE *sptr_interface,ULONG source_address,ULONG router_id,ULONG cryptographic_sequence_number);static void ospf_examine_rest_of_hello_packet_and_generate_events_as_necessary (OSPF_HELLO_HEADER *sptr_hello,OSPF_NEIGHBOR *sptr_new_neighbor, OSPF_INTERFACE *sptr_interface,ULONG size_of_packet);static enum BOOLEAN ospf_examine_neighbors_in_hello_packet (OSPF_HELLO_HEADER *sptr_hello,OSPF_NEIGHBOR *sptr_new_neighbor, OSPF_INTERFACE *sptr_interface,ULONG size_of_packet);static void ospf_update_router_priority_for_neighbor (OSPF_NEIGHBOR *sptr_new_neighbor,USHORT router_priority, OSPF_INTERFACE *sptr_interface);static ULONG ospf_check_if_only_dr_is_present_and_no_bdr (OSPF_INTERFACE *sptr_interface, OSPF_HELLO_HEADER *sptr_hello, ULONG size_of_packet );/*************************************************************************** ospf_send_hello - set up hello packet to be sent** This routine will create and send a Hello packet to its neighbor.** <sptr_interface> OSPF interface** <sptr_neighbor> Neighbor associated with interface** <goingdown> Whether or not the router is going down** RETURNS: N/A** ERRNO: N/A** NOMANUAL*//*********************************************************************************//* section 9.5 of OSPF specification (page 71) */void ospf_send_hello (OSPF_INTERFACE *sptr_interface,OSPF_NEIGHBOR *sptr_neighbor,enum BOOLEAN goingdown){ OSPF_HEADER *sptr_packet = NULL ; OSPF_HELLO_HEADER *sptr_hello =NULL; ULONG destination_router ; ULONG *ulptr_recently_seen_neighbor = NULL; ULONG length_of_packet ; ULONG number_of_neighbors ; ULONG authentication_size ; OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_send_hello\r\n");#if defined (__OSPF_PASSIVE_INTERFACE__) if (sptr_interface->passive == TRUE) { OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: ospf_send_hello:: interface %lx is passive!\r\n", sptr_interface->address); return; }#endif /* __OSPF_PASSIVE_INTERFACE__ */ sptr_packet = NULL; sptr_hello = NULL; destination_router = 0x00000000L; ulptr_recently_seen_neighbor = NULL; length_of_packet = 0x00000000; number_of_neighbors = 0x00000000; authentication_size = 0x00000000; number_of_neighbors = ospf_determine_number_of_neighbors_for_hello_packet (sptr_interface); authentication_size = ospf_get_authentication_size (sptr_interface); sptr_packet = ospf_new_hello (number_of_neighbors, authentication_size); /* Added changes as per TMS PR # 1583 To make sure sptr_packet if ospf_new_hello() failed*/ if (sptr_packet == NULL) { OSPF_PRINTF_DEBUG (OSPF_ALARM_PRINTF, "OSPF: ospf_send_hello::ospf_new_hello() failed!\r\n"); return; } sptr_hello = (OSPF_HELLO_HEADER *) &(sptr_packet->rest_of_packet.hello); ospf_initialize_hello_packet_header (sptr_hello, sptr_interface, goingdown); ulptr_recently_seen_neighbor = &(sptr_hello->neighbor); length_of_packet = OSPF_PACKET_SIZE + OSPF_HELLO_HEADER_SIZE; ospf_set_destination_and_neighbor_information (sptr_interface, sptr_neighbor, goingdown, &destination_router, ulptr_recently_seen_neighbor, sptr_packet, &length_of_packet); if (destination_router != 0x00000000L) /* there's no one to send to */ { ospf_tx_packet (sptr_packet, sptr_interface, OSPF_HELLO_PACKET, length_of_packet, destination_router, TRUE); } else { ospf_free_an_ospf_send_packet (sptr_packet); } return;}/*************************************************************************** ospf_determine_number_of_neighbors_for_hello_packet - determine the number of neighbors for the hello packet** This routine will find out all the neighbors on an interface.** <sptr_interface> OSPF interface** RETURNS: ULONG** ERRNO: N/A** NOMANUAL*/static ULONG ospf_determine_number_of_neighbors_for_hello_packet (OSPF_INTERFACE *sptr_interface){ ULONG number_of_neighbors; OSPF_NEIGHBOR *sptr_neighbor = NULL; OSPF_NEIGHBOR *sptr_next_neighbor = NULL; char print_buffer[PRINT_BUFFER_SIZE]; OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_determine_number_of_neighbors_for_hello_packet\r\n"); number_of_neighbors = 0x00000000L; for (sptr_neighbor = sptr_interface->sptr_neighbor; sptr_neighbor != NULL; sptr_neighbor = sptr_next_neighbor) { sptr_next_neighbor = sptr_neighbor->sptr_forward_link; ++number_of_neighbors; }#if defined (__UNNUMBERED_LINK__) /* -bt- */ OSPF_PRINTF_ALARM (OSPF_ALARM_PRINTF, "Number of neighbors %d at Port %d with address ", number_of_neighbors, sptr_interface->port_number); OSPF_CONVERT_IP_ADDRESS_TO_DOT_FORMAT_FOR_DEBUG (print_buffer, sptr_interface->address); OSPF_PRINTF_ALARM (OSPF_ALARM_PRINTF, "%s \r\n", print_buffer);#else /* __UNNUMBERED_LINK__ -bt- */ OSPF_PRINTF_ALARM (OSPF_ALARM_PRINTF, "Number of neighbors %d on interface with address ", number_of_neighbors); OSPF_CONVERT_IP_ADDRESS_TO_DOT_FORMAT_FOR_DEBUG (print_buffer, sptr_interface->address); OSPF_PRINTF_ALARM (OSPF_ALARM_PRINTF, "%s \r\n", print_buffer);#endif /* __UNNUMBERED_LINK__ -bt- */ return (number_of_neighbors);}/*************************************************************************** ospf_new_hello - create a new hello packet** This routine will create a new hello packet** <number_of_neighbors> Number of neighbors to allocate memory for** <authentication_size> Size needed for authentication of interface** RETURNS: OSPF_HEADER * or NULL** ERRNO: N/A** NOMANUAL*/static OSPF_HEADER *ospf_new_hello (ULONG number_of_neighbors,ULONG authentication_size){ OSPF_HEADER *sptr_packet =NULL; OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_new_hello\r\n"); sptr_packet = ospf_get_an_ospf_send_packet (OSPF_PACKET_SIZE + OSPF_HELLO_HEADER_SIZE + (number_of_neighbors * sizeof (ULONG)) + authentication_size); return (sptr_packet);}/*************************************************************************** ospf_initialize_hello_packet_header - set values for hello packet header** This routine will initialize all the variables inside the hello packet* header along with the configured variables from configuration.** <sptr_hello> Hello packet header** <sptr_interface> OSPF interface** <going_down> Whether or not the router is going down** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/static void ospf_initialize_hello_packet_header (OSPF_HELLO_HEADER *sptr_hello,OSPF_INTERFACE *sptr_interface,enum BOOLEAN goingdown){ OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_initialize_hello_packet_header\r\n"); if (sptr_interface->type == OSPF_VIRTUAL_LINK) { sptr_hello->network_mask = 0x00000000L; }#if defined (__UNNUMBERED_LINK__) /* -bt- */ else if ((sptr_interface->type == OSPF_POINT_TO_POINT) && (sptr_interface->address == 0)) { /* unnumbered link rfc2328 */ sptr_hello->network_mask = 0x00000000L; }#endif /* __UNNUMBERED_LINK__ -bt- */ else { sptr_hello->network_mask = host_to_net_long (sptr_interface->netmask); } sptr_hello->hello_interval = host_to_net_short ((USHORT) sptr_interface->hello_interval); if (sptr_interface->sptr_area->flags._bit.stub == TRUE) { sptr_hello->options._byte = 0x0000; }#if defined (__NSSA__) else { if (sptr_interface->sptr_area->flags._bit.nssa == TRUE) { sptr_hello->options._byte = 0x0000; sptr_hello->options._bit.nssa = TRUE; }#endif /*__NSSA__*/ else { sptr_hello->options._byte = 0x0000; sptr_hello->options._bit.externals = TRUE; }#if defined (__NSSA__) }#endif /*__NSSA__*/ sptr_hello->router_priority = (BYTE) sptr_interface->priority; sptr_hello->router_dead_interval = host_to_net_long (sptr_interface->router_dead_interval); if (goingdown == FALSE) { sptr_hello->designated_router = host_to_net_long (sptr_interface->designated_router.address); sptr_hello->backup_designated_router = host_to_net_long (sptr_interface->backup_designated_router.address); } return;}/*************************************************************************** ospf_set_destination_and_neighbor_information - set destination and neighbor information** This routine will set the destination and neighbor information* for the hello packet.** <sptr_interface> OSPF interface** <sptr_neighbor> Neighbor associated with the interface** <going_down> Whether or not the router is going down** <sptr_destination_router> Destination router** <ulptr_recently_seen_neighbor> Recently seen neighbor identifier** <sptr_packet> Hello packet header** <ulptr_length_of_packet> Length of hello packet** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/static void ospf_set_destination_and_neighbor_information (OSPF_INTERFACE *sptr_interface,OSPF_NEIGHBOR *sptr_neighbor,enum BOOLEAN goingdown, ULONG *sptr_destination_router,ULONG *ulptr_recently_seen_neighbor,OSPF_HEADER *sptr_packet,ULONG *ulptr_length_of_packet){ OSPF_NEIGHBOR *sptr_next_neighbor = NULL; OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_set_destination_and_neighbor_information\r\n"); switch (sptr_interface->type) { case OSPF_NBMA: { ospf_setup_to_send_on_an_NBMA_network (sptr_interface, sptr_neighbor, goingdown, sptr_destination_router, ulptr_recently_seen_neighbor, sptr_packet, ulptr_length_of_packet); break; } case OSPF_BROADCAST: { if (ospf.ip_multicast == TRUE) { /* On a multicast interface, include all neighbors since they can all see this packet */ *sptr_destination_router = OSPF_ADDR_ALLSPF; if (goingdown == FALSE) { for (sptr_neighbor = sptr_interface->sptr_neighbor; sptr_neighbor != NULL; sptr_neighbor = sptr_next_neighbor) { sptr_next_neighbor = sptr_neighbor->sptr_forward_link; if (sptr_neighbor->state > OSPF_NEIGHBOR_ATTEMPT) { ulptr_recently_seen_neighbor = ospf_add_neighbor_to_end_of_hello_packet (ulptr_recently_seen_neighbor, sptr_neighbor->id, ulptr_length_of_packet); } } } } else { *sptr_destination_router = 0x00000000L; /* something's not right, so don't send to anyone */ } break; } case OSPF_POINT_TO_POINT: case OSPF_VIRTUAL_LINK: { if (ospf.ip_multicast == TRUE) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -