📄 ospf_interface.c
字号:
/* ospf_interface.c - used for initializing interface *//* Copyright 1998 - 2003 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history-------------------- 02d,15may03,asr Changes to make OSPF virtual stack compatible02c,14may03,agi Changed RWOS semaphores to vxWorks semaphores02b,19nov02,mwv Merge TMS code SPR 8428402a,08oct02,agi Fixed compiler warnings01r,24jun02,kc Changed check_if_status() to return boolean (instead of int).01q,06feb02,bt look for changes in comment __UNNUMBERED_LINK__ver1.001p,26sep00,reshma Added WindRiver CopyRight01o,25sep00,reshma RFC-1587 implementation for OSPF NSSA Option, also tested against ANVL.01n,07jul00,reshma Unix compatibility related changes.01m,04apr00,reshma Added some MIB support (Read only). Passed all important ANVL OSPF tests.01l,23dec99,reshma Compatibility with VxWorks-IP and VxWorks RTM-interface01k,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_interface.c is used for initializing and bringing up interfaces in OSPF. This file checksif the interface is up or down.This file is used whenever an interface needs to be brought up or initialized.*/#include <stdio.h>#include <stdarg.h>#include <vxWorks.h>#include <tickLib.h>#include <netLib.h>#include <net/systm.h>#include <net/mbuf.h>#include <net/domain.h>#include <net/protosw.h>#include <sys/socket.h>#include <errno.h>#include <net/if.h>#include <net/route.h>#include <netinet/in.h>#include <netinet/in_pcb.h>#include <netinet/in_systm.h>#include <netinet/in_var.h>#include <netinet/ip.h>#include <netinet/ip_var.h>#include <netinet/ip_icmp.h>#include "ospf.h"#if defined (__OSPF_VIRTUAL_STACK__)#include "ospf_vs_lib.h"#endif /* __OSPF_VIRTUAL_STACK__ *//******************************************************************************/static void ospf_initialize_interface_time_counters (OSPF_INTERFACE *sptr_interface);/******************************************************************************//*************************************************************************** ospf_bring_up_interface - bring up an interface** This routine will bring up an interface and execute* the associated interface state machine.** <sptr_interface> OSPF interface** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/void ospf_bring_up_interface (OSPF_INTERFACE *sptr_interface){ OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_bring_up_interface\r\n"); ospf_initialize_interface_time_counters (sptr_interface); sptr_interface->sptr_head_of_delayed_acknowledgement_list = NULL; sptr_interface->number_of_acknowledgements_on_delayed_acknowledgement_list = 0x00000000L; ospf_execute_interface_state_machine (OSPF_INTERFACE_UP, OSPF_INTERFACE_IS_DOWN, sptr_interface); ospf_generate_network_and_router_link_state_advertisements (sptr_interface); return;}/*************************************************************************** ospf_initialize_interface - initialize an interface** This routine will initialize the variables associated* with an interface.** <sptr_interface> OSPF interface** <dynamic> Boolean to tell whether or not dynamically configured** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/void ospf_initialize_interface (OSPF_INTERFACE *sptr_interface, BOOL dynamic){ ULONG address =0; char print_buffer[PRINT_BUFFER_SIZE]; char print_buffer_1[PRINT_BUFFER_SIZE]; OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_initialize_interface\r\n"); if (sptr_interface == NULL) return; if (sptr_interface->type == OSPF_VIRTUAL_LINK) { /* Virtual Link - no interface */ OSPF_CONVERT_IP_ADDRESS_TO_DOT_FORMAT_FOR_DEBUG (print_buffer, sptr_interface->virtual_neighbor_rid); OSPF_CONVERT_IP_ADDRESS_TO_DOT_FORMAT_FOR_DEBUG (print_buffer_1, sptr_interface->sptr_transit_area->area_id); OSPF_PRINTF_INTERFACE (OSPF_INTERFACE_PRINTF, "OSPF: initializing virtual interface to neighbor %s via transit area %s\r\n", print_buffer, print_buffer_1); } else { /* Non-virtual interface */ address = sptr_interface->address; OSPF_CONVERT_IP_ADDRESS_TO_DOT_FORMAT_FOR_DEBUG (print_buffer, address); OSPF_CONVERT_IP_ADDRESS_TO_DOT_FORMAT_FOR_DEBUG (print_buffer_1, sptr_interface->sptr_area->area_id); OSPF_PRINTF_INTERFACE (OSPF_INTERFACE_PRINTF, "OSPF: initializing interface %s in area %s\r\n", print_buffer, print_buffer_1); switch (sptr_interface->type) { case OSPF_POINT_TO_POINT: case OSPF_BROADCAST: { if ((ospf.ip_multicast == TRUE) && (sptr_interface->flags._bit.multicast == TRUE)) { /* Indicate we joined the group */ address |= OSPF_IF_MULTICAST_ALLSPF; } break; } case OSPF_NBMA: { break; } default: { break; } } /* execute state machine to bring up the interface if the interface UP flag * is set */ if ((check_if_status( sptr_interface->ifnet_index )) == true ) { ospf_execute_interface_state_machine (OSPF_INTERFACE_UP, OSPF_INTERFACE_IS_DOWN, sptr_interface); } } ospf_initialize_interface_time_counters (sptr_interface); sptr_interface->sptr_head_of_delayed_acknowledgement_list = NULL; sptr_interface->number_of_acknowledgements_on_delayed_acknowledgement_list = 0x00000000L; sptr_interface->designated_router.address = 0x00000000L; sptr_interface->designated_router.id = 0x00000000L; sptr_interface->backup_designated_router.address = 0x00000000L; sptr_interface->backup_designated_router.id = 0x00000000L; return;}/*************************************************************************** ospf_initialize_interface_time_counters - initialize interface counters** This routine will initialize the counters associated* with an interface.** <sptr_interface> OSPF interface** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/static void ospf_initialize_interface_time_counters (OSPF_INTERFACE *sptr_interface){ OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_initialize_interface_time_counters\r\n"); sptr_interface->periodic_hello_time_counter = 0x00000000L; sptr_interface->hello_timer_enabled = TRUE; sptr_interface->periodic_retransmit_time_counter = 0x00000000L; sptr_interface->retransmit_timer_enabled = TRUE; sptr_interface->delayed_acknowledgement_timer_enabled = FALSE; return;}/*************************************************************************** ospf_is_if_up - checks if the interface is up** This routine will check IP if the interface is up** <ip_address> Interface identifier ** RETURNS: TRUE or FALSE** ERRNO: N/A** NOMANUAL*/enum BOOLEAN ospf_is_if_up (ULONG ip_address){ struct ifnet *sptr_ifnet; struct ifaddr* sptr_ifaddr; struct in_ifaddr * sptr_interface_address; int s; /* asr: set the virtual stack context */#if defined (VIRTUAL_STACK) virtualStackNumTaskIdSet (ospf.ospf_vsid);#endif /* VIRTUAL_STACK */ semGive (ospf_global_mutex ); sptr_ifnet = NULL; sptr_ifaddr = NULL; s = splimp();#if defined (VIRTUAL_STACK) for (sptr_ifnet = _ifnet; sptr_ifnet; sptr_ifnet = sptr_ifnet->if_next)#else for (sptr_ifnet = ifnet; sptr_ifnet; sptr_ifnet = sptr_ifnet->if_next)#endif /* VIRTUAL_STACK */ { 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; } /* check the sin family type for Internet */ if (sptr_interface_address->ia_addr.sin_family != AF_INET) { continue; } if (sptr_interface_address->ia_addr.sin_addr.s_addr == ip_address) { if (sptr_ifnet->if_flags &IFF_UP) { splx(s); semTake (ospf_global_mutex , WAIT_FOREVER); return (TRUE); } else OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: INTERFACE DOWN with address (HEX) %lx\r\n", ip_address); } } /* for */ }/*for */ splx(s); semTake (ospf_global_mutex , WAIT_FOREVER); return (FALSE);}#if defined (__UNNUMBERED_LINK__) /* __UNNUMBERED_LINK__ver1.0 */ /*************************************************************************** this routine will scan the I/F table to see if the the unnumbered interfaces* exists and it's also UP ***************************************************************************//*************************************************************************** ospf_is_if_unnumbered_up - checks if the unnumbered interface is up** This routine will check IP if the interface is up** <sptr_interface> OSPF interface** RETURNS: TRUE or FALSE** ERRNO: N/A** NOMANUAL*/enum BOOLEAN ospf_is_if_unnumbered_up(OSPF_INTERFACE *sptr_interface){ struct ifnet *sptr_ifnet; struct ifaddr *sptr_ifaddr; struct in_addr ip_address; ULONG interface_address = 0x00000000; sptr_ifnet = NULL; sptr_ifaddr = NULL; OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_is_if_unnumbered_up\r\n"); interface_address = sptr_interface->unnumbered_dest_ip; /* check to see if this interface is actually an unnumbered interface */ if(interface_address == 0) { OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: PORT%d is not an UNNUMBERED Interface!!\n",sptr_interface->port_number); return(false); } else { interface_address = host_to_net_long(interface_address); ip_address.s_addr = interface_address; } /* with the destination ip find the corresponding IF from the IP stack */ sptr_ifnet = dstaddr_to_ifp(ip_address); if ((sptr_ifnet != NULL) && (sptr_ifnet->if_flags & IFF_UP)) { return (true); } else { OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Unnumbered PORT%s is DOWN!!\r\n", sptr_interface->port_number); return(false); }}#endif /* __UNNUMBERED_LINK__ver1.0 *//**************************************************************************************This routine scans IF list and returns 1 if the IF is up and 0 if IF is down.***************************************************************************************//*************************************************************************** check_if_status - checks interface status** This routine will check IP for the interfaces status of * being up or down.** <if_index> Interface index** RETURNS: INT** ERRNO: N/A** NOMANUAL*/enum BOOLEAN check_if_status( unsigned short if_index ){ struct ifnet *sptr_ifnet; int s; sptr_ifnet = NULL;#if defined (VIRTUAL_STACK) virtualStackNumTaskIdSet (ospf.ospf_vsid);#endif /* VIRTUAL_STACK */ s = splimp ();#if defined (VIRTUAL_STACK) for (sptr_ifnet = _ifnet; sptr_ifnet; sptr_ifnet = sptr_ifnet->if_next)#else for (sptr_ifnet = ifnet; sptr_ifnet; sptr_ifnet = sptr_ifnet->if_next)#endif /* VIRTUAL_STACK */ { if( sptr_ifnet->if_index == if_index ) { if( sptr_ifnet->if_flags & IFF_UP) { splx (s); return(true); } else { splx (s); return(false); } } } splx (s); return(false);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -