]>
Commit | Line | Data |
---|---|---|
5435a2bf | 1 | /* |
63d4bd12 QY |
2 | * VRRP entry point. |
3 | * Copyright (C) 2018-2019 Cumulus Networks, Inc. | |
4 | * Quentin Young | |
5435a2bf QY |
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> | |
21 | ||
22 | #include <lib/version.h> | |
63d4bd12 QY |
23 | |
24 | #include "lib/command.h" | |
25 | #include "lib/filter.h" | |
26 | #include "lib/getopt.h" | |
27 | #include "lib/if.h" | |
28 | #include "lib/libfrr.h" | |
29 | #include "lib/log.h" | |
30 | #include "lib/memory.h" | |
31 | #include "lib/nexthop.h" | |
32 | #include "lib/privs.h" | |
33 | #include "lib/sigevent.h" | |
34 | #include "lib/thread.h" | |
35 | #include "lib/vrf.h" | |
534b98f9 | 36 | #include "lib/vty.h" |
5435a2bf QY |
37 | |
38 | #include "vrrp.h" | |
78fb3dbe | 39 | #include "vrrp_debug.h" |
5435a2bf | 40 | #include "vrrp_vty.h" |
63d4bd12 | 41 | #include "vrrp_zebra.h" |
5435a2bf | 42 | |
bf8d3d6a | 43 | DEFINE_MGROUP(VRRPD, "vrrpd"); |
7c136b08 | 44 | |
5435a2bf QY |
45 | char backup_config_file[256]; |
46 | ||
47 | zebra_capabilities_t _caps_p[] = { | |
40744000 | 48 | ZCAP_NET_RAW, |
5435a2bf QY |
49 | }; |
50 | ||
51 | struct zebra_privs_t vrrp_privs = { | |
52 | #if defined(FRR_USER) && defined(FRR_GROUP) | |
53 | .user = FRR_USER, | |
54 | .group = FRR_GROUP, | |
55 | #endif | |
56 | #if defined(VTY_GROUP) | |
57 | .vty_group = VTY_GROUP, | |
58 | #endif | |
59 | .caps_p = _caps_p, | |
60 | .cap_num_p = array_size(_caps_p), | |
61 | .cap_num_i = 0}; | |
62 | ||
19c38250 | 63 | struct option longopts[] = { {0} }; |
5435a2bf QY |
64 | |
65 | /* Master of threads. */ | |
66 | struct thread_master *master; | |
67 | ||
534b98f9 QY |
68 | static struct frr_daemon_info vrrpd_di; |
69 | ||
5435a2bf QY |
70 | /* SIGHUP handler. */ |
71 | static void sighup(void) | |
72 | { | |
73 | zlog_info("SIGHUP received"); | |
534b98f9 QY |
74 | |
75 | vty_read_config(NULL, vrrpd_di.config_file, config_default); | |
5435a2bf QY |
76 | } |
77 | ||
78 | /* SIGINT / SIGTERM handler. */ | |
f1175ba9 | 79 | static void __attribute__((noreturn)) sigint(void) |
5435a2bf QY |
80 | { |
81 | zlog_notice("Terminating on signal"); | |
82 | ||
f1175ba9 QY |
83 | vrrp_fini(); |
84 | ||
41b21bfa MS |
85 | frr_fini(); |
86 | ||
5435a2bf QY |
87 | exit(0); |
88 | } | |
89 | ||
90 | /* SIGUSR1 handler. */ | |
91 | static void sigusr1(void) | |
92 | { | |
93 | zlog_rotate(); | |
94 | } | |
95 | ||
96 | struct quagga_signal_t vrrp_signals[] = { | |
97 | { | |
98 | .signal = SIGHUP, | |
99 | .handler = &sighup, | |
100 | }, | |
101 | { | |
102 | .signal = SIGUSR1, | |
103 | .handler = &sigusr1, | |
104 | }, | |
105 | { | |
106 | .signal = SIGINT, | |
107 | .handler = &sigint, | |
108 | }, | |
109 | { | |
110 | .signal = SIGTERM, | |
111 | .handler = &sigint, | |
112 | }, | |
113 | }; | |
114 | ||
0d8c7a26 | 115 | static const struct frr_yang_module_info *const vrrp_yang_modules[] = { |
fb7f5aa8 | 116 | &frr_filter_info, |
57f4b459 | 117 | &frr_vrf_info, |
a8144d7f | 118 | &frr_interface_info, |
f495425b | 119 | &frr_vrrpd_info, |
5435a2bf QY |
120 | }; |
121 | ||
8261c2e3 | 122 | #define VRRP_VTY_PORT 2619 |
5435a2bf QY |
123 | |
124 | FRR_DAEMON_INFO(vrrpd, VRRP, .vty_port = VRRP_VTY_PORT, | |
125 | .proghelp = "Virtual Router Redundancy Protocol", | |
126 | .signals = vrrp_signals, | |
127 | .n_signals = array_size(vrrp_signals), | |
128 | .privs = &vrrp_privs, | |
129 | .yang_modules = vrrp_yang_modules, | |
130 | .n_yang_modules = array_size(vrrp_yang_modules), | |
80413c20 | 131 | ); |
5435a2bf QY |
132 | |
133 | int main(int argc, char **argv, char **envp) | |
134 | { | |
135 | frr_preinit(&vrrpd_di, argc, argv); | |
136 | frr_opt_add("", longopts, ""); | |
137 | ||
138 | while (1) { | |
139 | int opt; | |
140 | ||
141 | opt = frr_getopt(argc, argv, NULL); | |
142 | ||
143 | if (opt == EOF) | |
144 | break; | |
145 | ||
146 | switch (opt) { | |
147 | case 0: | |
148 | break; | |
149 | default: | |
150 | frr_help_exit(1); | |
151 | break; | |
152 | } | |
153 | } | |
154 | ||
155 | master = frr_init(); | |
156 | ||
7d938b22 | 157 | access_list_init(); |
78fb3dbe | 158 | vrrp_debug_init(); |
5435a2bf QY |
159 | vrrp_zebra_init(); |
160 | vrrp_vty_init(); | |
161 | vrrp_init(); | |
162 | ||
163 | snprintf(backup_config_file, sizeof(backup_config_file), | |
164 | "%s/vrrpd.conf", frr_sysconfdir); | |
165 | vrrpd_di.backup_config_file = backup_config_file; | |
166 | ||
167 | frr_config_fork(); | |
168 | frr_run(master); | |
169 | ||
170 | /* Not reached. */ | |
171 | return 0; | |
172 | } |