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