]>
Commit | Line | Data |
---|---|---|
7e24fdf3 DS |
1 | /* |
2 | * STATICd - main code | |
3 | * Copyright (C) 2018 Cumulus Networks, Inc. | |
4 | * Donald Sharp | |
5 | * | |
8d5cbee9 DS |
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. | |
7e24fdf3 | 10 | * |
8d5cbee9 DS |
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. | |
7e24fdf3 DS |
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" | |
29348bd7 | 33 | #include "filter.h" |
88fa5104 | 34 | #include "routing_nb.h" |
7e24fdf3 DS |
35 | |
36 | #include "static_vrf.h" | |
37 | #include "static_vty.h" | |
38 | #include "static_routes.h" | |
39 | #include "static_zebra.h" | |
31ddf3b7 | 40 | #include "static_debug.h" |
88fa5104 | 41 | #include "static_nb.h" |
7e24fdf3 | 42 | |
ad3489a0 DS |
43 | char backup_config_file[256]; |
44 | ||
7e24fdf3 DS |
45 | bool mpls_enabled; |
46 | ||
41b21bfa | 47 | |
7e24fdf3 DS |
48 | zebra_capabilities_t _caps_p[] = { |
49 | }; | |
50 | ||
51 | struct zebra_privs_t static_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 | ||
63 | struct option longopts[] = { { 0 } }; | |
64 | ||
65 | /* Master of threads. */ | |
66 | struct thread_master *master; | |
67 | ||
88fa5104 | 68 | static struct frr_daemon_info staticd_di; |
7e24fdf3 DS |
69 | /* SIGHUP handler. */ |
70 | static void sighup(void) | |
71 | { | |
72 | zlog_info("SIGHUP received"); | |
88fa5104 | 73 | vty_read_config(NULL, staticd_di.config_file, config_default); |
7e24fdf3 DS |
74 | } |
75 | ||
76 | /* SIGINT / SIGTERM handler. */ | |
77 | static void sigint(void) | |
78 | { | |
79 | zlog_notice("Terminating on signal"); | |
80 | ||
a4155a1b | 81 | static_vrf_terminate(); |
82 | ||
41b21bfa MS |
83 | frr_fini(); |
84 | ||
7e24fdf3 DS |
85 | exit(0); |
86 | } | |
87 | ||
88 | /* SIGUSR1 handler. */ | |
89 | static void sigusr1(void) | |
90 | { | |
91 | zlog_rotate(); | |
92 | } | |
93 | ||
94 | struct quagga_signal_t static_signals[] = { | |
95 | { | |
96 | .signal = SIGHUP, | |
97 | .handler = &sighup, | |
98 | }, | |
99 | { | |
100 | .signal = SIGUSR1, | |
101 | .handler = &sigusr1, | |
102 | }, | |
103 | { | |
104 | .signal = SIGINT, | |
105 | .handler = &sigint, | |
106 | }, | |
107 | { | |
108 | .signal = SIGTERM, | |
109 | .handler = &sigint, | |
110 | }, | |
111 | }; | |
112 | ||
0d8c7a26 | 113 | static const struct frr_yang_module_info *const staticd_yang_modules[] = { |
c2aab693 | 114 | &frr_filter_info, |
88fa5104 | 115 | &frr_interface_info, |
6fd8972a | 116 | &frr_vrf_info, |
88fa5104 | 117 | &frr_routing_info, |
118 | &frr_staticd_info, | |
8fcdd0d6 RW |
119 | }; |
120 | ||
7e24fdf3 DS |
121 | #define STATIC_VTY_PORT 2616 |
122 | ||
123 | FRR_DAEMON_INFO(staticd, STATIC, .vty_port = STATIC_VTY_PORT, | |
124 | ||
125 | .proghelp = "Implementation of STATIC.", | |
126 | ||
127 | .signals = static_signals, | |
128 | .n_signals = array_size(static_signals), | |
129 | ||
8fcdd0d6 RW |
130 | .privs = &static_privs, .yang_modules = staticd_yang_modules, |
131 | .n_yang_modules = array_size(staticd_yang_modules), | |
ba86c88f | 132 | ) |
7e24fdf3 DS |
133 | |
134 | int main(int argc, char **argv, char **envp) | |
135 | { | |
136 | frr_preinit(&staticd_di, argc, argv); | |
137 | frr_opt_add("", longopts, ""); | |
138 | ||
139 | while (1) { | |
140 | int opt; | |
141 | ||
142 | opt = frr_getopt(argc, argv, NULL); | |
143 | ||
144 | if (opt == EOF) | |
145 | break; | |
146 | ||
147 | switch (opt) { | |
148 | case 0: | |
149 | break; | |
150 | default: | |
151 | frr_help_exit(1); | |
152 | break; | |
153 | } | |
154 | } | |
155 | ||
156 | master = frr_init(); | |
157 | ||
31ddf3b7 | 158 | static_debug_init(); |
7e24fdf3 DS |
159 | static_vrf_init(); |
160 | ||
161 | static_zebra_init(); | |
162 | static_vty_init(); | |
163 | ||
88fa5104 | 164 | hook_register(routing_conf_event, |
165 | routing_control_plane_protocols_name_validate); | |
166 | ||
ad3489a0 DS |
167 | snprintf(backup_config_file, sizeof(backup_config_file), |
168 | "%s/zebra.conf", frr_sysconfdir); | |
169 | staticd_di.backup_config_file = backup_config_file; | |
170 | ||
7e24fdf3 DS |
171 | frr_config_fork(); |
172 | frr_run(master); | |
173 | ||
174 | /* Not reached. */ | |
175 | return 0; | |
176 | } |