]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
7e24fdf3 DS |
2 | /* |
3 | * STATICd - main code | |
4 | * Copyright (C) 2018 Cumulus Networks, Inc. | |
5 | * Donald Sharp | |
7e24fdf3 DS |
6 | */ |
7 | #include <zebra.h> | |
8 | ||
9 | #include <lib/version.h> | |
10 | #include "getopt.h" | |
11 | #include "thread.h" | |
12 | #include "command.h" | |
13 | #include "log.h" | |
14 | #include "memory.h" | |
15 | #include "privs.h" | |
16 | #include "sigevent.h" | |
17 | #include "libfrr.h" | |
18 | #include "vrf.h" | |
19 | #include "nexthop.h" | |
29348bd7 | 20 | #include "filter.h" |
88fa5104 | 21 | #include "routing_nb.h" |
7e24fdf3 DS |
22 | |
23 | #include "static_vrf.h" | |
24 | #include "static_vty.h" | |
25 | #include "static_routes.h" | |
26 | #include "static_zebra.h" | |
31ddf3b7 | 27 | #include "static_debug.h" |
88fa5104 | 28 | #include "static_nb.h" |
7e24fdf3 | 29 | |
ad3489a0 DS |
30 | char backup_config_file[256]; |
31 | ||
7e24fdf3 | 32 | bool mpls_enabled; |
41b21bfa | 33 | |
7e24fdf3 DS |
34 | zebra_capabilities_t _caps_p[] = { |
35 | }; | |
36 | ||
37 | struct zebra_privs_t static_privs = { | |
38 | #if defined(FRR_USER) && defined(FRR_GROUP) | |
39 | .user = FRR_USER, | |
40 | .group = FRR_GROUP, | |
41 | #endif | |
42 | #if defined(VTY_GROUP) | |
43 | .vty_group = VTY_GROUP, | |
44 | #endif | |
45 | .caps_p = _caps_p, | |
46 | .cap_num_p = array_size(_caps_p), | |
47 | .cap_num_i = 0}; | |
48 | ||
49 | struct option longopts[] = { { 0 } }; | |
50 | ||
51 | /* Master of threads. */ | |
52 | struct thread_master *master; | |
53 | ||
88fa5104 | 54 | static struct frr_daemon_info staticd_di; |
7e24fdf3 DS |
55 | /* SIGHUP handler. */ |
56 | static void sighup(void) | |
57 | { | |
58 | zlog_info("SIGHUP received"); | |
88fa5104 | 59 | vty_read_config(NULL, staticd_di.config_file, config_default); |
7e24fdf3 DS |
60 | } |
61 | ||
62 | /* SIGINT / SIGTERM handler. */ | |
63 | static void sigint(void) | |
64 | { | |
65 | zlog_notice("Terminating on signal"); | |
66 | ||
7a185ac8 DS |
67 | /* Disable BFD events to avoid wasting processing. */ |
68 | bfd_protocol_integration_set_shutdown(true); | |
69 | ||
a4155a1b | 70 | static_vrf_terminate(); |
71 | ||
08040409 | 72 | static_zebra_stop(); |
41b21bfa MS |
73 | frr_fini(); |
74 | ||
7e24fdf3 DS |
75 | exit(0); |
76 | } | |
77 | ||
78 | /* SIGUSR1 handler. */ | |
79 | static void sigusr1(void) | |
80 | { | |
81 | zlog_rotate(); | |
82 | } | |
83 | ||
7cc91e67 | 84 | struct frr_signal_t static_signals[] = { |
7e24fdf3 DS |
85 | { |
86 | .signal = SIGHUP, | |
87 | .handler = &sighup, | |
88 | }, | |
89 | { | |
90 | .signal = SIGUSR1, | |
91 | .handler = &sigusr1, | |
92 | }, | |
93 | { | |
94 | .signal = SIGINT, | |
95 | .handler = &sigint, | |
96 | }, | |
97 | { | |
98 | .signal = SIGTERM, | |
99 | .handler = &sigint, | |
100 | }, | |
101 | }; | |
102 | ||
0d8c7a26 | 103 | static const struct frr_yang_module_info *const staticd_yang_modules[] = { |
c2aab693 | 104 | &frr_filter_info, |
88fa5104 | 105 | &frr_interface_info, |
6fd8972a | 106 | &frr_vrf_info, |
88fa5104 | 107 | &frr_routing_info, |
108 | &frr_staticd_info, | |
8fcdd0d6 RW |
109 | }; |
110 | ||
7e24fdf3 DS |
111 | #define STATIC_VTY_PORT 2616 |
112 | ||
113 | FRR_DAEMON_INFO(staticd, STATIC, .vty_port = STATIC_VTY_PORT, | |
114 | ||
115 | .proghelp = "Implementation of STATIC.", | |
116 | ||
117 | .signals = static_signals, | |
118 | .n_signals = array_size(static_signals), | |
119 | ||
8fcdd0d6 RW |
120 | .privs = &static_privs, .yang_modules = staticd_yang_modules, |
121 | .n_yang_modules = array_size(staticd_yang_modules), | |
80413c20 | 122 | ); |
7e24fdf3 DS |
123 | |
124 | int main(int argc, char **argv, char **envp) | |
125 | { | |
126 | frr_preinit(&staticd_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); | |
7e24fdf3 DS |
142 | } |
143 | } | |
144 | ||
145 | master = frr_init(); | |
146 | ||
31ddf3b7 | 147 | static_debug_init(); |
7e24fdf3 DS |
148 | static_vrf_init(); |
149 | ||
150 | static_zebra_init(); | |
151 | static_vty_init(); | |
152 | ||
88fa5104 | 153 | hook_register(routing_conf_event, |
154 | routing_control_plane_protocols_name_validate); | |
155 | ||
2ada6269 IR |
156 | routing_control_plane_protocols_register_vrf_dependency(); |
157 | ||
ad3489a0 DS |
158 | snprintf(backup_config_file, sizeof(backup_config_file), |
159 | "%s/zebra.conf", frr_sysconfdir); | |
160 | staticd_di.backup_config_file = backup_config_file; | |
161 | ||
7e24fdf3 DS |
162 | frr_config_fork(); |
163 | frr_run(master); | |
164 | ||
165 | /* Not reached. */ | |
166 | return 0; | |
167 | } |