]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bfdd: session specific command type checks
authorRafael Zalamena <rzalamena@opensourcerouting.org>
Tue, 1 Dec 2020 11:01:37 +0000 (08:01 -0300)
committerIgor Ryzhov <iryzhov@nfware.com>
Wed, 24 Mar 2021 12:15:22 +0000 (15:15 +0300)
Replace the unclear error message:

```
% Failed to edit configuration.

YANG error(s):
 Schema node not found.
 YANG path: /frr-bfdd:bfdd/bfd/sessions/single-hop[dest-addr='192.168.253.6'][interface=''][vrf='default']/minimum-ttl
```

With:

```
frr(config-bfd-peer)# minimum-ttl 250
% Minimum TTL is only available for multi hop sessions.

! or

frr(config-bfd-peer)# echo
% Echo mode is only available for single hop sessions.
frr(config-bfd-peer)# echo-interval 300
% Echo mode is only available for single hop sessions.
```

Reported-by: Trae Santiago
Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
bfdd/bfdd_cli.c

index f6ba8fce94ad510697361d8891e7c77c5a9295a6..470e3e2f058a4bd50cc6e52f5db2f9de7b4c3f3c 100644 (file)
 /*
  * Prototypes.
  */
+static bool
+bfd_cli_is_single_hop(struct vty *vty)
+{
+       return strstr(VTY_CURR_XPATH, "/single-hop") != NULL;
+}
 
 /*
  * Functions.
@@ -297,6 +302,11 @@ DEFPY_YANG(
        "Expect packets with at least this TTL\n"
        "Minimum TTL expected\n")
 {
+       if (bfd_cli_is_single_hop(vty)) {
+               vty_out(vty, "%% Minimum TTL is only available for multi hop sessions.\n");
+               return CMD_WARNING_CONFIG_FAILED;
+       }
+
        if (no)
                nb_cli_enqueue_change(vty, "./minimum-ttl", NB_OP_DESTROY,
                                      NULL);
@@ -412,6 +422,11 @@ DEFPY_YANG(
        NO_STR
        "Configure echo mode\n")
 {
+       if (!bfd_cli_is_single_hop(vty)) {
+               vty_out(vty, "%% Echo mode is only available for single hop sessions.\n");
+               return CMD_WARNING_CONFIG_FAILED;
+       }
+
        nb_cli_enqueue_change(vty, "./echo-mode", NB_OP_MODIFY,
                              no ? "false" : "true");
        return nb_cli_apply_changes(vty, NULL);
@@ -435,6 +450,11 @@ DEFPY_YANG(
 {
        char value[32];
 
+       if (!bfd_cli_is_single_hop(vty)) {
+               vty_out(vty, "%% Echo mode is only available for single hop sessions.\n");
+               return CMD_WARNING_CONFIG_FAILED;
+       }
+
        snprintf(value, sizeof(value), "%ld", interval * 1000);
        nb_cli_enqueue_change(vty, "./desired-echo-transmission-interval",
                              NB_OP_MODIFY, value);