]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
78fb3dbe QY |
2 | /* |
3 | * VRRP debugging. | |
4 | * Copyright (C) 2019 Cumulus Networks, Inc. | |
5 | * Quentin Young | |
78fb3dbe QY |
6 | */ |
7 | #include <zebra.h> | |
8 | ||
9 | #include "lib/command.h" | |
10 | #include "lib/debug.h" | |
11 | #include "lib/vector.h" | |
12 | ||
13 | #include "vrrp_debug.h" | |
14 | ||
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"}; | |
23 | ||
24 | struct debug *vrrp_debugs[] = { | |
2fff50ec | 25 | &vrrp_dbg_arp, |
78fb3dbe QY |
26 | &vrrp_dbg_auto, |
27 | &vrrp_dbg_ndisc, | |
28 | &vrrp_dbg_pkt, | |
29 | &vrrp_dbg_proto, | |
30 | &vrrp_dbg_sock, | |
31 | &vrrp_dbg_zebra | |
32 | }; | |
33 | ||
34 | const char *vrrp_debugs_conflines[] = { | |
35 | "debug vrrp arp", | |
36 | "debug vrrp autoconfigure", | |
37 | "debug vrrp ndisc", | |
38 | "debug vrrp packets", | |
39 | "debug vrrp protocol", | |
40 | "debug vrrp sockets", | |
41 | "debug vrrp zebra", | |
42 | }; | |
43 | /* clang-format on */ | |
44 | ||
45 | /* | |
46 | * Set or unset flags on all debugs for vrrpd. | |
47 | * | |
48 | * flags | |
49 | * The flags to set | |
50 | * | |
51 | * set | |
52 | * Whether to set or unset the specified flags | |
53 | */ | |
54 | static void vrrp_debug_set_all(uint32_t flags, bool set) | |
55 | { | |
56 | for (unsigned int i = 0; i < array_size(vrrp_debugs); i++) { | |
57 | DEBUG_FLAGS_SET(vrrp_debugs[i], flags, set); | |
58 | ||
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]); | |
62 | } | |
63 | } | |
64 | ||
65 | static int vrrp_debug_config_write_helper(struct vty *vty, bool config) | |
66 | { | |
67 | uint32_t mode = DEBUG_MODE_ALL; | |
68 | ||
69 | if (config) | |
70 | mode = DEBUG_MODE_CONF; | |
71 | ||
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]); | |
75 | ||
76 | return 0; | |
77 | } | |
78 | ||
f828842a | 79 | int vrrp_config_write_debug(struct vty *vty) |
78fb3dbe QY |
80 | { |
81 | return vrrp_debug_config_write_helper(vty, true); | |
82 | } | |
83 | ||
84 | int vrrp_debug_status_write(struct vty *vty) | |
85 | { | |
86 | return vrrp_debug_config_write_helper(vty, false); | |
87 | } | |
88 | ||
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) | |
92 | { | |
93 | uint32_t mode = DEBUG_NODE2MODE(vtynode); | |
94 | ||
95 | if (proto) | |
96 | DEBUG_MODE_SET(&vrrp_dbg_proto, mode, onoff); | |
97 | if (autoconf) | |
98 | DEBUG_MODE_SET(&vrrp_dbg_auto, mode, onoff); | |
99 | if (pkt) | |
100 | DEBUG_MODE_SET(&vrrp_dbg_pkt, mode, onoff); | |
101 | if (sock) | |
102 | DEBUG_MODE_SET(&vrrp_dbg_sock, mode, onoff); | |
103 | if (ndisc) | |
104 | DEBUG_MODE_SET(&vrrp_dbg_ndisc, mode, onoff); | |
105 | if (arp) | |
106 | DEBUG_MODE_SET(&vrrp_dbg_arp, mode, onoff); | |
107 | if (zebra) | |
108 | DEBUG_MODE_SET(&vrrp_dbg_zebra, mode, onoff); | |
109 | } | |
110 | ||
111 | /* ------------------------------------------------------------------------- */ | |
112 | ||
113 | struct debug_callbacks vrrp_dbg_cbs = {.debug_set_all = vrrp_debug_set_all}; | |
114 | ||
115 | void vrrp_debug_init(void) | |
116 | { | |
117 | debug_init(&vrrp_dbg_cbs); | |
118 | } |