]>
Commit | Line | Data |
---|---|---|
5894e76d DL |
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 | * | |
896014f4 DL |
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 | |
5894e76d DL |
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 | ||
5e244469 RW |
35 | #ifdef __cplusplus |
36 | extern "C" { | |
37 | #endif | |
38 | ||
5894e76d DL |
39 | DECLARE_MTYPE(CMD_ARG) |
40 | ||
41 | struct vty; | |
42 | ||
43 | /** | |
44 | * Types for tokens. | |
45 | * | |
46 | * The type determines what kind of data the token can match (in the | |
47 | * matching use case) or hold (in the argv use case). | |
48 | */ | |
9779e3f1 | 49 | /* clang-format off */ |
d62a17ae | 50 | enum cmd_token_type { |
9779e3f1 | 51 | WORD_TKN, // words |
d62a17ae | 52 | VARIABLE_TKN, // almost anything |
53 | RANGE_TKN, // integer range | |
9779e3f1 | 54 | IPV4_TKN, // IPV4 addresses |
d62a17ae | 55 | IPV4_PREFIX_TKN, // IPV4 network prefixes |
9779e3f1 | 56 | IPV6_TKN, // IPV6 prefixes |
d62a17ae | 57 | IPV6_PREFIX_TKN, // IPV6 network prefixes |
9779e3f1 QY |
58 | MAC_TKN, // Ethernet address |
59 | MAC_PREFIX_TKN, // Ethernet address w/ CIDR mask | |
d62a17ae | 60 | |
61 | /* plumbing types */ | |
62 | FORK_TKN, // marks subgraph beginning | |
63 | JOIN_TKN, // marks subgraph end | |
64 | START_TKN, // first token in line | |
65 | END_TKN, // last token in line | |
66 | ||
67 | SPECIAL_TKN = FORK_TKN, | |
5894e76d | 68 | }; |
9779e3f1 | 69 | /* clang-format on */ |
5894e76d | 70 | |
70d44c5c DL |
71 | #define IS_VARYING_TOKEN(x) ((x) >= VARIABLE_TKN && (x) < FORK_TKN) |
72 | ||
5894e76d | 73 | /* Command attributes */ |
d62a17ae | 74 | enum { CMD_ATTR_NORMAL, |
75 | CMD_ATTR_DEPRECATED, | |
76 | CMD_ATTR_HIDDEN, | |
5894e76d DL |
77 | }; |
78 | ||
79 | /* Comamand token struct. */ | |
d62a17ae | 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 repetively? | |
84 | uint32_t refcnt; | |
85 | ||
86 | char *text; // token text | |
87 | char *desc; // token description | |
88 | long long min, max; // for ranges | |
89 | char *arg; // user input that matches this token | |
90 | char *varname; | |
91 | ||
92 | struct graph_node *forkjoin; // paired FORK/JOIN for JOIN/FORK | |
5894e76d DL |
93 | }; |
94 | ||
95 | /* Structure of command element. */ | |
d62a17ae | 96 | struct cmd_element { |
97 | const char *string; /* Command specification by string. */ | |
98 | const char *doc; /* Documentation of this command. */ | |
99 | int daemon; /* Daemon to which this command belong. */ | |
100 | uint8_t attr; /* Command attributes */ | |
5894e76d | 101 | |
d62a17ae | 102 | /* handler function for command */ |
103 | int (*func)(const struct cmd_element *, struct vty *, int, | |
104 | struct cmd_token *[]); | |
5894e76d | 105 | |
d62a17ae | 106 | const char *name; /* symbol name for debugging */ |
5894e76d DL |
107 | }; |
108 | ||
109 | /* text for <cr> command */ | |
110 | #define CMD_CR_TEXT "<cr>" | |
111 | ||
112 | /* memory management for cmd_token */ | |
d62a17ae | 113 | extern struct cmd_token *cmd_token_new(enum cmd_token_type, uint8_t attr, |
114 | const char *text, const char *desc); | |
115 | extern struct cmd_token *cmd_token_dup(struct cmd_token *); | |
116 | extern void cmd_token_del(struct cmd_token *); | |
5894e76d DL |
117 | extern void cmd_token_varname_set(struct cmd_token *token, const char *varname); |
118 | ||
d62a17ae | 119 | extern void cmd_graph_parse(struct graph *graph, struct cmd_element *cmd); |
120 | extern void cmd_graph_names(struct graph *graph); | |
7f04943d | 121 | extern void cmd_graph_merge(struct graph *old, struct graph *n, |
d62a17ae | 122 | int direction); |
26fbe472 QY |
123 | /* |
124 | * Print callback for DOT dumping. | |
125 | * | |
126 | * See graph.h for more details. | |
127 | */ | |
128 | extern void cmd_graph_node_print_cb(struct graph_node *gn, struct buffer *buf); | |
129 | /* | |
130 | * Dump command graph to DOT. | |
131 | * | |
132 | * cmdgraph | |
133 | * A command graph to dump | |
134 | * | |
135 | * Returns: | |
136 | * String allocated with MTYPE_TMP representing this graph | |
137 | */ | |
138 | char *cmd_graph_dump_dot(struct graph *cmdgraph); | |
5894e76d | 139 | |
5e244469 RW |
140 | #ifdef __cplusplus |
141 | } | |
142 | #endif | |
143 | ||
5894e76d | 144 | #endif /* _FRR_COMMAND_GRAPH_H */ |