1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) 2019 Cumulus Networks, Inc.
9 #include "lib/command.h"
10 #include "lib/debug.h"
11 #include "lib/vector.h"
13 #include "vrrp_debug.h"
15 /* clang-format off */
16 struct debug vrrp_dbg_arp
= {0, "VRRP ARP"};
17 struct debug vrrp_dbg_auto
= {0, "VRRP autoconfiguration events"};
18 struct debug vrrp_dbg_ndisc
= {0, "VRRP Neighbor Discovery"};
19 struct debug vrrp_dbg_pkt
= {0, "VRRP packets"};
20 struct debug vrrp_dbg_proto
= {0, "VRRP protocol events"};
21 struct debug vrrp_dbg_sock
= {0, "VRRP sockets"};
22 struct debug vrrp_dbg_zebra
= {0, "VRRP Zebra events"};
24 struct debug
*vrrp_debugs
[] = {
34 const char *vrrp_debugs_conflines
[] = {
36 "debug vrrp autoconfigure",
39 "debug vrrp protocol",
46 * Set or unset flags on all debugs for vrrpd.
52 * Whether to set or unset the specified flags
54 static void vrrp_debug_set_all(uint32_t flags
, bool set
)
56 for (unsigned int i
= 0; i
< array_size(vrrp_debugs
); i
++) {
57 DEBUG_FLAGS_SET(vrrp_debugs
[i
], flags
, set
);
59 /* if all modes have been turned off, don't preserve options */
60 if (!DEBUG_MODE_CHECK(vrrp_debugs
[i
], DEBUG_MODE_ALL
))
61 DEBUG_CLEAR(vrrp_debugs
[i
]);
65 static int vrrp_debug_config_write_helper(struct vty
*vty
, bool config
)
67 uint32_t mode
= DEBUG_MODE_ALL
;
70 mode
= DEBUG_MODE_CONF
;
72 for (unsigned int i
= 0; i
< array_size(vrrp_debugs
); i
++)
73 if (DEBUG_MODE_CHECK(vrrp_debugs
[i
], mode
))
74 vty_out(vty
, "%s\n", vrrp_debugs_conflines
[i
]);
79 int vrrp_config_write_debug(struct vty
*vty
)
81 return vrrp_debug_config_write_helper(vty
, true);
84 int vrrp_debug_status_write(struct vty
*vty
)
86 return vrrp_debug_config_write_helper(vty
, false);
89 void vrrp_debug_set(struct interface
*ifp
, uint8_t vrid
, int vtynode
,
90 bool onoff
, bool proto
, bool autoconf
, bool pkt
, bool sock
,
91 bool ndisc
, bool arp
, bool zebra
)
93 uint32_t mode
= DEBUG_NODE2MODE(vtynode
);
96 DEBUG_MODE_SET(&vrrp_dbg_proto
, mode
, onoff
);
98 DEBUG_MODE_SET(&vrrp_dbg_auto
, mode
, onoff
);
100 DEBUG_MODE_SET(&vrrp_dbg_pkt
, mode
, onoff
);
102 DEBUG_MODE_SET(&vrrp_dbg_sock
, mode
, onoff
);
104 DEBUG_MODE_SET(&vrrp_dbg_ndisc
, mode
, onoff
);
106 DEBUG_MODE_SET(&vrrp_dbg_arp
, mode
, onoff
);
108 DEBUG_MODE_SET(&vrrp_dbg_zebra
, mode
, onoff
);
111 /* ------------------------------------------------------------------------- */
113 struct debug_callbacks vrrp_dbg_cbs
= {.debug_set_all
= vrrp_debug_set_all
};
115 void vrrp_debug_init(void)
117 debug_init(&vrrp_dbg_cbs
);