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