#include "rib.h"
#include "zebra/zserv.h"
+#include "zebra/router-id.h"
+#include "zebra/redistribute.h"
-static struct list rid_all_sorted_list;
-static struct list rid_lo_sorted_list;
+static struct list _rid_all_sorted_list;
+static struct list _rid_lo_sorted_list;
+static struct list *rid_all_sorted_list = &_rid_all_sorted_list;
+static struct list *rid_lo_sorted_list = &_rid_lo_sorted_list;
static struct prefix rid_user_assigned;
/* master zebra server structure */
static int
router_id_bad_address (struct connected *ifc)
{
- struct prefix n;
-
if (ifc->address->family != AF_INET)
return 1;
-
- n.u.prefix4.s_addr = htonl (INADDR_LOOPBACK);
- n.prefixlen = 8;
- n.family = AF_INET;
-
- if (prefix_match (&n, ifc->address))
+
+ /* non-redistributable addresses shouldn't be used for RIDs either */
+ if (!zebra_check_addr (ifc->address))
return 1;
-
+
return 0;
}
if (rid_user_assigned.u.prefix4.s_addr)
p->u.prefix4.s_addr = rid_user_assigned.u.prefix4.s_addr;
- else if (!list_isempty (&rid_lo_sorted_list))
+ else if (!list_isempty (rid_lo_sorted_list))
{
- node = listtail (&rid_lo_sorted_list);
+ node = listtail (rid_lo_sorted_list);
c = listgetdata (node);
p->u.prefix4.s_addr = c->address->u.prefix4.s_addr;
}
- else if (!list_isempty (&rid_all_sorted_list))
+ else if (!list_isempty (rid_all_sorted_list))
{
- node = listtail (&rid_all_sorted_list);
+ node = listtail (rid_all_sorted_list);
c = listgetdata (node);
p->u.prefix4.s_addr = c->address->u.prefix4.s_addr;
}
if (!strncmp (ifc->ifp->name, "lo", 2)
|| !strncmp (ifc->ifp->name, "dummy", 5))
- l = &rid_lo_sorted_list;
+ l = rid_lo_sorted_list;
else
- l = &rid_all_sorted_list;
+ l = rid_all_sorted_list;
if (!router_id_find_node (l, ifc))
- listnode_add (l, ifc);
+ listnode_add_sort (l, ifc);
router_id_get (&after);
if (!strncmp (ifc->ifp->name, "lo", 2)
|| !strncmp (ifc->ifp->name, "dummy", 5))
- l = &rid_lo_sorted_list;
+ l = rid_lo_sorted_list;
else
- l = &rid_all_sorted_list;
+ l = rid_all_sorted_list;
if ((c = router_id_find_node (l, ifc)))
listnode_delete (l, c);
return CMD_SUCCESS;
}
-int
+static int
router_id_cmp (void *a, void *b)
{
- unsigned int A, B;
-
- A = ((struct connected *) a)->address->u.prefix4.s_addr;
- B = ((struct connected *) b)->address->u.prefix4.s_addr;
+ const struct connected *ifa = (const struct connected *)a;
+ const struct connected *ifb = (const struct connected *)b;
- if (A > B)
- return 1;
- else if (A < B)
- return -1;
- return 0;
+ return IPV4_ADDR_CMP(&ifa->address->u.prefix4.s_addr,&ifb->address->u.prefix4.s_addr);
}
void
install_element (CONFIG_NODE, &router_id_cmd);
install_element (CONFIG_NODE, &no_router_id_cmd);
- memset (&rid_all_sorted_list, 0, sizeof (rid_all_sorted_list));
- memset (&rid_lo_sorted_list, 0, sizeof (rid_lo_sorted_list));
+ memset (rid_all_sorted_list, 0, sizeof (rid_all_sorted_list));
+ memset (rid_lo_sorted_list, 0, sizeof (rid_lo_sorted_list));
memset (&rid_user_assigned, 0, sizeof (rid_user_assigned));
- rid_all_sorted_list.cmp = router_id_cmp;
- rid_lo_sorted_list.cmp = router_id_cmp;
+ rid_all_sorted_list->cmp = router_id_cmp;
+ rid_lo_sorted_list->cmp = router_id_cmp;
rid_user_assigned.family = AF_INET;
rid_user_assigned.prefixlen = 32;