zebra: rewrite locator_prefix_cmd with DEFPY

Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
This commit is contained in:
Hiroki Shirokura 2020-12-29 07:30:47 +00:00 committed by Mark Stapp
parent 7de4c88525
commit daedb8b3cf
2 changed files with 11 additions and 19 deletions

View File

@ -131,6 +131,7 @@ clippy_scan += \
zebra/zebra_mlag_vty.c \ zebra/zebra_mlag_vty.c \
zebra/zebra_routemap.c \ zebra/zebra_routemap.c \
zebra/zebra_vty.c \ zebra/zebra_vty.c \
zebra/zebra_srv6_vty.c \
# end # end
noinst_HEADERS += \ noinst_HEADERS += \

View File

@ -40,6 +40,10 @@
#include "zebra/zebra_routemap.h" #include "zebra/zebra_routemap.h"
#include "zebra/zebra_dplane.h" #include "zebra/zebra_dplane.h"
#ifndef VTYSH_EXTRACT_PL
#include "zebra/zebra_srv6_vty_clippy.c"
#endif
static int zebra_sr_config(struct vty *vty); static int zebra_sr_config(struct vty *vty);
static struct cmd_node sr_node = { static struct cmd_node sr_node = {
@ -229,37 +233,24 @@ DEFUN_NOSH (srv6_locator,
return CMD_SUCCESS; return CMD_SUCCESS;
} }
DEFUN (locator_prefix, DEFPY (locator_prefix,
locator_prefix_cmd, locator_prefix_cmd,
"prefix X:X::X:X/M [func-bits (8-64)]", "prefix X:X::X:X/M$prefix [func-bits (16-64)$func_bit_len]",
"Configure SRv6 locator prefix\n" "Configure SRv6 locator prefix\n"
"Specify SRv6 locator prefix\n" "Specify SRv6 locator prefix\n"
"Configure SRv6 locator function length in bits\n" "Configure SRv6 locator function length in bits\n"
"Specify SRv6 locator function length in bits\n") "Specify SRv6 locator function length in bits\n")
{ {
VTY_DECLVAR_CONTEXT(srv6_locator, locator); VTY_DECLVAR_CONTEXT(srv6_locator, locator);
struct prefix_ipv6 prefix;
struct srv6_locator_chunk *chunk = NULL; struct srv6_locator_chunk *chunk = NULL;
struct listnode *node = NULL; struct listnode *node = NULL;
uint8_t function_bits_length = 16;
int ret;
ret = str2prefix_ipv6(argv[1]->arg, &prefix); locator->prefix = *prefix;
if (ret <= 0) { locator->function_bits_length = func_bit_len;
vty_out(vty, "%% Malformed address\n");
return CMD_WARNING_CONFIG_FAILED;
}
apply_mask_ipv6(&prefix);
if (argc >= 3)
function_bits_length = strtoul(argv[3]->arg, NULL, 10);
locator->prefix = prefix;
locator->function_bits_length = function_bits_length;
if (list_isempty(locator->chunks)) { if (list_isempty(locator->chunks)) {
chunk = srv6_locator_chunk_alloc(); chunk = srv6_locator_chunk_alloc();
chunk->prefix = prefix; chunk->prefix = *prefix;
chunk->proto = 0; chunk->proto = 0;
listnode_add(locator->chunks, chunk); listnode_add(locator->chunks, chunk);
} else { } else {
@ -270,7 +261,7 @@ DEFUN (locator_prefix,
struct zserv *client; struct zserv *client;
struct listnode *client_node; struct listnode *client_node;
chunk->prefix = prefix; chunk->prefix = *prefix;
for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, for (ALL_LIST_ELEMENTS_RO(zrouter.client_list,
client_node, client_node,
client)) { client)) {