]> git.proxmox.com Git - mirror_frr.git/blame - lib/command_graph.h
Merge pull request #12811 from Avineus/frr_neighlog_5884
[mirror_frr.git] / lib / command_graph.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
5894e76d
DL
2/*
3 * CLI graph handling
4 *
5 * --
6 * Copyright (C) 2016 Cumulus Networks, Inc.
7 * Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
8 * Copyright (C) 2013 by Open Source Routing.
9 * Copyright (C) 2013 by Internet Systems Consortium, Inc. ("ISC")
5894e76d
DL
10 */
11
12#ifndef _FRR_COMMAND_GRAPH_H
13#define _FRR_COMMAND_GRAPH_H
14
15#include <stdbool.h>
16#include <stdint.h>
17
18#include "memory.h"
19#include "vector.h"
20#include "graph.h"
feb06e7a 21#include "xref.h"
5894e76d 22
5e244469
RW
23#ifdef __cplusplus
24extern "C" {
25#endif
26
bf8d3d6a 27DECLARE_MTYPE(CMD_ARG);
5894e76d
DL
28
29struct vty;
30
31/**
32 * Types for tokens.
33 *
34 * The type determines what kind of data the token can match (in the
35 * matching use case) or hold (in the argv use case).
36 */
9779e3f1 37/* clang-format off */
d62a17ae 38enum cmd_token_type {
9779e3f1 39 WORD_TKN, // words
d62a17ae 40 VARIABLE_TKN, // almost anything
41 RANGE_TKN, // integer range
9779e3f1 42 IPV4_TKN, // IPV4 addresses
d62a17ae 43 IPV4_PREFIX_TKN, // IPV4 network prefixes
9779e3f1 44 IPV6_TKN, // IPV6 prefixes
d62a17ae 45 IPV6_PREFIX_TKN, // IPV6 network prefixes
9779e3f1
QY
46 MAC_TKN, // Ethernet address
47 MAC_PREFIX_TKN, // Ethernet address w/ CIDR mask
8079a413 48 ASNUM_TKN, // AS dot format
d62a17ae 49
50 /* plumbing types */
51 FORK_TKN, // marks subgraph beginning
52 JOIN_TKN, // marks subgraph end
53 START_TKN, // first token in line
54 END_TKN, // last token in line
90c8406c 55 NEG_ONLY_TKN, // filter token, match if "no ..." command
d62a17ae 56
57 SPECIAL_TKN = FORK_TKN,
5894e76d 58};
9779e3f1 59/* clang-format on */
5894e76d 60
70d44c5c
DL
61#define IS_VARYING_TOKEN(x) ((x) >= VARIABLE_TKN && (x) < FORK_TKN)
62
5894e76d 63/* Command attributes */
9eebf97e
DL
64enum {
65 CMD_ATTR_YANG = (1 << 0),
66 CMD_ATTR_HIDDEN = (1 << 1),
67 CMD_ATTR_DEPRECATED = (1 << 2),
3df57644 68 CMD_ATTR_NOSH = (1 << 3),
5894e76d
DL
69};
70
8005767b
DL
71enum varname_src {
72 VARNAME_NONE = 0,
73 VARNAME_AUTO,
74 VARNAME_VAR,
75 VARNAME_TEXT,
76 VARNAME_EXPLICIT,
77};
78
81eb8fc7 79/* Command token struct. */
d62a17ae 80struct cmd_token {
81 enum cmd_token_type type; // token type
82 uint8_t attr; // token attributes
81eb8fc7 83 bool allowrepeat; // matcher allowed to match token repetitively?
8005767b 84 uint8_t varname_src;
d62a17ae 85 uint32_t refcnt;
86
87 char *text; // token text
88 char *desc; // token description
89 long long min, max; // for ranges
90 char *arg; // user input that matches this token
91 char *varname;
92
93 struct graph_node *forkjoin; // paired FORK/JOIN for JOIN/FORK
5894e76d
DL
94};
95
96/* Structure of command element. */
d62a17ae 97struct cmd_element {
98 const char *string; /* Command specification by string. */
99 const char *doc; /* Documentation of this command. */
100 int daemon; /* Daemon to which this command belong. */
5e085e52 101 uint32_t attr; /* Command attributes */
5894e76d 102
d62a17ae 103 /* handler function for command */
104 int (*func)(const struct cmd_element *, struct vty *, int,
105 struct cmd_token *[]);
5894e76d 106
d62a17ae 107 const char *name; /* symbol name for debugging */
feb06e7a 108 struct xref xref;
5894e76d
DL
109};
110
111/* text for <cr> command */
112#define CMD_CR_TEXT "<cr>"
113
114/* memory management for cmd_token */
d62a17ae 115extern struct cmd_token *cmd_token_new(enum cmd_token_type, uint8_t attr,
116 const char *text, const char *desc);
117extern struct cmd_token *cmd_token_dup(struct cmd_token *);
118extern void cmd_token_del(struct cmd_token *);
5894e76d 119extern void cmd_token_varname_set(struct cmd_token *token, const char *varname);
8005767b
DL
120extern void cmd_token_varname_seqappend(struct graph_node *n);
121extern void cmd_token_varname_join(struct graph_node *n, const char *varname);
5894e76d 122
154e9ca1 123extern void cmd_graph_parse(struct graph *graph, const struct cmd_element *cmd);
d62a17ae 124extern void cmd_graph_names(struct graph *graph);
7f04943d 125extern void cmd_graph_merge(struct graph *old, struct graph *n,
d62a17ae 126 int direction);
26fbe472
QY
127/*
128 * Print callback for DOT dumping.
129 *
130 * See graph.h for more details.
131 */
132extern void cmd_graph_node_print_cb(struct graph_node *gn, struct buffer *buf);
133/*
134 * Dump command graph to DOT.
135 *
136 * cmdgraph
137 * A command graph to dump
138 *
139 * Returns:
140 * String allocated with MTYPE_TMP representing this graph
141 */
142char *cmd_graph_dump_dot(struct graph *cmdgraph);
5894e76d 143
5e244469
RW
144#ifdef __cplusplus
145}
146#endif
147
5894e76d 148#endif /* _FRR_COMMAND_GRAPH_H */