]> git.proxmox.com Git - mirror_frr.git/blame - lib/command_graph.h
Merge pull request #11469 from donaldsharp/fdev2
[mirror_frr.git] / lib / command_graph.h
CommitLineData
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"
feb06e7a 34#include "xref.h"
5894e76d 35
5e244469
RW
36#ifdef __cplusplus
37extern "C" {
38#endif
39
bf8d3d6a 40DECLARE_MTYPE(CMD_ARG);
5894e76d
DL
41
42struct 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 */
9779e3f1 50/* clang-format off */
d62a17ae 51enum cmd_token_type {
9779e3f1 52 WORD_TKN, // words
d62a17ae 53 VARIABLE_TKN, // almost anything
54 RANGE_TKN, // integer range
9779e3f1 55 IPV4_TKN, // IPV4 addresses
d62a17ae 56 IPV4_PREFIX_TKN, // IPV4 network prefixes
9779e3f1 57 IPV6_TKN, // IPV6 prefixes
d62a17ae 58 IPV6_PREFIX_TKN, // IPV6 network prefixes
9779e3f1
QY
59 MAC_TKN, // Ethernet address
60 MAC_PREFIX_TKN, // Ethernet address w/ CIDR mask
d62a17ae 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
90c8406c 67 NEG_ONLY_TKN, // filter token, match if "no ..." command
d62a17ae 68
69 SPECIAL_TKN = FORK_TKN,
5894e76d 70};
9779e3f1 71/* clang-format on */
5894e76d 72
70d44c5c
DL
73#define IS_VARYING_TOKEN(x) ((x) >= VARIABLE_TKN && (x) < FORK_TKN)
74
5894e76d 75/* Command attributes */
d62a17ae 76enum { CMD_ATTR_NORMAL,
77 CMD_ATTR_DEPRECATED,
78 CMD_ATTR_HIDDEN,
ca77b518 79 CMD_ATTR_YANG,
5894e76d
DL
80};
81
8005767b
DL
82enum varname_src {
83 VARNAME_NONE = 0,
84 VARNAME_AUTO,
85 VARNAME_VAR,
86 VARNAME_TEXT,
87 VARNAME_EXPLICIT,
88};
89
81eb8fc7 90/* Command token struct. */
d62a17ae 91struct cmd_token {
92 enum cmd_token_type type; // token type
93 uint8_t attr; // token attributes
81eb8fc7 94 bool allowrepeat; // matcher allowed to match token repetitively?
8005767b 95 uint8_t varname_src;
d62a17ae 96 uint32_t refcnt;
97
98 char *text; // token text
99 char *desc; // token description
100 long long min, max; // for ranges
101 char *arg; // user input that matches this token
102 char *varname;
103
104 struct graph_node *forkjoin; // paired FORK/JOIN for JOIN/FORK
5894e76d
DL
105};
106
107/* Structure of command element. */
d62a17ae 108struct cmd_element {
109 const char *string; /* Command specification by string. */
110 const char *doc; /* Documentation of this command. */
111 int daemon; /* Daemon to which this command belong. */
5e085e52 112 uint32_t attr; /* Command attributes */
5894e76d 113
d62a17ae 114 /* handler function for command */
115 int (*func)(const struct cmd_element *, struct vty *, int,
116 struct cmd_token *[]);
5894e76d 117
d62a17ae 118 const char *name; /* symbol name for debugging */
feb06e7a 119 struct xref xref;
5894e76d
DL
120};
121
122/* text for <cr> command */
123#define CMD_CR_TEXT "<cr>"
124
125/* memory management for cmd_token */
d62a17ae 126extern struct cmd_token *cmd_token_new(enum cmd_token_type, uint8_t attr,
127 const char *text, const char *desc);
128extern struct cmd_token *cmd_token_dup(struct cmd_token *);
129extern void cmd_token_del(struct cmd_token *);
5894e76d 130extern void cmd_token_varname_set(struct cmd_token *token, const char *varname);
8005767b
DL
131extern void cmd_token_varname_seqappend(struct graph_node *n);
132extern void cmd_token_varname_join(struct graph_node *n, const char *varname);
5894e76d 133
154e9ca1 134extern void cmd_graph_parse(struct graph *graph, const struct cmd_element *cmd);
d62a17ae 135extern void cmd_graph_names(struct graph *graph);
7f04943d 136extern void cmd_graph_merge(struct graph *old, struct graph *n,
d62a17ae 137 int direction);
26fbe472
QY
138/*
139 * Print callback for DOT dumping.
140 *
141 * See graph.h for more details.
142 */
143extern void cmd_graph_node_print_cb(struct graph_node *gn, struct buffer *buf);
144/*
145 * Dump command graph to DOT.
146 *
147 * cmdgraph
148 * A command graph to dump
149 *
150 * Returns:
151 * String allocated with MTYPE_TMP representing this graph
152 */
153char *cmd_graph_dump_dot(struct graph *cmdgraph);
5894e76d 154
5e244469
RW
155#ifdef __cplusplus
156}
157#endif
158
5894e76d 159#endif /* _FRR_COMMAND_GRAPH_H */