]> git.proxmox.com Git - mirror_frr.git/blame - lib/debug.c
Merge pull request #5746 from donaldsharp/bgp_sa
[mirror_frr.git] / lib / debug.c
CommitLineData
aea03ad6
QY
1/*
2 * Debugging utilities.
3 * Copyright (C) 2018 Cumulus Networks, Inc.
4 * Quentin Young
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20#include <zebra.h>
f756a869 21#include "typesafe.h"
aea03ad6
QY
22#include "debug.h"
23#include "command.h"
24
f756a869
DS
25static struct debug_cb_list_head cb_head;
26
27DECLARE_LIST(debug_cb_list, struct debug_callbacks, item)
aea03ad6
QY
28
29/* All code in this section should be reentrant and MT-safe */
30
31DEFUN_NOSH(debug_all, debug_all_cmd, "[no] debug all",
32 NO_STR DEBUG_STR "Toggle all debugging output\n")
33{
f756a869
DS
34 struct debug_callbacks *cb;
35
e0cade1b 36 bool set = !strmatch(argv[0]->text, "no");
aea03ad6
QY
37 uint32_t mode = DEBUG_NODE2MODE(vty->node);
38
f756a869
DS
39 frr_each (debug_cb_list, &cb_head, cb)
40 cb->debug_set_all(mode, set);
41
aea03ad6
QY
42 return CMD_SUCCESS;
43}
44
45/* ------------------------------------------------------------------------- */
46
f756a869 47void debug_init(struct debug_callbacks *cb)
aea03ad6 48{
f756a869
DS
49 static bool inited = false;
50
51 if (!inited) {
52 inited = true;
53 debug_cb_list_init(&cb_head);
54 }
55
56 debug_cb_list_add_head(&cb_head, cb);
ae0994f6 57}
f756a869 58
ae0994f6
DS
59void debug_init_cli(void)
60{
aea03ad6
QY
61 install_element(ENABLE_NODE, &debug_all_cmd);
62 install_element(CONFIG_NODE, &debug_all_cmd);
63}