From a0fbad586911f227d8d3c6beff46e36b901a8196 Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Wed, 7 Jul 2021 10:20:01 -0300 Subject: [PATCH] ospf6d: rework default-information configuration Move code to its own function and remove most of the code indentation (e.g. test for failure and quit as soon as possible). Signed-off-by: Rafael Zalamena --- ospf6d/ospf6_asbr.c | 55 ++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c index aad4e7571d..3e911a743a 100644 --- a/ospf6d/ospf6_asbr.c +++ b/ospf6d/ospf6_asbr.c @@ -2568,36 +2568,41 @@ int config_write_ospf6_debug_asbr(struct vty *vty) return 0; } -int ospf6_distribute_config_write(struct vty *vty, struct ospf6 *ospf6) +static void ospf6_default_originate_write(struct vty *vty, struct ospf6 *o) { 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, " default-information originate"); + if (o->default_originate == DEFAULT_ORIGINATE_ALWAYS) + vty_out(vty, " always"); - vty_out(vty, "\n"); - } + red = ospf6_redist_lookup(o, DEFAULT_ROUTE, 0); + if (red == NULL) { + vty_out(vty, "\n"); + return; } + + 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"); +} + +int ospf6_distribute_config_write(struct vty *vty, struct ospf6 *o) +{ + if (o == NULL) + return 0; + + /* Print default originate configuration. */ + if (o->default_originate != DEFAULT_ORIGINATE_NONE) + ospf6_default_originate_write(vty, o); + return 0; } -- 2.39.5