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