📄 ospf_hello.c
字号:
/* On a point to point or virtual link, always send directly to connected neighbor, this need to be configured */ *sptr_destination_router = ospf_determine_destination (sptr_interface, sptr_interface->sptr_neighbor); if (goingdown == FALSE) { /* DC1: end modification */ if (sptr_neighbor != NULL) { 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; }#if defined ( __RFC_2328__) /* RFC 2178 Section G.2 */ case OSPF_POINT_TO_MULTIPOINT: { ospf_setup_to_send_on_a_point_to_multipoint_network (sptr_interface, sptr_neighbor, goingdown, sptr_destination_router, ulptr_recently_seen_neighbor, sptr_packet, ulptr_length_of_packet); break; }#endif /* __RFC_2328__ */ default: { *sptr_destination_router = 0x00000000L; /* something's not right, so don't send to anyone */ break; } } return;}/*************************************************************************** ospf_setup_to_send_on_an_NBMA_network - set up the hello packet to send on an NBMA network** This routine will set up the hello packet to be sent over* an NBMA network. It will find the appropriate neighbors to* send the hello packet to.** <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_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 ) { OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_setup_to_send_on_an_NBMA_network\r\n"); if (sptr_neighbor != NULL) { *sptr_destination_router = sptr_neighbor->address; /* If provided with a neighbor pointer, just send to that neighbor */ if (goingdown == FALSE) { ulptr_recently_seen_neighbor = ospf_add_neighbor_to_end_of_hello_packet (ulptr_recently_seen_neighbor, sptr_neighbor->id, ulptr_length_of_packet); } } else { /* * Figure out which group to send to and include the smallest subset of neighbors possible. Ideally we would only * include the neighbor we are sending the packet to, but the overhead of sending the packet is potentially too great */ switch (sptr_interface->state) { case OSPF_INTERFACE_DESIGNATED_ROUTER_OTHER: { ospf_setup_to_send_to_designated_router_and_backup_designated_router (sptr_interface, sptr_destination_router, ulptr_recently_seen_neighbor, goingdown, ulptr_length_of_packet); break; } case OSPF_INTERFACE_WAITING: { ospf_setup_to_send_to_all_eligible_neighbors (sptr_interface, sptr_destination_router, ulptr_recently_seen_neighbor, goingdown, sptr_neighbor, ulptr_length_of_packet); break; } case OSPF_INTERFACE_DESIGNATED_ROUTER: case OSPF_INTERFACE_BACKUP_DESIGNATED_ROUTER: { ospf_setup_to_send_to_all_neighbors_in_up_state (sptr_interface, sptr_destination_router, ulptr_recently_seen_neighbor, goingdown, sptr_neighbor, sptr_packet, ulptr_length_of_packet); break; } default: { /* something's not right, so don't send to anyone */ *sptr_destination_router = 0x00000000L; break; } } } }#if defined (__RFC_2328__)/*RFC 2178 G.2 *//*************************************************************************** ospf_setup_to_send_on_a_point_to_multipoint_network - set up the hello packet to send on point to multipoint network** This routine will set up the hello packet to be sent over* a point to multipoint network. It will find the appropriate neighbors to* send the hello packet to.** <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_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){ OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_setup_to_send_on_a_point_to_multipoint_network\r\n"); if (sptr_neighbor != NULL) { *sptr_destination_router = sptr_neighbor->address; /* If provided with a neighbor pointer, just send to that neighbor */ if (goingdown == FALSE) { ulptr_recently_seen_neighbor = ospf_add_neighbor_to_end_of_hello_packet (ulptr_recently_seen_neighbor, sptr_neighbor->id, ulptr_length_of_packet); } } else { ospf_setup_to_send_to_all_neighbors_in_exchange_state (sptr_interface, sptr_destination_router, ulptr_recently_seen_neighbor, goingdown, sptr_neighbor, sptr_packet, ulptr_length_of_packet); } return;}#endif /* __RFC_2328__ *//*************************************************************************** ospf_setup_to_send_to_designated_router_and_backup_designated_router - set up the designated router and backup designated router** This routine will set the hello packet to be sent to the* designated router and backup designated router.** <sptr_interface> OSPF interface** <sptr_destination_router> Destination router** <ulptr_recently_seen_neighbor> Recently seen neighbor identifier** <going_down> Whether or not the router is going down** <ulptr_length_of_packet> Length of hello packet** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/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){ OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_setup_to_send_to_designated_router_and_backup_designated_router\r\n"); *sptr_destination_router = OSPF_DESIGNATED_ROUTER_AND_BACKUP_DESIGNATED_ROUTER; if (goingdown == FALSE) { ulptr_recently_seen_neighbor = ospf_add_neighbor_to_end_of_hello_packet (ulptr_recently_seen_neighbor, sptr_interface->designated_router.id, ulptr_length_of_packet); ulptr_recently_seen_neighbor = ospf_add_neighbor_to_end_of_hello_packet (ulptr_recently_seen_neighbor, sptr_interface->backup_designated_router.id, ulptr_length_of_packet); } return;}/*************************************************************************** ospf_setup_to_send_to_all_eligible_neighbors - set up the hello packet to send to all eligible neighbors** This routine will set the hello packet to be sent to all* eligible neighbors.** <sptr_interface> OSPF interface** <sptr_destination_router> Destination router** <ulptr_recently_seen_neighbor> Recently seen neighbor identifier** <going_down> Whether or not the router is going down** <sptr_neighbor> Neighbor associated with the interface** <ulptr_length_of_packet> Length of hello packet** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/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){ OSPF_NEIGHBOR *sptr_next_neighbor = NULL; OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_setup_to_send_to_all_eligible_neighbors\r\n"); *sptr_destination_router = OSPF_ALL_ELIGIBLE_NEIGHBORS; 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->priority) { ulptr_recently_seen_neighbor = ospf_add_neighbor_to_end_of_hello_packet (ulptr_recently_seen_neighbor, sptr_neighbor->id, ulptr_length_of_packet); } } } return;}/*************************************************************************** ospf_setup_to_send_to_all_neighbors_in_up_state - set up the hello packet to send to all neighbors in up state** This routine will set the hello packet to be sent to all* neighbors in up state.** <sptr_interface> OSPF interface** <sptr_destination_router> Destination router** <ulptr_recently_seen_neighbor> Recently seen neighbor identifier** <going_down> Whether or not the router is going down** <sptr_neighbor> Neighbor associated with the interface** <sptr_packet> Hello packet header** <ulptr_length_of_packet> Length of hello packet** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/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){ ULONG interface_mtu; ULONG number_of_neighbors; ULONG authentication_size; OSPF_NEIGHBOR *sptr_next_neighbor = NULL; OSPF_PRINTF_PROLOGUE (OSPF_PROLOGUE_PRINTF, "OSPF: Entering ospf_setup_to_send_to_all_neighbors_in_up_state\r\n"); *sptr_destination_router = OSPF_ALL_UP_NEIGHBORS; if (goingdown == FALSE) { /* * There is less processing overhead in sending one packet with all neighbors listed. A large number of neighbors could require * more buffer space than is allowed on a socket. First build a packet with all neighbors listed. If this packet replicated by * the number of neighbors is greater than the available buffer space, or the packet is greater than the interface MTU, make a * packet for each neighbor with only it's ID listed. */ 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; if (sptr_neighbor->state != OSPF_NEIGHBOR_DOWN) { ++number_of_neighbors; } } interface_mtu = ospf_get_interface_mtu (sptr_interface); authentication_size = ospf_get_authentication_size (sptr_interface); if ((*ulptr_length_of_packet + (number_of_neighbors * sizeof (ULONG)) + authentication_size) > interface_mtu) { /* Better to absorb the overhead of sending an individual packet to each neighbor */ 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) { ulptr_recently_seen_neighbor = &(sptr_packet->rest_of_packet.hello.neighbor); *ulptr_length_of_packet = OSPF_PACKET_SIZE + OSPF_HELLO_HEADER_SIZE; ulptr_recently_seen_neighbor = ospf_add_neighbor_to_end_of_hello_packet (ulptr_recently_seen_neighbor, sptr_neighbor->id, ulptr_length_of_packet); ospf_tx_packet (sptr_packet, sptr_interface, OSPF_HELLO_PACKET, *ulptr_length_of_packet, *sptr_destination_router, FALSE); } } ospf_free_an_ospf_send_packet (sptr_packet); *sptr_destination_router = 0x00000000L; /* done sending all hello packets, so clear the destination variable */ } else { 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) { ulptr_recently_seen_neighbor = ospf_add_neighbor_to_end_of_hello_packet (ulptr_recently_seen_neighbor, sptr_neighbor->id, ulptr_length_of_packet); } } } } return;}#if defined (__RFC_2328__)/* RFC 2178 G.2 *//*************************************************************************** ospf_setup_to_send_to_all_neighbors_in_exchange_state - set up the hello packet to send to all neighbors in exchange state** This routine will set the hello packet to be sent to all* neighbors in exchange state.** <sptr_interface> OSPF interface** <sptr_destination_router> Destination router** <ulptr_recently_seen_neighbor> Recently seen neighbor identifier** <going_down> Whether or not the router is going down** <sptr_neighbor> Neighbor associated with the interface** <sptr_packet> Hello packet header** <ulptr_length_of_packet> Length of hello packet** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/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)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -