📄 ospf_sysctl.c
字号:
/* ospf_sysctl.c - Management Interface Helper routines for sysctl *//* Copyright 2001-2003 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02l,09sep03,agi Added missing semGive(ospf_global_mutex)02k,28may03,agi Changed type of mutexAcquired to STATUS02g,24may03,agi Removed debug statements02i,14may03,agi Changed RWOS semaphores to vxWorks semaphores02h,22apr03,ram SPR#76812 Modifications for OSPF performance enhancements02g,17feb02,ram SPR 81808 Added OSPF memory partition support02f,28jan03,ram SPR 85050 Added support for external route redistribution based on OSPF external metric values02e,16jan03,smr SPR 78250 Added case for M2_ipRouteProto_other for UNH 3.2102d,14jan03,asr SPR 85632 Disallow redistribution of loopback address02a,20dec02,ram SPR 83418 Added support for external route metric type and value01h,20nov02,kc Modified ospf_sysctl_interfaceFlagChange() to flush the network-LSA using ospf_flush_network_link_advertisement(). SPR 84478, 84485, 8448601g,18Nov02,hme Fixed ospf_sysctl_interfaceFlagChange(). When a router that has formerly been the Designated Router for a network, but is no longer, should flush the network-LSA that it had previously installed. SPR 84478, 84485, 8448601f,19nov02,mwv Merge TMS code SPR 8428401e,25sep02,hme Fixed TSR# 291665 (Lucent/ProcSys Issue #26). If __OSPF_MIB__ is not defined, ospf_sysctl_interfaceFlagChange() needs to do the following: (1) bring up an interface if it receives an interface up notification and bring down an interface if it receives an interface down notification. (2) send out router lsa to all areas if the ABR status for the router is changed when interface is added or deleted.01d,18sep02,agi Added ospf_compare_sysctl_rtableWalk()01d,21aug02,kc Fixed ospf2Mapi_request() in ospf_sysctl_interfaceAddrDelete().01c,26jun02,kc Simplified ospf_sysctl_interfaceFlagChange().01b,30may02,kc Fixed PR #2078 - Added ospf_sysctl_rtableWalk() routine to retrieve the routing table from kernel.01a,24may02,kc Initial file creation.*//*DESCRIPTIONThis file contains method routines required to process routing socket messagesreceived by the tRtmOspf task. All method routines in this file expects tooperate in the environment using the WindNet Router Stack 1.0 (or newer).The routine ospf_sysctl_input() is used to process selected routing socketmessages from tRtmOspf task. This routine is invoked by the tRtmOspf task toprocess the RTM_NEWADDR, RTM_DELADDR and RTM_IFINFO routing socket messages.The routine ospf_sysctl_rtableWalk() is used to retrieve routing tableinformation from the kernel. This routine is executed during the OSPF protocolstartup to retrieve any AF_INET famility gateway routes that may need to beredistributed by OSPF to the neighboring routers.*/#if defined(__RTM_FOR_SYNTH__)/* VxWorks standard includes */#include <stdio.h>#include <stdlib.h>#include <vxWorks.h>#include <ctype.h>#include <semLib.h>#include <netinet/in.h>#include <netinet/in_var.h>#include <net/if.h>#include <net/if_dl.h>#include <inetLib.h>#include <m2Lib.h>/* ospf includes */#include "ospf.h"#include "rtMessageLib.h"int sysCtlDebug = 0; /* turn it off initially */IMPORT int sysctl_rtable (int *, int, caddr_t, size_t *, caddr_t *, size_t);/********************************************************************************* ospf_sysctl_interfaceAddrDelete - process interface delete routing socket* message** This routine process the interface delete routing socket message. It is* invoked when * the RTM_DELADDR routing message is received.** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/LOCAL void ospf_sysctl_interfaceAddrDelete ( ushort_t interface_index, struct sockaddr *sptr_interface_addr ) { STATUS mutexAcquired; STATUS rc; OSPF_INTERFACE *sptr_interface = NULL; OSPF_INTERFACE *sptr_next_interface = NULL; ulong_t interface_addr; /* extract the interface address from the sockaddr */ interface_addr = ((struct sockaddr_in *)sptr_interface_addr)->sin_addr.s_addr; if ( sysCtlDebug ) { char address[32]; inet_ntoa_b( ((struct sockaddr_in *)sptr_interface_addr)->sin_addr, address ); printf ("ospf_sysctl_interfaceAddrDelete: got %-17s", address); } /* convert the interface address to host order */ interface_addr = ntohl(interface_addr);#if defined(__OSPF_MIB__) { ospf2MapiSysCtl_t msg; /* construct the MIB API control message */ memset( (char *)&msg, 0, sizeof(ospf2MapiSysCtl_t) ); msg.if_index = interface_index; msg.pCtlData = (void *)interface_addr; /* tell MIB API to delete this interface from its database */ ospf2Mapi_request( (void *)&msg, ospfIfDeleteReqType ); }#endif /* __OSPF_MIB__ */ /* lock the ospf mutex semaphore for exclusive access to ospf structure */ mutexAcquired = semTake (ospf_global_mutex, WAIT_FOREVER); if ( mutexAcquired == ERROR ) { if ( sysCtlDebug ) printf("ospf_sysctl_interfaceAddrDelete:failed to acquire ospf mutex!\n"); return; } 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_addr) && (sptr_interface->ifnet_index == interface_index) ) { /* dynamically tear down this interface */ rc = ospf_dynamic_destroy_interface( sptr_interface, sptr_interface->sptr_area ); if ( rc == ERROR ) { if ( sysCtlDebug ) printf("ospf_sysctl_interfaceAddrDelete:ospf_dynamic_destroy_interface failed\n"); } } } semGive (ospf_global_mutex); }/********************************************************************************* ospf_sysctl_interfaceFlagChange - process interface flag change routing socket* message** This routine process the interface flag chanage routing socket message. It is* invoked when the RTM_IFINFO routing message is received.** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/LOCAL void ospf_sysctl_interfaceFlagChange( ushort_t interface_index, ulong_t interface_flags ){ STATUS mutexAcquired; BOOL up;#if !defined(__OSPF_MIB__) OSPF_INTERFACE *sptr_interface; /* Fix TSR# 291665 Begin */ enum BOOLEAN was_I_an_area_border_router = FALSE; enum BOOLEAN am_I_an_area_border_router = FALSE; /* Fix TSR# 291665 End */#endif /* __OSPF_MIB__ */ if ( (interface_flags & IFF_UP) == IFF_UP ) up = TRUE; else up = FALSE;#if defined(__OSPF_MIB__) { ospf2MapiSysCtl_t msg; /* construct the MIB API control message */ memset( (char *)&msg, 0, sizeof(ospf2MapiSysCtl_t) ); msg.if_index = interface_index; msg.pCtlData = (void *)interface_flags; /* tell MIB API to update its interface flag */ ospf2Mapi_request( (void *)&msg, ospfIfChangeReqType ); }#endif /* __OSPF_MIB__ */ /* lock the ospf mutex semaphore for exclusive access to ospf structure */ mutexAcquired = semTake (ospf_global_mutex, WAIT_FOREVER); if ( mutexAcquired == ERROR ) { if ( sysCtlDebug ) printf("ospf_sysctl_interfaceFlagChange:failed to acquire ospf mutex!\n"); return; }/* Fix TSR# 291665 Begin */#if !defined(__OSPF_MIB__) /* if receive an interface up notification while the ospf-interface-state * for that interface is DOWN, bring up the interface. Otherwise, if receive * an interface down notification bring down the interface. */ for (sptr_interface = ospf.sptr_interface_list; sptr_interface != NULL; sptr_interface=sptr_interface->sptr_forward_link) { if (sptr_interface->ifnet_index == interface_index) { if ((up == TRUE) && (sptr_interface->state == OSPF_INTERFACE_IS_DOWN)) { was_I_an_area_border_router = ospf_check_if_area_border_router (); sptr_interface->sptr_area->build_router = TRUE; ospf_bring_up_interface(sptr_interface); am_I_an_area_border_router = ospf_check_if_area_border_router (); } else if (up == FALSE) { /* SPR 84478, 84485, 84486 -- Begin */ /************************************************************************ * A router that has formerly been the Designated Router for a network, * but is no longer, should flush the network-LSA that it had previously. ***********************************************************************/ ospf_flush_network_link_advertisement( sptr_interface ); /* SPR 84478, 84485, 84486 -- End */ was_I_an_area_border_router = ospf_check_if_area_border_router (); sptr_interface->sptr_area->build_router = TRUE; ospf_process_interface_down_event(sptr_interface); am_I_an_area_border_router = ospf_check_if_area_border_router (); } break; } } if (am_I_an_area_border_router != was_I_an_area_border_router) { /* SPR 84478, 84485, 84486 -- Begin */ /* if the area border router status has changed, notiify all other areas * about the changes.Skip the interface where the new interface is connected * since the area has gone through the link state database exchange process * when the interface is first brought up in that area */ ospf_notify_areas_for_abr_change( sptr_interface->area_id ); /* SPR 84478, 84485, 84486 -- End */ }#endif/* Fix TSR# 291665 End */ /* if receive the interface up notification and if ospf is configured as * autonomous system border router, walk the kernel routing table to * retrieve any external routes that may need to be exported. This is * necessary because at the time the routing table is read during ospf * startup, some of those external routes may have been previously ignored * due to RTF_BLACKHOLE flag set. With the interface up notification, the * RTF_BLACKHOLE flag would now be cleared. */ if ( up == TRUE ) { if ( ospf.autonomous_system_border_router == TRUE ) { ospf_sysctl_rtableWalk( ospf.autonomous_system_border_router, ospf.ospf_redistribution_configuration.redistribute_all_static, ospf.ospf_redistribution_configuration.redistribute_all_rip, ospf.ospf_redistribution_configuration.redistribute_all_bgp, ospf.ospf_redistribution_configuration.redistribute_ip_default_route); } } semGive (ospf_global_mutex); }/********************************************************************************* ospf_sysctl_input - process selected routing socket messages from tRtmOspf task.** This routine process the selected routing socket message from tRtmOspf task. This* routine is registered as the second to last argument to the protocol_rtm_init() and* is invoked by the tRtmOspf task.** RETURNS: N/A** ERROR: N/A*/void ospf_sysctl_input( int rsock_message, ushort_t interface_index, void *sptr_ctl_data ){ switch (rsock_message) { case RTM_NEWADDR: /* not yet */ break; case RTM_DELADDR: { struct sockaddr *sptr_interface_addr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -