*: track version & "defaults" in configs

[CF]: Move default name to autoconf and update tests

Signed-off-by: Christian Franke <chris@opensourcerouting.org>
This commit is contained in:
David Lamparter 2017-03-09 19:00:19 +01:00 committed by Christian Franke
parent c1ec5aaf7c
commit 8efe88eacf
13 changed files with 170 additions and 51 deletions

View file

@ -16,3 +16,5 @@ EXTRA_DIST = aclocal.m4 SERVICES REPORTING-BUGS \
tools/zebra.el tools/multiple-bgpd.sh
ACLOCAL_AMFLAGS = -I m4
noinst_HEADERS = defaults.h

View file

@ -2889,10 +2889,18 @@ bgp_create (as_t *as, const char *name, enum bgp_instance_type inst_type)
bgp->stalepath_time = BGP_DEFAULT_STALEPATH_TIME;
bgp->dynamic_neighbors_limit = BGP_DYNAMIC_NEIGHBORS_LIMIT_DEFAULT;
bgp->dynamic_neighbors_count = 0;
#if DFLT_BGP_IMPORT_CHECK
bgp_flag_set (bgp, BGP_FLAG_IMPORT_CHECK);
#endif
#if DFLT_BGP_SHOW_HOSTNAME
bgp_flag_set (bgp, BGP_FLAG_SHOW_HOSTNAME);
#endif
#if DFLT_BGP_LOG_NEIGHBOR_CHANGES
bgp_flag_set (bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES);
#endif
#if DFLT_BGP_DETERMINISTIC_MED
bgp_flag_set (bgp, BGP_FLAG_DETERMINISTIC_MED);
#endif
bgp->addpath_tx_id = BGP_ADDPATH_TX_ID_FOR_DEFAULT_ORIGINATE;
bgp->as = *as;
@ -7263,8 +7271,11 @@ bgp_config_write (struct vty *vty)
inet_ntoa (bgp->router_id_static), VTY_NEWLINE);
/* BGP log-neighbor-changes. */
if (!bgp_flag_check (bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES))
vty_out (vty, " no bgp log-neighbor-changes%s", VTY_NEWLINE);
if (!!bgp_flag_check (bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES)
!= DFLT_BGP_LOG_NEIGHBOR_CHANGES)
vty_out (vty, " %sbgp log-neighbor-changes%s",
bgp_flag_check (bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES) ? "" : "no ",
VTY_NEWLINE);
/* BGP configuration. */
if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED))
@ -7280,8 +7291,11 @@ bgp_config_write (struct vty *vty)
bgp->default_local_pref, VTY_NEWLINE);
/* BGP default show-hostname */
if (!bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME))
vty_out (vty, " no bgp default show-hostname%s", VTY_NEWLINE);
if (!!bgp_flag_check(bgp, BGP_FLAG_SHOW_HOSTNAME)
!= DFLT_BGP_SHOW_HOSTNAME)
vty_out (vty, " %sbgp default show-hostname%s",
bgp_flag_check (bgp, BGP_FLAG_SHOW_HOSTNAME) ? "" : "no ",
VTY_NEWLINE);
/* BGP default subgroup-pkt-queue-max. */
if (bgp->default_subgroup_pkt_queue_max != BGP_DEFAULT_SUBGROUP_PKT_QUEUE_MAX)
@ -7324,8 +7338,11 @@ bgp_config_write (struct vty *vty)
vty_out (vty, " bgp enforce-first-as%s", VTY_NEWLINE);
/* BGP deterministic-med. */
if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
vty_out (vty, " no bgp deterministic-med%s", VTY_NEWLINE);
if (!!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
!= DFLT_BGP_DETERMINISTIC_MED)
vty_out (vty, " %sbgp deterministic-med%s",
bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED) ? "" : "no ",
VTY_NEWLINE);
/* BGP update-delay. */
bgp_config_write_update_delay (vty, bgp);
@ -7397,8 +7414,11 @@ bgp_config_write (struct vty *vty)
}
/* BGP network import check. */
if (!bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
vty_out (vty, " no bgp network import-check%s", VTY_NEWLINE);
if (!!bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK)
!= DFLT_BGP_IMPORT_CHECK)
vty_out (vty, " %sbgp network import-check%s",
bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK) ? "" : "no ",
VTY_NEWLINE);
/* BGP flag dampening. */
if (CHECK_FLAG (bgp->af_flags[AFI_IP][SAFI_UNICAST],

View file

@ -29,6 +29,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#include "sockunion.h"
#include "routemap.h"
#include "linklist.h"
#include "defaults.h"
#include "bgp_memory.h"
#define BGP_MAX_HOSTNAME 64 /* Linux max, is larger than most other sys */
@ -1052,12 +1053,13 @@ struct bgp_nlri
#define BGP_EVENTS_MAX 15
/* BGP timers default value. */
/* note: the DFLT_ ones depend on compile-time "defaults" selection */
#define BGP_INIT_START_TIMER 1
#define BGP_DEFAULT_HOLDTIME 9
#define BGP_DEFAULT_KEEPALIVE 3
#define BGP_DEFAULT_HOLDTIME DFLT_BGP_HOLDTIME
#define BGP_DEFAULT_KEEPALIVE DFLT_BGP_KEEPALIVE
#define BGP_DEFAULT_EBGP_ROUTEADV 0
#define BGP_DEFAULT_IBGP_ROUTEADV 0
#define BGP_DEFAULT_CONNECT_RETRY 10
#define BGP_DEFAULT_CONNECT_RETRY DFLT_BGP_TIMERS_CONNECT
/* BGP default local preference. */
#define BGP_DEFAULT_LOCAL_PREF 100

View file

@ -346,7 +346,12 @@ AC_SUBST(MPLS_METHOD)
if test "${enable_cumulus}" = "yes" ; then
AC_DEFINE(HAVE_CUMULUS,,Compile Special Cumulus Code in)
DFLT_NAME="datacenter"
else
DFLT_NAME="traditional"
fi
AC_SUBST(DFLT_NAME)
AC_DEFINE_UNQUOTED(DFLT_NAME,["$DFLT_NAME"], Name of the configuration default set)
if test "${enable_shell_access}" = "yes"; then
AC_DEFINE(HAVE_SHELL_ACCESS,,Allow user to use ssh/telnet/bash)
@ -1599,6 +1604,7 @@ AC_CONFIG_FILES([Makefile lib/Makefile qpb/Makefile zebra/Makefile ripd/Makefile
snapcraft/Makefile
snapcraft/snapcraft.yaml
lib/version.h
tests/lib/cli/test_cli.refout
doc/defines.texi
doc/bgpd.8
doc/isisd.8

54
defaults.h Normal file
View file

@ -0,0 +1,54 @@
/*
* FRR switchable defaults.
* Copyright (C) 2017 David Lamparter for NetDEF, Inc.
*
* This file is part of FreeRangeRouting (FRR).
*
* FRR is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2, or (at your option) any later version.
*
* FRR is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along
* with FRR; see the file COPYING. If not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _FRR_DEFAULTS_H
#define _FRR_DEFAULTS_H
#include "config.h"
#ifdef HAVE_CUMULUS
#define DFLT_BGP_IMPORT_CHECK 1
#define DFLT_BGP_TIMERS_CONNECT 10
#define DFLT_BGP_HOLDTIME 9
#define DFLT_BGP_KEEPALIVE 3
#define DFLT_BGP_LOG_NEIGHBOR_CHANGES 1
#define DFLT_BGP_SHOW_HOSTNAME 1
#define DFLT_BGP_DETERMINISTIC_MED 1
#define DFLT_OSPF_LOG_ADJACENCY_CHANGES 1
#define DFLT_OSPF6_LOG_ADJACENCY_CHANGES 1
#else /* !HAVE_CUMULUS */
#define DFLT_BGP_IMPORT_CHECK 0
#define DFLT_BGP_TIMERS_CONNECT 120
#define DFLT_BGP_HOLDTIME 180
#define DFLT_BGP_KEEPALIVE 60
#define DFLT_BGP_LOG_NEIGHBOR_CHANGES 0
#define DFLT_BGP_SHOW_HOSTNAME 0
#define DFLT_BGP_DETERMINISTIC_MED 0
#define DFLT_OSPF_LOG_ADJACENCY_CHANGES 0
#define DFLT_OSPF6_LOG_ADJACENCY_CHANGES 0
#endif /* !HAVE_CUMULUS */
#endif /* _FRR_DEFAULTS_H */

View file

@ -34,6 +34,7 @@ Boston, MA 02111-1307, USA. */
#include "workqueue.h"
#include "vrf.h"
#include "qobj.h"
#include "defaults.h"
DEFINE_MTYPE( LIB, HOST, "Host config")
DEFINE_MTYPE( LIB, STRVEC, "String vector")
@ -3082,6 +3083,23 @@ DEFUN (show_version,
return CMD_SUCCESS;
}
/* "Set" version ... ignore version tags */
DEFUN (frr_version_defaults,
frr_version_defaults_cmd,
"frr (version|defaults) .LINE",
"FreeRangeRouting global parameters\n"
"version configuration was written by\n"
"set of configuration defaults used\n"
"version string\n")
{
if (vty->type == VTY_TERM || vty->type == VTY_SHELL)
/* only print this when the user tries to do run it */
vty_out (vty, "%% NOTE: This command currently does nothing.%s"
"%% It is written to the configuration for future reference.%s",
VTY_NEWLINE, VTY_NEWLINE);
return CMD_SUCCESS;
}
/* Help display function for all node. */
DEFUN (config_help,
config_help_cmd,
@ -3125,6 +3143,37 @@ DEFUN (config_list,
return CMD_SUCCESS;
}
static void
vty_write_config (struct vty *vty)
{
size_t i;
struct cmd_node *node;
if (vty->type == VTY_TERM)
{
vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
VTY_NEWLINE);
vty_out (vty, "!%s", VTY_NEWLINE);
}
vty_out (vty, "frr version %s%s", FRR_VER_SHORT, VTY_NEWLINE);
vty_out (vty, "frr defaults %s%s", DFLT_NAME, VTY_NEWLINE);
vty_out (vty, "!%s", VTY_NEWLINE);
for (i = 0; i < vector_active (cmdvec); i++)
if ((node = vector_slot (cmdvec, i)) && node->func
&& (node->vtysh || vty->type != VTY_SHELL))
{
if ((*node->func) (vty))
vty_out (vty, "!%s", VTY_NEWLINE);
}
if (vty->type == VTY_TERM)
{
vty_out (vty, "end%s",VTY_NEWLINE);
}
}
/* Write current configuration into file. */
DEFUN (config_write_file,
config_write_file_cmd,
@ -3132,9 +3181,7 @@ DEFUN (config_write_file,
"Write running configuration to memory, network, or terminal\n"
"Write to configuration file\n")
{
unsigned int i;
int fd, dirfd;
struct cmd_node *node;
char *config_file, *slash;
char *config_file_tmp = NULL;
char *config_file_sav = NULL;
@ -3205,13 +3252,7 @@ DEFUN (config_write_file,
vty_out (file_vty, "!\n! Zebra configuration saved from vty\n! ");
vty_time_print (file_vty, 1);
vty_out (file_vty, "!\n");
for (i = 0; i < vector_active (cmdvec); i++)
if ((node = vector_slot (cmdvec, i)) && node->func)
{
if ((*node->func) (file_vty))
vty_out (file_vty, "!\n");
}
vty_write_config (file_vty);
vty_close (file_vty);
if (stat(config_file, &conf_stat) >= 0)
@ -3277,35 +3318,8 @@ DEFUN (config_write_terminal,
"Write running configuration to memory, network, or terminal\n"
"Write to terminal\n")
{
unsigned int i;
struct cmd_node *node;
if (host.noconfig)
return CMD_SUCCESS;
if (vty->type == VTY_SHELL_SERV)
{
for (i = 0; i < vector_active (cmdvec); i++)
if ((node = vector_slot (cmdvec, i)) && node->func && node->vtysh)
{
if ((*node->func) (vty))
vty_out (vty, "!%s", VTY_NEWLINE);
}
}
else
{
vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
VTY_NEWLINE);
vty_out (vty, "!%s", VTY_NEWLINE);
for (i = 0; i < vector_active (cmdvec); i++)
if ((node = vector_slot (cmdvec, i)) && node->func)
{
if ((*node->func) (vty))
vty_out (vty, "!%s", VTY_NEWLINE);
}
vty_out (vty, "end%s",VTY_NEWLINE);
}
if (!host.noconfig)
vty_write_config (vty);
return CMD_SUCCESS;
}
@ -4301,6 +4315,7 @@ cmd_init (int terminal)
install_element (CONFIG_NODE, &hostname_cmd);
install_element (CONFIG_NODE, &no_hostname_cmd);
install_element (CONFIG_NODE, &frr_version_defaults_cmd);
if (terminal > 0)
{

View file

@ -41,6 +41,7 @@
#define FRR_FULL_NAME "FreeRangeRouting"
#define FRR_VERSION "@PACKAGE_VERSION@" GIT_SUFFIX
#define FRR_VER_SHORT "@PACKAGE_VERSION@"
#define FRR_BUG_ADDRESS "@PACKAGE_BUGREPORT@"
#define FRR_COPYRIGHT "Copyright 1996-2005 Kunihiro Ishiguro, et al."
#define FRR_CONFIG_ARGS "@CONFIG_ARGS@"

View file

@ -29,6 +29,7 @@
#include "table.h"
#include "thread.h"
#include "command.h"
#include "defaults.h"
#include "ospf6_proto.h"
#include "ospf6_message.h"
@ -158,7 +159,9 @@ ospf6_create (void)
o->distance_table = route_table_init ();
/* Enable "log-adjacency-changes" */
#if DFLT_OSPF6_LOG_ADJACENCY_CHANGES
SET_FLAG(o->config_flags, OSPF6_LOG_ADJACENCY_CHANGES);
#endif
return o;
}
@ -1132,8 +1135,10 @@ config_write_ospf6 (struct vty *vty)
{
if (CHECK_FLAG(ospf6->config_flags, OSPF6_LOG_ADJACENCY_DETAIL))
vty_out(vty, " log-adjacency-changes detail%s", VTY_NEWLINE);
else if (!DFLT_OSPF6_LOG_ADJACENCY_CHANGES)
vty_out(vty, " log-adjacency-changes%s", VTY_NEWLINE);
}
else
else if (DFLT_OSPF6_LOG_ADJACENCY_CHANGES)
{
vty_out(vty, " no log-adjacency-changes%s", VTY_NEWLINE);
}

View file

@ -33,6 +33,7 @@
#include "plist.h"
#include "log.h"
#include "zclient.h"
#include "defaults.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_asbr.h"
@ -9873,8 +9874,10 @@ ospf_config_write (struct vty *vty)
{
if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
vty_out(vty, " log-adjacency-changes detail%s", VTY_NEWLINE);
else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES)
vty_out(vty, " log-adjacency-changes%s", VTY_NEWLINE);
}
else
else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES)
{
vty_out(vty, " no log-adjacency-changes%s", VTY_NEWLINE);
}

View file

@ -35,6 +35,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#include "plist.h"
#include "sockopt.h"
#include "bfd.h"
#include "defaults.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_network.h"
@ -291,7 +292,9 @@ ospf_new (u_short instance)
new->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT;
/* Enable "log-adjacency-changes" */
#if DFLT_OSPF_LOG_ADJACENCY_CHANGES
SET_FLAG(new->config, OSPF_LOG_ADJACENCY_CHANGES);
#endif
return new;
}

1
tests/lib/cli/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/test_cli.refout

View file

@ -270,6 +270,9 @@ test# show run
Current configuration:
!
frr version @PACKAGE_VERSION@
frr defaults @DFLT_NAME@
!
hostname test
!
!
@ -282,6 +285,9 @@ foohost(config)# do show run
Current configuration:
!
frr version @PACKAGE_VERSION@
frr defaults @DFLT_NAME@
!
hostname foohost
!
!

View file

@ -274,6 +274,7 @@ vtysh_config_parse_line (const char *line)
{
if (strncmp (line, "log", strlen ("log")) == 0
|| strncmp (line, "hostname", strlen ("hostname")) == 0
|| strncmp (line, "frr", strlen ("frr")) == 0
)
config_add_line_uniq (config_top, line);
else