summaryrefslogtreecommitdiffstats
path: root/eigrpd/eigrpd.c
diff options
context:
space:
mode:
Diffstat (limited to 'eigrpd/eigrpd.c')
-rw-r--r--eigrpd/eigrpd.c332
1 files changed, 159 insertions, 173 deletions
diff --git a/eigrpd/eigrpd.c b/eigrpd/eigrpd.c
index 2fa8296ce..99d88b2d0 100644
--- a/eigrpd/eigrpd.c
+++ b/eigrpd/eigrpd.c
@@ -37,7 +37,7 @@
#include "memory.h"
#include "stream.h"
#include "log.h"
-#include "sockunion.h" /* for inet_aton () */
+#include "sockunion.h" /* for inet_aton () */
#include "zclient.h"
#include "plist.h"
#include "sockopt.h"
@@ -91,232 +91,218 @@ extern struct in_addr router_id_zebra;
* This does not work for IPv6, and to make the code simpler, its
* stored and processed internerall as a 32bit number
*/
-void
-eigrp_router_id_update (struct eigrp *eigrp)
+void eigrp_router_id_update(struct eigrp *eigrp)
{
- struct interface *ifp;
- struct listnode *node;
- u_int32_t router_id, router_id_old;
+ struct interface *ifp;
+ struct listnode *node;
+ u_int32_t router_id, router_id_old;
- router_id_old = eigrp->router_id;
+ router_id_old = eigrp->router_id;
- if (eigrp->router_id_static != 0)
- router_id = eigrp->router_id_static;
+ if (eigrp->router_id_static != 0)
+ router_id = eigrp->router_id_static;
- else if (eigrp->router_id != 0)
- router_id = eigrp->router_id;
+ else if (eigrp->router_id != 0)
+ router_id = eigrp->router_id;
- else
- router_id = router_id_zebra.s_addr;
+ else
+ router_id = router_id_zebra.s_addr;
- eigrp->router_id = router_id;
- if (router_id_old != router_id)
- {
- // if (IS_DEBUG_EIGRP_EVENT)
- // zlog_debug("Router-ID[NEW:%s]: Update", inet_ntoa(eigrp->router_id));
+ eigrp->router_id = router_id;
+ if (router_id_old != router_id) {
+ // if (IS_DEBUG_EIGRP_EVENT)
+ // zlog_debug("Router-ID[NEW:%s]: Update",
+ // inet_ntoa(eigrp->router_id));
- /* update eigrp_interface's */
- for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp))
- eigrp_if_update(ifp);
- }
+ /* update eigrp_interface's */
+ for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp))
+ eigrp_if_update(ifp);
+ }
}
-void
-eigrp_master_init ()
+void eigrp_master_init()
{
- struct timeval tv;
+ struct timeval tv;
- memset(&eigrp_master, 0, sizeof(struct eigrp_master));
+ memset(&eigrp_master, 0, sizeof(struct eigrp_master));
- eigrp_om = &eigrp_master;
- eigrp_om->eigrp = list_new();
+ eigrp_om = &eigrp_master;
+ eigrp_om->eigrp = list_new();
- monotime(&tv);
- eigrp_om->start_time = tv.tv_sec;
+ monotime(&tv);
+ eigrp_om->start_time = tv.tv_sec;
}
/* Allocate new eigrp structure. */
-static struct eigrp *
-eigrp_new (const char *AS)
+static struct eigrp *eigrp_new(const char *AS)
{
- struct eigrp *eigrp = XCALLOC(MTYPE_EIGRP_TOP, sizeof (struct eigrp));
- int eigrp_socket;
-
- /* init information relevant to peers */
- eigrp->vrid = 0;
- eigrp->AS = atoi(AS);
- eigrp->router_id = 0L;
- eigrp->router_id_static = 0L;
- eigrp->sequence_number = 1;
-
- /*Configure default K Values for EIGRP Process*/
- eigrp->k_values[0] = EIGRP_K1_DEFAULT;
- eigrp->k_values[1] = EIGRP_K2_DEFAULT;
- eigrp->k_values[2] = EIGRP_K3_DEFAULT;
- eigrp->k_values[3] = EIGRP_K4_DEFAULT;
- eigrp->k_values[4] = EIGRP_K5_DEFAULT;
- eigrp->k_values[5] = EIGRP_K6_DEFAULT;
-
- /* init internal data structures */
- eigrp->eiflist = list_new();
- eigrp->passive_interface_default = EIGRP_IF_ACTIVE;
- eigrp->networks = route_table_init();
-
- if ((eigrp_socket = eigrp_sock_init()) < 0)
- {
- zlog_err("eigrp_new: fatal error: eigrp_sock_init was unable to open "
- "a socket");
- exit (1);
- }
-
- eigrp->fd = eigrp_socket;
- eigrp->maxsndbuflen = getsockopt_so_sendbuf(eigrp->fd);
-
- if ((eigrp->ibuf = stream_new(EIGRP_PACKET_MAX_LEN+1)) == NULL)
- {
- zlog_err("eigrp_new: fatal error: stream_new (%u) failed allocating ibuf",
- EIGRP_PACKET_MAX_LEN+1);
- exit(1);
- }
-
- eigrp->t_read = NULL;
- thread_add_read(master, eigrp_read, eigrp, eigrp->fd, &eigrp->t_read);
- eigrp->oi_write_q = list_new();
-
- eigrp->topology_table = eigrp_topology_new();
-
- eigrp->neighbor_self = eigrp_nbr_new(NULL);
- eigrp->neighbor_self->src.s_addr = INADDR_ANY;
-
- eigrp->variance = EIGRP_VARIANCE_DEFAULT;
- eigrp->max_paths = EIGRP_MAX_PATHS_DEFAULT;
-
- eigrp->serno = 0;
- eigrp->serno_last_update = 0;
- eigrp->topology_changes_externalIPV4 = list_new ();
- eigrp->topology_changes_internalIPV4 = list_new ();
-
- eigrp->list[EIGRP_FILTER_IN] = NULL;
- eigrp->list[EIGRP_FILTER_OUT] = NULL;
-
- eigrp->prefix[EIGRP_FILTER_IN] = NULL;
- eigrp->prefix[EIGRP_FILTER_OUT] = NULL;
-
- eigrp->routemap[EIGRP_FILTER_IN] = NULL;
- eigrp->routemap[EIGRP_FILTER_OUT] = NULL;
-
- QOBJ_REG(eigrp, eigrp);
- return eigrp;
+ struct eigrp *eigrp = XCALLOC(MTYPE_EIGRP_TOP, sizeof(struct eigrp));
+ int eigrp_socket;
+
+ /* init information relevant to peers */
+ eigrp->vrid = 0;
+ eigrp->AS = atoi(AS);
+ eigrp->router_id = 0L;
+ eigrp->router_id_static = 0L;
+ eigrp->sequence_number = 1;
+
+ /*Configure default K Values for EIGRP Process*/
+ eigrp->k_values[0] = EIGRP_K1_DEFAULT;
+ eigrp->k_values[1] = EIGRP_K2_DEFAULT;
+ eigrp->k_values[2] = EIGRP_K3_DEFAULT;
+ eigrp->k_values[3] = EIGRP_K4_DEFAULT;
+ eigrp->k_values[4] = EIGRP_K5_DEFAULT;
+ eigrp->k_values[5] = EIGRP_K6_DEFAULT;
+
+ /* init internal data structures */
+ eigrp->eiflist = list_new();
+ eigrp->passive_interface_default = EIGRP_IF_ACTIVE;
+ eigrp->networks = route_table_init();
+
+ if ((eigrp_socket = eigrp_sock_init()) < 0) {
+ zlog_err(
+ "eigrp_new: fatal error: eigrp_sock_init was unable to open "
+ "a socket");
+ exit(1);
+ }
+
+ eigrp->fd = eigrp_socket;
+ eigrp->maxsndbuflen = getsockopt_so_sendbuf(eigrp->fd);
+
+ if ((eigrp->ibuf = stream_new(EIGRP_PACKET_MAX_LEN + 1)) == NULL) {
+ zlog_err(
+ "eigrp_new: fatal error: stream_new (%u) failed allocating ibuf",
+ EIGRP_PACKET_MAX_LEN + 1);
+ exit(1);
+ }
+
+ eigrp->t_read = NULL;
+ thread_add_read(master, eigrp_read, eigrp, eigrp->fd, &eigrp->t_read);
+ eigrp->oi_write_q = list_new();
+
+ eigrp->topology_table = eigrp_topology_new();
+
+ eigrp->neighbor_self = eigrp_nbr_new(NULL);
+ eigrp->neighbor_self->src.s_addr = INADDR_ANY;
+
+ eigrp->variance = EIGRP_VARIANCE_DEFAULT;
+ eigrp->max_paths = EIGRP_MAX_PATHS_DEFAULT;
+
+ eigrp->serno = 0;
+ eigrp->serno_last_update = 0;
+ eigrp->topology_changes_externalIPV4 = list_new();
+ eigrp->topology_changes_internalIPV4 = list_new();
+
+ eigrp->list[EIGRP_FILTER_IN] = NULL;
+ eigrp->list[EIGRP_FILTER_OUT] = NULL;
+
+ eigrp->prefix[EIGRP_FILTER_IN] = NULL;
+ eigrp->prefix[EIGRP_FILTER_OUT] = NULL;
+
+ eigrp->routemap[EIGRP_FILTER_IN] = NULL;
+ eigrp->routemap[EIGRP_FILTER_OUT] = NULL;
+
+ QOBJ_REG(eigrp, eigrp);
+ return eigrp;
}
-static void
-eigrp_add (struct eigrp *eigrp)
+static void eigrp_add(struct eigrp *eigrp)
{
- listnode_add(eigrp_om->eigrp, eigrp);
+ listnode_add(eigrp_om->eigrp, eigrp);
}
-static void
-eigrp_delete (struct eigrp *eigrp)
+static void eigrp_delete(struct eigrp *eigrp)
{
- listnode_delete(eigrp_om->eigrp, eigrp);
+ listnode_delete(eigrp_om->eigrp, eigrp);
}
-struct eigrp *
-eigrp_get (const char *AS)
+struct eigrp *eigrp_get(const char *AS)
{
- struct eigrp *eigrp;
+ struct eigrp *eigrp;
- eigrp = eigrp_lookup();
- if (eigrp == NULL)
- {
- eigrp = eigrp_new(AS);
- eigrp_add(eigrp);
- }
+ eigrp = eigrp_lookup();
+ if (eigrp == NULL) {
+ eigrp = eigrp_new(AS);
+ eigrp_add(eigrp);
+ }
- return eigrp;
+ return eigrp;
}
/* Shut down the entire process */
-void
-eigrp_terminate (void)
+void eigrp_terminate(void)
{
- struct eigrp *eigrp;
- struct listnode *node, *nnode;
+ struct eigrp *eigrp;
+ struct listnode *node, *nnode;
- /* shutdown already in progress */
- if (CHECK_FLAG(eigrp_om->options, EIGRP_MASTER_SHUTDOWN))
- return;
+ /* shutdown already in progress */
+ if (CHECK_FLAG(eigrp_om->options, EIGRP_MASTER_SHUTDOWN))
+ return;
- SET_FLAG(eigrp_om->options, EIGRP_MASTER_SHUTDOWN);
+ SET_FLAG(eigrp_om->options, EIGRP_MASTER_SHUTDOWN);
- /* exit immediately if EIGRP not actually running */
- if (listcount(eigrp_om->eigrp) == 0)
- exit(0);
+ /* exit immediately if EIGRP not actually running */
+ if (listcount(eigrp_om->eigrp) == 0)
+ exit(0);
- for (ALL_LIST_ELEMENTS(eigrp_om->eigrp, node, nnode, eigrp))
- eigrp_finish(eigrp);
+ for (ALL_LIST_ELEMENTS(eigrp_om->eigrp, node, nnode, eigrp))
+ eigrp_finish(eigrp);
}
-void
-eigrp_finish (struct eigrp *eigrp)
+void eigrp_finish(struct eigrp *eigrp)
{
- eigrp_finish_final(eigrp);
-
- /* eigrp being shut-down? If so, was this the last eigrp instance? */
- if (CHECK_FLAG(eigrp_om->options, EIGRP_MASTER_SHUTDOWN)
- && (listcount(eigrp_om->eigrp) == 0))
- {
- if (zclient)
- {
- zclient_stop (zclient);
- zclient_free (zclient);
+ eigrp_finish_final(eigrp);
+
+ /* eigrp being shut-down? If so, was this the last eigrp instance? */
+ if (CHECK_FLAG(eigrp_om->options, EIGRP_MASTER_SHUTDOWN)
+ && (listcount(eigrp_om->eigrp) == 0)) {
+ if (zclient) {
+ zclient_stop(zclient);
+ zclient_free(zclient);
+ }
+ exit(0);
}
- exit(0);
- }
- return;
+ return;
}
/* Final cleanup of eigrp instance */
-void
-eigrp_finish_final (struct eigrp *eigrp)
+void eigrp_finish_final(struct eigrp *eigrp)
{
- struct eigrp_interface *ei;
- struct eigrp_neighbor *nbr;
- struct listnode *node, *nnode, *node2, *nnode2;
-
- for (ALL_LIST_ELEMENTS (eigrp->eiflist, node, nnode, ei))
- {
- for (ALL_LIST_ELEMENTS (ei->nbrs, node2, nnode2, nbr))
- eigrp_nbr_delete (nbr);
- eigrp_if_free (ei, INTERFACE_DOWN_BY_FINAL);
- }
+ struct eigrp_interface *ei;
+ struct eigrp_neighbor *nbr;
+ struct listnode *node, *nnode, *node2, *nnode2;
+
+ for (ALL_LIST_ELEMENTS(eigrp->eiflist, node, nnode, ei)) {
+ for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr))
+ eigrp_nbr_delete(nbr);
+ eigrp_if_free(ei, INTERFACE_DOWN_BY_FINAL);
+ }
- THREAD_OFF (eigrp->t_write);
- THREAD_OFF (eigrp->t_read);
- close (eigrp->fd);
+ THREAD_OFF(eigrp->t_write);
+ THREAD_OFF(eigrp->t_read);
+ close(eigrp->fd);
- list_delete(eigrp->eiflist);
- list_delete(eigrp->oi_write_q);
- list_delete(eigrp->topology_changes_externalIPV4);
- list_delete(eigrp->topology_changes_internalIPV4);
+ list_delete(eigrp->eiflist);
+ list_delete(eigrp->oi_write_q);
+ list_delete(eigrp->topology_changes_externalIPV4);
+ list_delete(eigrp->topology_changes_internalIPV4);
- eigrp_topology_cleanup(eigrp->topology_table);
- eigrp_topology_free(eigrp->topology_table);
+ eigrp_topology_cleanup(eigrp->topology_table);
+ eigrp_topology_free(eigrp->topology_table);
- eigrp_nbr_delete(eigrp->neighbor_self);
+ eigrp_nbr_delete(eigrp->neighbor_self);
- eigrp_delete(eigrp);
+ eigrp_delete(eigrp);
- XFREE(MTYPE_EIGRP_TOP,eigrp);
+ XFREE(MTYPE_EIGRP_TOP, eigrp);
}
/*Look for existing eigrp process*/
-struct eigrp *
-eigrp_lookup (void)
+struct eigrp *eigrp_lookup(void)
{
- if (listcount(eigrp_om->eigrp) == 0)
- return NULL;
+ if (listcount(eigrp_om->eigrp) == 0)
+ return NULL;
- return listgetdata(listhead(eigrp_om->eigrp));
+ return listgetdata(listhead(eigrp_om->eigrp));
}