]> git.proxmox.com Git - mirror_frr.git/blob - lib/command_graph.h
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / lib / command_graph.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
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")
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"
21 #include "xref.h"
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 DECLARE_MTYPE(CMD_ARG);
28
29 struct 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 */
37 /* clang-format off */
38 enum cmd_token_type {
39 WORD_TKN, // words
40 VARIABLE_TKN, // almost anything
41 RANGE_TKN, // integer range
42 IPV4_TKN, // IPV4 addresses
43 IPV4_PREFIX_TKN, // IPV4 network prefixes
44 IPV6_TKN, // IPV6 prefixes
45 IPV6_PREFIX_TKN, // IPV6 network prefixes
46 MAC_TKN, // Ethernet address
47 MAC_PREFIX_TKN, // Ethernet address w/ CIDR mask
48 ASNUM_TKN, // AS dot format
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
55 NEG_ONLY_TKN, // filter token, match if "no ..." command
56
57 SPECIAL_TKN = FORK_TKN,
58 };
59 /* clang-format on */
60
61 #define IS_VARYING_TOKEN(x) ((x) >= VARIABLE_TKN && (x) < FORK_TKN)
62
63 /* Command attributes */
64 enum {
65 CMD_ATTR_YANG = (1 << 0),
66 CMD_ATTR_HIDDEN = (1 << 1),
67 CMD_ATTR_DEPRECATED = (1 << 2),
68 CMD_ATTR_NOSH = (1 << 3),
69 };
70
71 enum varname_src {
72 VARNAME_NONE = 0,
73 VARNAME_AUTO,
74 VARNAME_VAR,
75 VARNAME_TEXT,
76 VARNAME_EXPLICIT,
77 };
78
79 /* Command token struct. */
80 struct cmd_token {
81 enum cmd_token_type type; // token type
82 uint8_t attr; // token attributes
83 bool allowrepeat; // matcher allowed to match token repetitively?
84 uint8_t varname_src;
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
94 };
95
96 /* Structure of command element. */
97 struct 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. */
101 uint32_t attr; /* Command attributes */
102
103 /* handler function for command */
104 int (*func)(const struct cmd_element *, struct vty *, int,
105 struct cmd_token *[]);
106
107 const char *name; /* symbol name for debugging */
108 struct xref xref;
109 };
110
111 /* text for <cr> command */
112 #define CMD_CR_TEXT "<cr>"
113
114 /* memory management for cmd_token */
115 extern struct cmd_token *cmd_token_new(enum cmd_token_type, uint8_t attr,
116 const char *text, const char *desc);
117 extern struct cmd_token *cmd_token_dup(struct cmd_token *);
118 extern void cmd_token_del(struct cmd_token *);
119 extern void cmd_token_varname_set(struct cmd_token *token, const char *varname);
120 extern void cmd_token_varname_seqappend(struct graph_node *n);
121 extern void cmd_token_varname_join(struct graph_node *n, const char *varname);
122
123 extern void cmd_graph_parse(struct graph *graph, const struct cmd_element *cmd);
124 extern void cmd_graph_names(struct graph *graph);
125 extern void cmd_graph_merge(struct graph *old, struct graph *n,
126 int direction);
127 /*
128 * Print callback for DOT dumping.
129 *
130 * See graph.h for more details.
131 */
132 extern 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 */
142 char *cmd_graph_dump_dot(struct graph *cmdgraph);
143
144 #ifdef __cplusplus
145 }
146 #endif
147
148 #endif /* _FRR_COMMAND_GRAPH_H */