]> git.proxmox.com Git - mirror_frr.git/blob - lib/command_graph.h
Merge pull request #12126 from cscarpitta/fix/add-missing-debug-guard-bgpd-srv6
[mirror_frr.git] / lib / command_graph.h
1 /*
2 * CLI graph handling
3 *
4 * --
5 * Copyright (C) 2016 Cumulus Networks, Inc.
6 * Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
7 * Copyright (C) 2013 by Open Source Routing.
8 * Copyright (C) 2013 by Internet Systems Consortium, Inc. ("ISC")
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
13 * any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; see the file COPYING; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #ifndef _FRR_COMMAND_GRAPH_H
26 #define _FRR_COMMAND_GRAPH_H
27
28 #include <stdbool.h>
29 #include <stdint.h>
30
31 #include "memory.h"
32 #include "vector.h"
33 #include "graph.h"
34 #include "xref.h"
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 DECLARE_MTYPE(CMD_ARG);
41
42 struct vty;
43
44 /**
45 * Types for tokens.
46 *
47 * The type determines what kind of data the token can match (in the
48 * matching use case) or hold (in the argv use case).
49 */
50 /* clang-format off */
51 enum cmd_token_type {
52 WORD_TKN, // words
53 VARIABLE_TKN, // almost anything
54 RANGE_TKN, // integer range
55 IPV4_TKN, // IPV4 addresses
56 IPV4_PREFIX_TKN, // IPV4 network prefixes
57 IPV6_TKN, // IPV6 prefixes
58 IPV6_PREFIX_TKN, // IPV6 network prefixes
59 MAC_TKN, // Ethernet address
60 MAC_PREFIX_TKN, // Ethernet address w/ CIDR mask
61
62 /* plumbing types */
63 FORK_TKN, // marks subgraph beginning
64 JOIN_TKN, // marks subgraph end
65 START_TKN, // first token in line
66 END_TKN, // last token in line
67 NEG_ONLY_TKN, // filter token, match if "no ..." command
68
69 SPECIAL_TKN = FORK_TKN,
70 };
71 /* clang-format on */
72
73 #define IS_VARYING_TOKEN(x) ((x) >= VARIABLE_TKN && (x) < FORK_TKN)
74
75 /* Command attributes */
76 enum {
77 CMD_ATTR_YANG = (1 << 0),
78 CMD_ATTR_HIDDEN = (1 << 1),
79 CMD_ATTR_DEPRECATED = (1 << 2),
80 CMD_ATTR_NOSH = (1 << 3),
81 };
82
83 enum varname_src {
84 VARNAME_NONE = 0,
85 VARNAME_AUTO,
86 VARNAME_VAR,
87 VARNAME_TEXT,
88 VARNAME_EXPLICIT,
89 };
90
91 /* Command token struct. */
92 struct cmd_token {
93 enum cmd_token_type type; // token type
94 uint8_t attr; // token attributes
95 bool allowrepeat; // matcher allowed to match token repetitively?
96 uint8_t varname_src;
97 uint32_t refcnt;
98
99 char *text; // token text
100 char *desc; // token description
101 long long min, max; // for ranges
102 char *arg; // user input that matches this token
103 char *varname;
104
105 struct graph_node *forkjoin; // paired FORK/JOIN for JOIN/FORK
106 };
107
108 /* Structure of command element. */
109 struct cmd_element {
110 const char *string; /* Command specification by string. */
111 const char *doc; /* Documentation of this command. */
112 int daemon; /* Daemon to which this command belong. */
113 uint32_t attr; /* Command attributes */
114
115 /* handler function for command */
116 int (*func)(const struct cmd_element *, struct vty *, int,
117 struct cmd_token *[]);
118
119 const char *name; /* symbol name for debugging */
120 struct xref xref;
121 };
122
123 /* text for <cr> command */
124 #define CMD_CR_TEXT "<cr>"
125
126 /* memory management for cmd_token */
127 extern struct cmd_token *cmd_token_new(enum cmd_token_type, uint8_t attr,
128 const char *text, const char *desc);
129 extern struct cmd_token *cmd_token_dup(struct cmd_token *);
130 extern void cmd_token_del(struct cmd_token *);
131 extern void cmd_token_varname_set(struct cmd_token *token, const char *varname);
132 extern void cmd_token_varname_seqappend(struct graph_node *n);
133 extern void cmd_token_varname_join(struct graph_node *n, const char *varname);
134
135 extern void cmd_graph_parse(struct graph *graph, const struct cmd_element *cmd);
136 extern void cmd_graph_names(struct graph *graph);
137 extern void cmd_graph_merge(struct graph *old, struct graph *n,
138 int direction);
139 /*
140 * Print callback for DOT dumping.
141 *
142 * See graph.h for more details.
143 */
144 extern void cmd_graph_node_print_cb(struct graph_node *gn, struct buffer *buf);
145 /*
146 * Dump command graph to DOT.
147 *
148 * cmdgraph
149 * A command graph to dump
150 *
151 * Returns:
152 * String allocated with MTYPE_TMP representing this graph
153 */
154 char *cmd_graph_dump_dot(struct graph *cmdgraph);
155
156 #ifdef __cplusplus
157 }
158 #endif
159
160 #endif /* _FRR_COMMAND_GRAPH_H */