📄 ospf_transmit.c
字号:
/* include digest in packet's IP length field (not OSPF packet's length field) */ *ulptr_length = ((ULONG) *ulptr_length) + OSPF_AUTHENTICATION_MD5_SIZE; mdString ( (BYTE *) sptr_packet, (ULONG) *ulptr_length, bptr_digest, MD5); /* append digest to the end of the OSPF packet (i.e. the digest is written over the OSPF key) */ memcpy ((void *) bptr_end_of_packet, (const void *) bptr_digest, (size_t) OSPF_AUTHENTICATION_MD5_SIZE); break; } default: { sptr_packet->authentication_type = OSPF_AUTHENTICATION_NONE; sptr_packet->authentication_type = net_to_host_short (sptr_packet->authentication_type); memset ( (void *) &(sptr_packet->authentication_field.key_or_plain_text_passwd), 0x00, OSPF_AUTHENTICATION_SIMPLE_SIZE); sptr_packet->checksum = 0x0000; sptr_packet->checksum = calculate_ip_checksum (NULL, (BYTE *) sptr_packet, (USHORT) *ulptr_length /* in host order */); break; } } return OK;}/**************************************************************************************************************************************/static OSPF_AUTHENTICATION_KEY *ospf_get_best_key_to_use_for_md5_authentication (OSPF_INTERFACE *sptr_interface){ ULONG current_time; OSPF_AUTHENTICATION_KEY *sptr_authentication_key_to_use; OSPF_AUTHENTICATION_KEY *sptr_authentication_key; OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_get_best_key_to_use_for_md5_authentication\r\n"); /* SPR 84312 -- Begin */ current_time = ospf_get_system_elapsed_time_second (); /* SPR 84312 -- End */ sptr_authentication_key_to_use = NULL; for (sptr_authentication_key = sptr_interface->sptr_authentication_key; sptr_authentication_key != NULL; sptr_authentication_key = sptr_authentication_key->sptr_forward_link) { if ((sptr_authentication_key->key_start_generate <= current_time) && ((sptr_authentication_key->key_stop_generate > current_time) || (sptr_authentication_key->key_stop_generate == 0x00000000L))) { if (sptr_authentication_key_to_use != NULL) { if (sptr_authentication_key_to_use->key_start_generate < sptr_authentication_key->key_start_generate) { sptr_authentication_key_to_use = sptr_authentication_key; } } else { sptr_authentication_key_to_use = sptr_authentication_key; } } } if (sptr_authentication_key_to_use == NULL) { return (0x0000); } else { return (sptr_authentication_key_to_use); }}/**************************************************************************************************************************************/static void ospf_send_packet_to_all_neighbors_in_up_state (OSPF_HEADER *sptr_packet,ULONG length /* in host order */, OSPF_INTERFACE *sptr_interface,enum BOOLEAN free_packet){ OSPF_NEIGHBOR *sptr_neighbor = NULL; OSPF_NEIGHBOR *sptr_next_neighbor = NULL; OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_send_packet_to_all_neighbors_in_up_state\r\n"); 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_DOWN) { ospf_send_packet (sptr_packet, length /* in host order */, sptr_neighbor->address, sptr_interface, free_packet); } } return;}/**************************************************************************************************************************************/static void ospf_send_packet_to_all_eligible_neighbors (OSPF_HEADER *sptr_packet,ULONG length /* in host order */, OSPF_INTERFACE *sptr_interface,enum BOOLEAN free_packet){ OSPF_NEIGHBOR *sptr_neighbor = NULL; OSPF_NEIGHBOR *sptr_next_neighbor = NULL; OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_send_packet_to_all_eligible_neighbors\r\n"); 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->priority != 0x0000) { ospf_send_packet (sptr_packet, length /* in host order */, sptr_neighbor->address, sptr_interface, free_packet); } } return;}/**************************************************************************************************************************************/static void ospf_send_packet_to_all_neighbors_in_exchange_state (OSPF_HEADER *sptr_packet,ULONG length /* in host order */, OSPF_INTERFACE *sptr_interface,enum BOOLEAN free_packet){ OSPF_NEIGHBOR *sptr_neighbor = NULL; OSPF_NEIGHBOR *sptr_next_neighbor = NULL; OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_send_packet_to_all_neighbors_in_exchange_state\r\n"); 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_EXCHANGE) { ospf_send_packet (sptr_packet, length /* in host order */, sptr_neighbor->address, sptr_interface, free_packet); } } return;}/**************************************************************************************************************************************/static void ospf_send_packet_to_designated_router_and_backup_designated_router (OSPF_HEADER *sptr_packet,ULONG length /* in host order */, OSPF_INTERFACE *sptr_interface,enum BOOLEAN free_packet){ OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_send_packet_to_designated_router_and_backup_designated_router\r\n"); if (sptr_interface->designated_router.address != 0x00000000L) { ospf_send_packet (sptr_packet, length /* in host order */, sptr_interface->designated_router.address, sptr_interface, free_packet); } if (sptr_interface->backup_designated_router.address != 0x00000000L) { ospf_send_packet (sptr_packet, length /* in host order */, sptr_interface->backup_designated_router.address, sptr_interface, free_packet); } return;}/*raw socket - Removed building ip header for OSPF packet and *added sptr_packet and length to ospf_vx_ip_output. These two *variables were needed for sockets jkw*//**************************************************************************************************************************************/static void ospf_send_packet (OSPF_HEADER *sptr_packet,ULONG length /* in host order */,ULONG destination_address, OSPF_INTERFACE *sptr_interface,enum BOOLEAN free_packet){ bool flag_multicast; OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_send_packet\r\n"); if ((destination_address == OSPF_ADDR_ALLSPF) ||(destination_address == OSPF_ADDR_ALLDR)) { flag_multicast = true; } else { flag_multicast = false; } if (ospf_validate_interface(sptr_interface->address) != TRUE) { if (free_packet == TRUE) ospf_free_an_ospf_send_packet (sptr_packet); return; } if (sptr_interface->type != OSPF_VIRTUAL_LINK); else { /* * Packet is going out on Virtual Link. Destination can never be Multicast address */ flag_multicast = false;/* bhanu - fix for correcting the destination address from RID to IpAddress */ destination_address = ospf_virtual_link_convert_rid_to_interface_addresss( destination_address, sptr_interface->sptr_transit_area);/* end of fix - bhanu */ } ospf_display_ospf_header (sptr_packet, FALSE); ospf_vx_ip_output (sptr_packet, sptr_interface->address/*source address*/, flag_multicast, destination_address, length, free_packet); return;}/******************************************************************************/static ULONG ospf_virtual_link_convert_rid_to_interface_addresss ( ULONG destination_address, OSPF_AREA_ENTRY *sptr_transit_area ) { ULONG virtual_address = 0x00000000; OSPF_LS_DATABASE_ENTRY *sptr_database_entry = NULL; if (sptr_transit_area == NULL) { return destination_address; } /* SPR#76812 -- Begin */ sptr_database_entry = ospf_find_LSA(sptr_transit_area, destination_address, 0x00000000, OSPF_LS_ROUTER); if (sptr_database_entry == NULL) { return destination_address; } else { if(sptr_database_entry->advertisement.sptr_router != NULL) { virtual_address = sptr_database_entry->advertisement.sptr_router->link.link_data; return net_to_host_long (virtual_address); } } return destination_address; /* SPR#76812 -- End */ }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -