]> git.proxmox.com Git - mirror_frr.git/blob - vrrpd/vrrp_main.c
Merge pull request #4365 from adharkar/frr-master-fpm_rtm_table
[mirror_frr.git] / vrrpd / vrrp_main.c
1 /*
2 * VRRP entry point.
3 * Copyright (C) 2018-2019 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>
21
22 #include <lib/version.h>
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"
36
37 #include "vrrp.h"
38 #include "vrrp_debug.h"
39 #include "vrrp_vty.h"
40 #include "vrrp_zebra.h"
41
42 char backup_config_file[256];
43
44 zebra_capabilities_t _caps_p[] = {
45 ZCAP_NET_RAW,
46 };
47
48 struct zebra_privs_t vrrp_privs = {
49 #if defined(FRR_USER) && defined(FRR_GROUP)
50 .user = FRR_USER,
51 .group = FRR_GROUP,
52 #endif
53 #if defined(VTY_GROUP)
54 .vty_group = VTY_GROUP,
55 #endif
56 .caps_p = _caps_p,
57 .cap_num_p = array_size(_caps_p),
58 .cap_num_i = 0};
59
60 struct option longopts[] = { {0} };
61
62 /* Master of threads. */
63 struct thread_master *master;
64
65 /* SIGHUP handler. */
66 static void sighup(void)
67 {
68 zlog_info("SIGHUP received");
69 }
70
71 /* SIGINT / SIGTERM handler. */
72 static void __attribute__((noreturn)) sigint(void)
73 {
74 zlog_notice("Terminating on signal");
75
76 vrrp_fini();
77
78 exit(0);
79 }
80
81 /* SIGUSR1 handler. */
82 static void sigusr1(void)
83 {
84 zlog_rotate();
85 }
86
87 struct quagga_signal_t vrrp_signals[] = {
88 {
89 .signal = SIGHUP,
90 .handler = &sighup,
91 },
92 {
93 .signal = SIGUSR1,
94 .handler = &sigusr1,
95 },
96 {
97 .signal = SIGINT,
98 .handler = &sigint,
99 },
100 {
101 .signal = SIGTERM,
102 .handler = &sigint,
103 },
104 };
105
106 static const struct frr_yang_module_info *vrrp_yang_modules[] = {
107 &frr_interface_info,
108 };
109
110 #define VRRP_VTY_PORT 2619
111
112 FRR_DAEMON_INFO(vrrpd, VRRP, .vty_port = VRRP_VTY_PORT,
113 .proghelp = "Virtual Router Redundancy Protocol",
114 .signals = vrrp_signals,
115 .n_signals = array_size(vrrp_signals),
116 .privs = &vrrp_privs,
117 .yang_modules = vrrp_yang_modules,
118 .n_yang_modules = array_size(vrrp_yang_modules),
119 )
120
121 int main(int argc, char **argv, char **envp)
122 {
123 frr_preinit(&vrrpd_di, argc, argv);
124 frr_opt_add("", longopts, "");
125
126 while (1) {
127 int opt;
128
129 opt = frr_getopt(argc, argv, NULL);
130
131 if (opt == EOF)
132 break;
133
134 switch (opt) {
135 case 0:
136 break;
137 default:
138 frr_help_exit(1);
139 break;
140 }
141 }
142
143 master = frr_init();
144
145 vrrp_debug_init();
146 vrrp_zebra_init();
147 vrrp_vty_init();
148 vrrp_init();
149
150 snprintf(backup_config_file, sizeof(backup_config_file),
151 "%s/vrrpd.conf", frr_sysconfdir);
152 vrrpd_di.backup_config_file = backup_config_file;
153
154 frr_config_fork();
155 frr_run(master);
156
157 /* Not reached. */
158 return 0;
159 }