summaryrefslogtreecommitdiffstats
path: root/ospf6d/ospf6_asbr.c
diff options
context:
space:
mode:
authorYash Ranjan <ranjany@vmware.com>2021-02-10 05:53:46 +0100
committerYash Ranjan <ranjany@vmware.com>2021-03-29 15:37:10 +0200
commitb19502d3b0d53c8c50e8e47124beb760b41e286d (patch)
tree3d3646a466d67099055fe4e724726304e66076d5 /ospf6d/ospf6_asbr.c
parentMerge pull request #8285 from donaldsharp/rpki_find (diff)
downloadfrr-b19502d3b0d53c8c50e8e47124beb760b41e286d.tar.xz
frr-b19502d3b0d53c8c50e8e47124beb760b41e286d.zip
ospf6d: Add CLI and logic for default-information originate command
Signed-off-by: Yash Ranjan <ranjany@vmware.com>
Diffstat (limited to 'ospf6d/ospf6_asbr.c')
-rw-r--r--ospf6d/ospf6_asbr.c177
1 files changed, 176 insertions, 1 deletions
diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c
index 3497b2665..62ce74718 100644
--- a/ospf6d/ospf6_asbr.c
+++ b/ospf6d/ospf6_asbr.c
@@ -57,6 +57,10 @@ static void ospf6_asbr_redistribute_set(int type, vrf_id_t vrf_id);
static void ospf6_asbr_redistribute_unset(struct ospf6 *ospf6,
struct ospf6_redist *red, int type);
+#ifndef VTYSH_EXTRACT_PL
+#include "ospf6d/ospf6_asbr_clippy.c"
+#endif
+
unsigned char conf_debug_ospf6_asbr = 0;
#define ZROUTE_NAME(x) zebra_route_string(x)
@@ -1150,7 +1154,8 @@ void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex,
if (!red)
return;
- if (!ospf6_zebra_is_redistribute(type, ospf6->vrf_id))
+ if ((type != DEFAULT_ROUTE)
+ && !ospf6_zebra_is_redistribute(type, ospf6->vrf_id))
return;
memset(&troute, 0, sizeof(troute));
@@ -1533,6 +1538,140 @@ static void ospf6_redistribute_show_config(struct vty *vty, struct ospf6 *ospf6,
vty_out(vty, "Total %d routes\n", total);
}
+static void ospf6_redistribute_default_set(struct ospf6 *ospf6, int originate)
+{
+ struct prefix_ipv6 p = {};
+ struct in6_addr nexthop = {};
+ int cur_originate = ospf6->default_originate;
+
+ p.family = AF_INET6;
+ p.prefixlen = 0;
+
+ ospf6->default_originate = originate;
+
+ switch (cur_originate) {
+ case DEFAULT_ORIGINATE_NONE:
+ break;
+ case DEFAULT_ORIGINATE_ZEBRA:
+ zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_DELETE,
+ zclient, AFI_IP6, ospf6->vrf_id);
+ ospf6_asbr_redistribute_remove(DEFAULT_ROUTE, 0,
+ (struct prefix *)&p, ospf6);
+
+ break;
+ case DEFAULT_ORIGINATE_ALWAYS:
+ ospf6_asbr_redistribute_remove(DEFAULT_ROUTE, 0,
+ (struct prefix *)&p, ospf6);
+ break;
+ }
+
+ switch (originate) {
+ case DEFAULT_ORIGINATE_NONE:
+ break;
+ case DEFAULT_ORIGINATE_ZEBRA:
+ zclient_redistribute_default(ZEBRA_REDISTRIBUTE_DEFAULT_ADD,
+ zclient, AFI_IP6, ospf6->vrf_id);
+
+ break;
+ case DEFAULT_ORIGINATE_ALWAYS:
+ ospf6_asbr_redistribute_add(DEFAULT_ROUTE, 0,
+ (struct prefix *)&p, 0, &nexthop, 0,
+ ospf6);
+ break;
+ }
+}
+
+/* Default Route originate. */
+DEFPY (ospf6_default_route_originate,
+ ospf6_default_route_originate_cmd,
+ "default-information originate [{always$always|metric (0-16777214)$mval|metric-type (1-2)$mtype|route-map WORD$rtmap}]",
+ "Control distribution of default route\n"
+ "Distribute a default route\n"
+ "Always advertise default route\n"
+ "OSPFv3 default metric\n"
+ "OSPFv3 metric\n"
+ "OSPFv3 metric type for default routes\n"
+ "Set OSPFv3 External Type 1/2 metrics\n"
+ "Route map reference\n"
+ "Pointer to route-map entries\n")
+{
+ int default_originate = DEFAULT_ORIGINATE_ZEBRA;
+ struct ospf6_redist *red;
+ bool sameRtmap = false;
+
+ VTY_DECLVAR_CONTEXT(ospf6, ospf6);
+
+ int cur_originate = ospf6->default_originate;
+
+ OSPF6_CMD_CHECK_RUNNING(ospf6);
+
+ red = ospf6_redist_add(ospf6, DEFAULT_ROUTE, 0);
+
+ if (always != NULL)
+ default_originate = DEFAULT_ORIGINATE_ALWAYS;
+
+ if (mval_str == NULL)
+ mval = -1;
+
+ if (mtype_str == NULL)
+ mtype = -1;
+
+ /* To check ,if user is providing same route map */
+ if ((rtmap == ROUTEMAP_NAME(red))
+ || (rtmap && ROUTEMAP_NAME(red)
+ && (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0)))
+ sameRtmap = true;
+
+ /* Don't allow if the same lsa is aleardy originated. */
+ if ((sameRtmap) && (red->dmetric.type == mtype)
+ && (red->dmetric.value == mval)
+ && (cur_originate == default_originate))
+ return CMD_SUCCESS;
+
+ /* Updating Metric details */
+ red->dmetric.type = mtype;
+ red->dmetric.value = mval;
+
+ /* updating route map details */
+ if (rtmap)
+ ospf6_asbr_routemap_set(red, rtmap);
+ else
+ ospf6_asbr_routemap_unset(red);
+
+ ospf6_redistribute_default_set(ospf6, default_originate);
+ return CMD_SUCCESS;
+}
+
+DEFPY (no_ospf6_default_information_originate,
+ no_ospf6_default_information_originate_cmd,
+ "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
+ NO_STR
+ "Control distribution of default information\n"
+ "Distribute a default route\n"
+ "Always advertise default route\n"
+ "OSPFv3 default metric\n"
+ "OSPFv3 metric\n"
+ "OSPFv3 metric type for default routes\n"
+ "Set OSPFv3 External Type 1/2 metrics\n"
+ "Route map reference\n"
+ "Pointer to route-map entries\n")
+{
+ struct ospf6_redist *red;
+
+ VTY_DECLVAR_CONTEXT(ospf6, ospf6);
+
+ OSPF6_CMD_CHECK_RUNNING(ospf6);
+
+ red = ospf6_redist_lookup(ospf6, DEFAULT_ROUTE, 0);
+ if (!red)
+ return CMD_SUCCESS;
+
+ ospf6_asbr_routemap_unset(red);
+ ospf6_redist_del(ospf6, red, DEFAULT_ROUTE);
+
+ ospf6_redistribute_default_set(ospf6, DEFAULT_ORIGINATE_NONE);
+ return CMD_SUCCESS;
+}
/* Routemap Functions */
static enum route_map_cmd_result_t
@@ -2115,6 +2254,9 @@ void ospf6_asbr_init(void)
install_element(VIEW_NODE, &show_ipv6_ospf6_redistribute_cmd);
+ install_element(OSPF6_NODE, &ospf6_default_route_originate_cmd);
+ install_element(OSPF6_NODE,
+ &no_ospf6_default_information_originate_cmd);
install_element(OSPF6_NODE, &ospf6_redistribute_cmd);
install_element(OSPF6_NODE, &ospf6_redistribute_routemap_cmd);
install_element(OSPF6_NODE, &no_ospf6_redistribute_cmd);
@@ -2176,6 +2318,39 @@ int config_write_ospf6_debug_asbr(struct vty *vty)
return 0;
}
+int ospf6_distribute_config_write(struct vty *vty, struct ospf6 *ospf6)
+{
+ struct ospf6_redist *red;
+
+ if (ospf6) {
+ /* default-route print. */
+ if (ospf6->default_originate != DEFAULT_ORIGINATE_NONE) {
+ vty_out(vty, " default-information originate");
+ if (ospf6->default_originate
+ == DEFAULT_ORIGINATE_ALWAYS)
+ vty_out(vty, " always");
+
+ red = ospf6_redist_lookup(ospf6, DEFAULT_ROUTE, 0);
+ if (red) {
+ if (red->dmetric.value >= 0)
+ vty_out(vty, " metric %d",
+ red->dmetric.value);
+
+ if (red->dmetric.type >= 0)
+ vty_out(vty, " metric-type %d",
+ red->dmetric.type);
+
+ if (ROUTEMAP_NAME(red))
+ vty_out(vty, " route-map %s",
+ ROUTEMAP_NAME(red));
+ }
+
+ vty_out(vty, "\n");
+ }
+ }
+ return 0;
+}
+
void install_element_ospf6_debug_asbr(void)
{
install_element(ENABLE_NODE, &debug_ospf6_asbr_cmd);