3 * Copyright (C) 2019 Cumulus Networks, Inc.
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)
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
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
22 #include "lib/command.h"
23 #include "lib/debug.h"
24 #include "lib/vector.h"
26 #include "vrrp_debug.h"
28 /* clang-format off */
29 struct debug vrrp_dbg_arp
= {0, "VRRP ARP"};
30 struct debug vrrp_dbg_auto
= {0, "VRRP autoconfiguration events"};
31 struct debug vrrp_dbg_ndisc
= {0, "VRRP Neighbor Discovery"};
32 struct debug vrrp_dbg_pkt
= {0, "VRRP packets"};
33 struct debug vrrp_dbg_proto
= {0, "VRRP protocol events"};
34 struct debug vrrp_dbg_sock
= {0, "VRRP sockets"};
35 struct debug vrrp_dbg_zebra
= {0, "VRRP Zebra events"};
37 struct debug
*vrrp_debugs
[] = {
47 const char *vrrp_debugs_conflines
[] = {
49 "debug vrrp autoconfigure",
52 "debug vrrp protocol",
59 * Set or unset flags on all debugs for vrrpd.
65 * Whether to set or unset the specified flags
67 static void vrrp_debug_set_all(uint32_t flags
, bool set
)
69 for (unsigned int i
= 0; i
< array_size(vrrp_debugs
); i
++) {
70 DEBUG_FLAGS_SET(vrrp_debugs
[i
], flags
, set
);
72 /* if all modes have been turned off, don't preserve options */
73 if (!DEBUG_MODE_CHECK(vrrp_debugs
[i
], DEBUG_MODE_ALL
))
74 DEBUG_CLEAR(vrrp_debugs
[i
]);
78 static int vrrp_debug_config_write_helper(struct vty
*vty
, bool config
)
80 uint32_t mode
= DEBUG_MODE_ALL
;
83 mode
= DEBUG_MODE_CONF
;
85 for (unsigned int i
= 0; i
< array_size(vrrp_debugs
); i
++)
86 if (DEBUG_MODE_CHECK(vrrp_debugs
[i
], mode
))
87 vty_out(vty
, "%s\n", vrrp_debugs_conflines
[i
]);
92 int vrrp_config_write_debug(struct vty
*vty
)
94 return vrrp_debug_config_write_helper(vty
, true);
97 int vrrp_debug_status_write(struct vty
*vty
)
99 return vrrp_debug_config_write_helper(vty
, false);
102 void vrrp_debug_set(struct interface
*ifp
, uint8_t vrid
, int vtynode
,
103 bool onoff
, bool proto
, bool autoconf
, bool pkt
, bool sock
,
104 bool ndisc
, bool arp
, bool zebra
)
106 uint32_t mode
= DEBUG_NODE2MODE(vtynode
);
109 DEBUG_MODE_SET(&vrrp_dbg_proto
, mode
, onoff
);
111 DEBUG_MODE_SET(&vrrp_dbg_auto
, mode
, onoff
);
113 DEBUG_MODE_SET(&vrrp_dbg_pkt
, mode
, onoff
);
115 DEBUG_MODE_SET(&vrrp_dbg_sock
, mode
, onoff
);
117 DEBUG_MODE_SET(&vrrp_dbg_ndisc
, mode
, onoff
);
119 DEBUG_MODE_SET(&vrrp_dbg_arp
, mode
, onoff
);
121 DEBUG_MODE_SET(&vrrp_dbg_zebra
, mode
, onoff
);
124 /* ------------------------------------------------------------------------- */
126 struct debug_callbacks vrrp_dbg_cbs
= {.debug_set_all
= vrrp_debug_set_all
};
128 void vrrp_debug_init(void)
130 debug_init(&vrrp_dbg_cbs
);