return 0;
}
-void router_id_get(struct prefix *p, vrf_id_t vrf_id)
+void router_id_get(struct prefix *p, struct zebra_vrf *zvrf)
{
struct listnode *node;
struct connected *c;
- struct zebra_vrf *zvrf = vrf_info_get(vrf_id);
p->u.prefix4.s_addr = INADDR_ANY;
p->family = AF_INET;
}
}
-static void router_id_set(struct prefix *p, vrf_id_t vrf_id)
+static void router_id_set(struct prefix *p, struct zebra_vrf *zvrf)
{
struct prefix p2;
struct listnode *node;
struct zserv *client;
- struct zebra_vrf *zvrf;
-
- if (p->u.prefix4.s_addr == 0) /* unset */
- {
- zvrf = vrf_info_lookup(vrf_id);
- if (!zvrf)
- return;
- } else /* set */
- zvrf = vrf_info_get(vrf_id);
zvrf->rid_user_assigned.u.prefix4.s_addr = p->u.prefix4.s_addr;
- router_id_get(&p2, vrf_id);
+ router_id_get(&p2, zvrf);
for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client))
- zsend_router_id_update(client, &p2, vrf_id);
+ zsend_router_id_update(client, &p2, zvrf->vrf->vrf_id);
}
void router_id_add_address(struct connected *ifc)
if (router_id_bad_address(ifc))
return;
- router_id_get(&before, zvrf_id(zvrf));
+ router_id_get(&before, zvrf);
if (if_is_loopback(ifc->ifp))
l = zvrf->rid_lo_sorted_list;
if (!router_id_find_node(l, ifc))
listnode_add_sort(l, ifc);
- router_id_get(&after, zvrf_id(zvrf));
+ router_id_get(&after, zvrf);
if (prefix_same(&before, &after))
return;
if (router_id_bad_address(ifc))
return;
- router_id_get(&before, zvrf_id(zvrf));
+ router_id_get(&before, zvrf);
if (if_is_loopback(ifc->ifp))
l = zvrf->rid_lo_sorted_list;
if ((c = router_id_find_node(l, ifc)))
listnode_delete(l, c);
- router_id_get(&after, zvrf_id(zvrf));
+ router_id_get(&after, zvrf);
if (prefix_same(&before, &after))
return;
zsend_router_id_update(client, &after, zvrf_id(zvrf));
}
-void router_id_write(struct vty *vty)
+void router_id_write(struct vty *vty, struct zebra_vrf *zvrf)
{
- struct vrf *vrf;
- struct zebra_vrf *zvrf;
+ char space[2];
+
+ memset(space, 0, sizeof(space));
+
+ if (zvrf_id(zvrf) != VRF_DEFAULT)
+ snprintf(space, sizeof(space), "%s", " ");
- RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
- if ((zvrf = vrf->info) != NULL)
- if (zvrf->rid_user_assigned.u.prefix4.s_addr
- != INADDR_ANY) {
- if (zvrf_id(zvrf) == VRF_DEFAULT)
- vty_out(vty, "router-id %s\n",
- inet_ntoa(
- zvrf->rid_user_assigned
- .u.prefix4));
- else
- vty_out(vty, "router-id %s vrf %s\n",
- inet_ntoa(
- zvrf->rid_user_assigned
- .u.prefix4),
- zvrf_name(zvrf));
- }
+ if (zvrf->rid_user_assigned.u.prefix4.s_addr != INADDR_ANY) {
+ vty_out(vty, "%srouter-id %s\n", space,
+ inet_ntoa(zvrf->rid_user_assigned.u.prefix4));
+ }
}
DEFUN (router_id,
router_id_cmd,
- "router-id A.B.C.D [vrf NAME]",
+ "router-id A.B.C.D vrf NAME",
"Manually set the router-id\n"
- "IP address to use for router-id\n"
- VRF_CMD_HELP_STR)
+ "IP address to use for router-id\n" VRF_CMD_HELP_STR)
{
int idx_ipv4 = 1;
int idx_name = 3;
+ struct zebra_vrf *zvrf;
struct prefix rid;
vrf_id_t vrf_id = VRF_DEFAULT;
if (argc > 2)
VRF_GET_ID(vrf_id, argv[idx_name]->arg, false);
- router_id_set(&rid, vrf_id);
+ zvrf = vrf_info_lookup(vrf_id);
+ router_id_set(&rid, zvrf);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (router_id_in_vrf,
+ router_id_in_vrf_cmd,
+ "router-id A.B.C.D",
+ "Manuall set the router-id\n"
+ "IP address to use for router-id\n")
+{
+ ZEBRA_DECLVAR_CONTEXT(vrf, zvrf);
+ int idx_ipv4 = 1;
+ struct prefix rid;
+
+ rid.u.prefix4.s_addr = inet_addr(argv[idx_ipv4]->arg);
+ if (!rid.u.prefix4.s_addr)
+ return CMD_WARNING_CONFIG_FAILED;
+
+ rid.prefixlen = 32;
+ rid.family = AF_INET;
+
+ router_id_set(&rid, zvrf);
return CMD_SUCCESS;
}
DEFUN (no_router_id,
no_router_id_cmd,
- "no router-id [A.B.C.D [vrf NAME]]",
+ "no router-id [A.B.C.D vrf NAME]",
NO_STR
"Remove the manually configured router-id\n"
- "IP address to use for router-id\n"
- VRF_CMD_HELP_STR)
+ "IP address to use for router-id\n" VRF_CMD_HELP_STR)
{
int idx_name = 4;
-
struct prefix rid;
vrf_id_t vrf_id = VRF_DEFAULT;
+ struct zebra_vrf *zvrf;
rid.u.prefix4.s_addr = 0;
rid.prefixlen = 0;
if (argc > 3)
VRF_GET_ID(vrf_id, argv[idx_name]->arg, false);
- router_id_set(&rid, vrf_id);
+ zvrf = vrf_info_get(vrf_id);
+ router_id_set(&rid, zvrf);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (no_router_id_in_vrf,
+ no_router_id_in_vrf_cmd,
+ "no router-id [A.B.C.D]",
+ NO_STR
+ "Remove the manually configured router-id\n"
+ "IP address to use for router-id\n")
+{
+ ZEBRA_DECLVAR_CONTEXT(vrf, zvrf);
+
+ struct prefix rid;
+
+ rid.u.prefix4.s_addr = 0;
+ rid.prefixlen = 0;
+ rid.family = AF_INET;
+
+ router_id_set(&rid, zvrf);
return CMD_SUCCESS;
}
{
install_element(CONFIG_NODE, &router_id_cmd);
install_element(CONFIG_NODE, &no_router_id_cmd);
+ install_element(CONFIG_NODE, &router_id_in_vrf_cmd);
+ install_element(VRF_NODE, &router_id_in_vrf_cmd);
+ install_element(CONFIG_NODE, &no_router_id_in_vrf_cmd);
+ install_element(VRF_NODE, &no_router_id_in_vrf_cmd);
install_element(VIEW_NODE, &show_router_id_cmd);
}