📄 igmp_initialize.c
字号:
/*
$Log:: /OEM Source Code/igmp/igmp_initialize.c $
*
* 1 4/23/98 9:53p Release Engineer
* Initial release
* IGMP v4.1.0
*/
/************************************************************************/
/* Copyright (C) 1997-1998 RouterWare, Inc. */
/* Unpublished - rights reserved under the Copyright Laws of the */
/* United States. Use, duplication, or disclosure by the */
/* Government is subject to restrictions as set forth in */
/* subparagraph (c)(1)(ii) of the Rights in Technical Data and */
/* Computer Software clause at 252.227-7013. */
/* RouterWare, Inc., 3961 MacArthur Blvd. Suite 212, Newport Beach, CA */
/************************************************************************/
#define GLOBAL_FILE
#include <stdlib.h>
#include <memory.h>
#include "igmp.h"
/********************************************************************************************/
static void igmp_register_with_mfapi (void);
static void check_for_igmp_initialization_breakpoint (void);
/********************************************************************************************/
enum TEST initialize_igmp (ULONG clock_ticks_per_second)
{
UINT port;
check_for_igmp_initialization_breakpoint ();
if (igmp.enabled == FALSE)
{
IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP: Not enabled. Cannot initialize.\n");
return (PASS);
}
if (igmp.number_of_ports == 0x0000)
{
IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP: Number of ports not defined. Cannot initialize.\n");
return (FAIL);
}
if (igmp.number_of_ports > NUMBER_OF_IP_PORTS)
{
IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP: Too many ports defined. Cannot initialize.\n");
return (FAIL);
}
#if defined (__LSL__)
if ((enum TEST) lsl_control (REGISTER_PROTOCOL_STACK, "IGMP", NULL, igmp_timer, igmp_control,
&igmp.stack_id, igmp_get_mib_variable) == FAIL)
{
IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP: Failed to register with LSL.\n");
return (FAIL);
}
#endif /*__LSL__*/
if (ip_register_upper_layer_protocol (IGMP_PROTOCOL,igmp_receive_packet,NULL) == FAIL)
{
IGMP_PROTOCOL_ALARM_TRACE (IGMP_ALARM_TRACE, "IGMP: Failed to register with IP.\n");
return (FAIL);
}
igmp.tick_counter = 0;
igmp.clock_ticks_per_second = clock_ticks_per_second;
/* note SNMP TimeTick variables are incremented every 1/100 th of a second */
igmp.number_of_snmp_time_ticks_per_clock_tick = 100/clock_ticks_per_second;
for (port = 0; port < igmp.number_of_ports; ++port)
{
initialize_igmp_port (port);
}
igmp_register_with_mfapi ();
IGMP_PROTOCOL_TRACE (IGMP_TRACE, "IGMP: Initialized.\n");
return (PASS);
}
/********************************************************************************************/
void initialize_igmp_port (UINT port)
{
if (igmp.port_table[port].version == 0)
{
igmp.port_table[port].version = IGMP_VERSION_2;
}
if (igmp.port_table[port].robustness == 0)
{
igmp.port_table[port].robustness = IGMP_DEFAULT_ROBUSTNESS_VALUE;
}
igmp.port_table[port].port_number = port;
igmp.port_table[port].ip_address_of_port = igmp_get_ip_address_for_port_from_ip (port);
igmp.port_table[port].ip_address_of_querier = 0x00000000L;
if (igmp.port_table[port].max_response_time_from_most_recent_query == 0)
{
igmp.port_table[port].max_response_time_from_most_recent_query = IGMP_HOST_DEFAULT_V1_MAX_RESPONSE_TIME; /* seconds */
}
if (igmp.port_table[port].router_enabled == TRUE)
{
igmp.port_table[port].router_port.state = IGMP_ROUTER_PORT_QUERIER_STATE;
igmp.port_table[port].router_port.initializing = TRUE;
igmp.port_table[port].router_port.number_of_startup_queries_sent = 0;
if (igmp.port_table[port].router_port.number_of_startup_queries_to_send == 0)
{
igmp.port_table[port].router_port.number_of_startup_queries_to_send = IGMP_DEFAULT_ROBUSTNESS_VALUE;
}
if (igmp.port_table[port].router_port.general_query_interval == 0)
{
igmp.port_table[port].router_port.general_query_interval = IGMP_DEFAULT_GENERAL_QUERY_INTERVAL;
}
if (igmp.port_table[port].router_port.startup_query_interval == 0)
{
igmp.port_table[port].router_port.startup_query_interval = igmp.port_table[port].router_port.general_query_interval / 4;
}
if (igmp.port_table[port].router_port.general_query_max_response_time == 0)
{
igmp.port_table[port].router_port.general_query_max_response_time = IGMP_DEFAULT_GENERAL_QUERY_MAX_RESPONSE_INTERVAL;
}
igmp_router_tx_message (port, 0x00000000L);
igmp_enable_timer (&igmp.port_table[port].router_port.general_query_timer, igmp.port_table[port].router_port.startup_query_interval);
}
if (igmp.port_table[port].host_enabled == TRUE)
{
igmp.port_table[port].host_port.v1_router_present = FALSE;
igmp.port_table[port].host_port.v1_router_present_timer = 0;
}
memset (&igmp.port_table[port].igmpInterfaceEntry, 0, sizeof (IGMP_MIB_INTERFACE_ENTRY));
igmp.port_table[port].igmpInterfaceEntry.igmpInterfaceIfIndex = port;
igmp.port_table[port].igmpInterfaceEntry.igmpInterfaceQueryInterval = igmp.port_table[port].router_port.general_query_interval;
igmp.port_table[port].igmpInterfaceEntry.igmpInterfaceStatus = igmp.port_table[port].router_enabled;
igmp.port_table[port].igmpInterfaceEntry.igmpInterfaceVersion = igmp.port_table[port].version;
igmp.port_table[port].igmpInterfaceEntry.igmpInterfaceQueryMaxResponseTime = igmp.port_table[port].router_port.general_query_max_response_time;
igmp.port_table[port].igmpInterfaceEntry.igmpInterfaceRobustness = igmp.port_table[port].robustness;
}
/********************************************************************************************/
static void igmp_register_with_mfapi (void)
{
MCAST_ROUTER_REGISTRATION_INFORMATION mfapi_registration_information;
MFAPI_ACTIVE_INTERFACE_NODE *sptr_interface_information;
UINT port;
memset (&mfapi_registration_information, 0, sizeof (MCAST_ROUTER_REGISTRATION_INFORMATION));
mfapi_registration_information.protocol_type = IGMPv2;
mfapi_registration_information.protocol_priority = IGMP_PROTOCOL_PRIORITY_FOR_MFAPI;
mfapi_registration_information.mcast_router_do_you_want_to_forward_this_packet = NULL;
mfapi_registration_information.mcast_router_send_graft_message = NULL;
mfapi_registration_information.mcast_router_send_prune_message = NULL;
mfapi_registration_information.mcast_router_should_this_packet_be_accepted_on_this_in_interface = NULL;
mfapi_registration_information.mcast_router_return_cost_metric_for_this_source = NULL;
mfapi_registration_information.number_of_active_interfaces = 0x00000000L;
for (port = 0;port < igmp.number_of_ports; ++port)
{
if (igmp.port_table[port].router_enabled == TRUE)
{
sptr_interface_information = (MFAPI_ACTIVE_INTERFACE_NODE *) table_malloc (1,sizeof (MFAPI_ACTIVE_INTERFACE_NODE));
if (sptr_interface_information == NULL)
{
for (sptr_interface_information = (MFAPI_ACTIVE_INTERFACE_NODE *) get_pointer_to_first_entry_in_list ((LINK *) &mfapi_registration_information.active_interface_list);
sptr_interface_information != NULL;
sptr_interface_information = (MFAPI_ACTIVE_INTERFACE_NODE *) get_pointer_to_next_entry_in_list ((LINK *) sptr_interface_information))
{
delete_entry_from_list ((LINK *) &mfapi_registration_information.active_interface_list, (LINK *) sptr_interface_information);
table_free (sptr_interface_information);
}
return;
}
memset (sptr_interface_information, 0, sizeof (MFAPI_ACTIVE_INTERFACE_NODE));
sptr_interface_information->active_interface_number = port;
add_entry_to_list ((LINK *)&mfapi_registration_information.active_interface_list, (LINK *)sptr_interface_information);
++mfapi_registration_information.number_of_active_interfaces;
}
}
mcast_router_register_with_mfapi (&mfapi_registration_information);
}
/********************************************************************************************/
static void check_for_igmp_initialization_breakpoint (void)
{
if (igmp.initialization_breakpoint == TRUE)
{
BREAKPOINT;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -