]> git.proxmox.com Git - mirror_frr.git/blob - staticd/static_main.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / staticd / static_main.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * STATICd - main code
4 * Copyright (C) 2018 Cumulus Networks, Inc.
5 * Donald Sharp
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"
20 #include "filter.h"
21 #include "routing_nb.h"
22
23 #include "static_vrf.h"
24 #include "static_vty.h"
25 #include "static_routes.h"
26 #include "static_zebra.h"
27 #include "static_debug.h"
28 #include "static_nb.h"
29
30 char backup_config_file[256];
31
32 bool mpls_enabled;
33
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
54 static struct frr_daemon_info staticd_di;
55 /* SIGHUP handler. */
56 static void sighup(void)
57 {
58 zlog_info("SIGHUP received");
59 vty_read_config(NULL, staticd_di.config_file, config_default);
60 }
61
62 /* SIGINT / SIGTERM handler. */
63 static void sigint(void)
64 {
65 zlog_notice("Terminating on signal");
66
67 static_vrf_terminate();
68
69 static_zebra_stop();
70 frr_fini();
71
72 exit(0);
73 }
74
75 /* SIGUSR1 handler. */
76 static void sigusr1(void)
77 {
78 zlog_rotate();
79 }
80
81 struct frr_signal_t static_signals[] = {
82 {
83 .signal = SIGHUP,
84 .handler = &sighup,
85 },
86 {
87 .signal = SIGUSR1,
88 .handler = &sigusr1,
89 },
90 {
91 .signal = SIGINT,
92 .handler = &sigint,
93 },
94 {
95 .signal = SIGTERM,
96 .handler = &sigint,
97 },
98 };
99
100 static const struct frr_yang_module_info *const staticd_yang_modules[] = {
101 &frr_filter_info,
102 &frr_interface_info,
103 &frr_vrf_info,
104 &frr_routing_info,
105 &frr_staticd_info,
106 };
107
108 #define STATIC_VTY_PORT 2616
109
110 FRR_DAEMON_INFO(staticd, STATIC, .vty_port = STATIC_VTY_PORT,
111
112 .proghelp = "Implementation of STATIC.",
113
114 .signals = static_signals,
115 .n_signals = array_size(static_signals),
116
117 .privs = &static_privs, .yang_modules = staticd_yang_modules,
118 .n_yang_modules = array_size(staticd_yang_modules),
119 );
120
121 int main(int argc, char **argv, char **envp)
122 {
123 frr_preinit(&staticd_di, argc, argv);
124 frr_opt_add("", longopts, "");
125
126 while (1) {
127 int opt;
128
129 opt = frr_getopt(argc, argv, NULL);
130
131 if (opt == EOF)
132 break;
133
134 switch (opt) {
135 case 0:
136 break;
137 default:
138 frr_help_exit(1);
139 }
140 }
141
142 master = frr_init();
143
144 static_debug_init();
145 static_vrf_init();
146
147 static_zebra_init();
148 static_vty_init();
149
150 hook_register(routing_conf_event,
151 routing_control_plane_protocols_name_validate);
152
153 routing_control_plane_protocols_register_vrf_dependency();
154
155 snprintf(backup_config_file, sizeof(backup_config_file),
156 "%s/zebra.conf", frr_sysconfdir);
157 staticd_di.backup_config_file = backup_config_file;
158
159 frr_config_fork();
160 frr_run(master);
161
162 /* Not reached. */
163 return 0;
164 }