From 8efe88eacfcbffcefd274238105b932dff76803a Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Thu, 9 Mar 2017 19:00:19 +0100 Subject: [PATCH] *: track version & "defaults" in configs [CF]: Move default name to autoconf and update tests Signed-off-by: Christian Franke --- Makefile.am | 2 + bgpd/bgpd.c | 36 ++++++-- bgpd/bgpd.h | 8 +- configure.ac | 6 ++ defaults.h | 54 +++++++++++ lib/command.c | 91 +++++++++++-------- lib/version.h.in | 1 + ospf6d/ospf6_top.c | 7 +- ospfd/ospf_vty.c | 5 +- ospfd/ospfd.c | 3 + tests/lib/cli/.gitignore | 1 + .../{test_cli.refout => test_cli.refout.in} | 6 ++ vtysh/vtysh_config.c | 1 + 13 files changed, 170 insertions(+), 51 deletions(-) create mode 100644 defaults.h create mode 100644 tests/lib/cli/.gitignore rename tests/lib/cli/{test_cli.refout => test_cli.refout.in} (93%) diff --git a/Makefile.am b/Makefile.am index 63dedeac0..3e73bd0cd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 528073123..86133cd76 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -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], diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 510082fdc..f1e5d7b0a 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -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 diff --git a/configure.ac b/configure.ac index 6ff64d086..9fc3cb72f 100755 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/defaults.h b/defaults.h new file mode 100644 index 000000000..e43fb2aa1 --- /dev/null +++ b/defaults.h @@ -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 */ diff --git a/lib/command.c b/lib/command.c index c9b261cf2..919e27ada 100644 --- a/lib/command.c +++ b/lib/command.c @@ -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) { diff --git a/lib/version.h.in b/lib/version.h.in index adc827818..6c78bd054 100644 --- a/lib/version.h.in +++ b/lib/version.h.in @@ -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@" diff --git a/ospf6d/ospf6_top.c b/ospf6d/ospf6_top.c index 3d632b644..f2d14ef09 100644 --- a/ospf6d/ospf6_top.c +++ b/ospf6d/ospf6_top.c @@ -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); } diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 2c3aaa680..5faf2850d 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -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); } diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index b83093db3..53b81c624 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -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; } diff --git a/tests/lib/cli/.gitignore b/tests/lib/cli/.gitignore new file mode 100644 index 000000000..682e95faa --- /dev/null +++ b/tests/lib/cli/.gitignore @@ -0,0 +1 @@ +/test_cli.refout diff --git a/tests/lib/cli/test_cli.refout b/tests/lib/cli/test_cli.refout.in similarity index 93% rename from tests/lib/cli/test_cli.refout rename to tests/lib/cli/test_cli.refout.in index 7da549482..26f7f09a0 100644 --- a/tests/lib/cli/test_cli.refout +++ b/tests/lib/cli/test_cli.refout.in @@ -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 ! ! diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c index e60e9c091..94c4042dd 100644 --- a/vtysh/vtysh_config.c +++ b/vtysh/vtysh_config.c @@ -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 -- 2.39.5