]>
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" | |
24a58196 | 11 | #include "frrevent.h" |
7e24fdf3 DS |
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 | |
d1e85e36 CH |
30 | #include "mgmt_be_client.h" |
31 | ||
ad3489a0 DS |
32 | char backup_config_file[256]; |
33 | ||
7e24fdf3 | 34 | bool mpls_enabled; |
41b21bfa | 35 | |
7e24fdf3 DS |
36 | zebra_capabilities_t _caps_p[] = { |
37 | }; | |
38 | ||
39 | struct zebra_privs_t static_privs = { | |
40 | #if defined(FRR_USER) && defined(FRR_GROUP) | |
41 | .user = FRR_USER, | |
42 | .group = FRR_GROUP, | |
43 | #endif | |
44 | #if defined(VTY_GROUP) | |
45 | .vty_group = VTY_GROUP, | |
46 | #endif | |
47 | .caps_p = _caps_p, | |
48 | .cap_num_p = array_size(_caps_p), | |
49 | .cap_num_i = 0}; | |
50 | ||
51 | struct option longopts[] = { { 0 } }; | |
52 | ||
53 | /* Master of threads. */ | |
cd9d0537 | 54 | struct event_loop *master; |
7e24fdf3 | 55 | |
7aecb863 | 56 | struct mgmt_be_client *mgmt_be_client; |
d1e85e36 | 57 | |
88fa5104 | 58 | static struct frr_daemon_info staticd_di; |
7e24fdf3 DS |
59 | /* SIGHUP handler. */ |
60 | static void sighup(void) | |
61 | { | |
62 | zlog_info("SIGHUP received"); | |
88fa5104 | 63 | vty_read_config(NULL, staticd_di.config_file, config_default); |
7e24fdf3 DS |
64 | } |
65 | ||
66 | /* SIGINT / SIGTERM handler. */ | |
67 | static void sigint(void) | |
68 | { | |
69 | zlog_notice("Terminating on signal"); | |
70 | ||
7a185ac8 DS |
71 | /* Disable BFD events to avoid wasting processing. */ |
72 | bfd_protocol_integration_set_shutdown(true); | |
73 | ||
7aecb863 | 74 | mgmt_be_client_destroy(mgmt_be_client); |
d1e85e36 | 75 | |
a4155a1b | 76 | static_vrf_terminate(); |
77 | ||
08040409 | 78 | static_zebra_stop(); |
41b21bfa MS |
79 | frr_fini(); |
80 | ||
7e24fdf3 DS |
81 | exit(0); |
82 | } | |
83 | ||
84 | /* SIGUSR1 handler. */ | |
85 | static void sigusr1(void) | |
86 | { | |
87 | zlog_rotate(); | |
88 | } | |
89 | ||
7cc91e67 | 90 | struct frr_signal_t static_signals[] = { |
7e24fdf3 DS |
91 | { |
92 | .signal = SIGHUP, | |
93 | .handler = &sighup, | |
94 | }, | |
95 | { | |
96 | .signal = SIGUSR1, | |
97 | .handler = &sigusr1, | |
98 | }, | |
99 | { | |
100 | .signal = SIGINT, | |
101 | .handler = &sigint, | |
102 | }, | |
103 | { | |
104 | .signal = SIGTERM, | |
105 | .handler = &sigint, | |
106 | }, | |
107 | }; | |
108 | ||
0d8c7a26 | 109 | static const struct frr_yang_module_info *const staticd_yang_modules[] = { |
c2aab693 | 110 | &frr_filter_info, |
88fa5104 | 111 | &frr_interface_info, |
6fd8972a | 112 | &frr_vrf_info, |
88fa5104 | 113 | &frr_routing_info, |
114 | &frr_staticd_info, | |
8fcdd0d6 RW |
115 | }; |
116 | ||
7e24fdf3 DS |
117 | #define STATIC_VTY_PORT 2616 |
118 | ||
8033bf39 CH |
119 | /* |
120 | * NOTE: .flags == FRR_NO_SPLIT_CONFIG to avoid reading split config, mgmtd will | |
121 | * do this for us now | |
122 | */ | |
7e24fdf3 DS |
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), | |
8033bf39 CH |
132 | |
133 | .flags = FRR_NO_SPLIT_CONFIG); | |
7e24fdf3 DS |
134 | |
135 | int main(int argc, char **argv, char **envp) | |
136 | { | |
137 | frr_preinit(&staticd_di, argc, argv); | |
138 | frr_opt_add("", longopts, ""); | |
139 | ||
140 | while (1) { | |
141 | int opt; | |
142 | ||
143 | opt = frr_getopt(argc, argv, NULL); | |
144 | ||
145 | if (opt == EOF) | |
146 | break; | |
147 | ||
148 | switch (opt) { | |
149 | case 0: | |
150 | break; | |
151 | default: | |
152 | frr_help_exit(1); | |
7e24fdf3 DS |
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 | ||
d1e85e36 | 164 | /* Initialize MGMT backend functionalities */ |
7aecb863 | 165 | mgmt_be_client = mgmt_be_client_create("staticd", NULL, 0, master); |
d1e85e36 | 166 | |
88fa5104 | 167 | hook_register(routing_conf_event, |
168 | routing_control_plane_protocols_name_validate); | |
169 | ||
2ada6269 IR |
170 | routing_control_plane_protocols_register_vrf_dependency(); |
171 | ||
8033bf39 CH |
172 | /* |
173 | * We set FRR_NO_SPLIT_CONFIG flag to avoid reading our config, but we | |
174 | * still need to write one if vtysh tells us to. Setting the host | |
175 | * config filename does this. | |
176 | */ | |
177 | host_config_set(config_default); | |
ad3489a0 | 178 | |
7e24fdf3 DS |
179 | frr_config_fork(); |
180 | frr_run(master); | |
181 | ||
182 | /* Not reached. */ | |
183 | return 0; | |
184 | } |