]> git.proxmox.com Git - mirror_frr.git/blob - sharpd/sharp_main.c
Merge pull request #8078 from idryzhov/fix-zebra-vni
[mirror_frr.git] / sharpd / sharp_main.c
1 /*
2 * SHARP - main code
3 * Copyright (C) Cumulus Networks, Inc.
4 * Donald Sharp
5 *
6 * This file is part of FRR.
7 *
8 * FRR is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * FRR is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22 #include <zebra.h>
23
24 #include <lib/version.h>
25 #include "getopt.h"
26 #include "thread.h"
27 #include "prefix.h"
28 #include "linklist.h"
29 #include "if.h"
30 #include "vector.h"
31 #include "vty.h"
32 #include "command.h"
33 #include "filter.h"
34 #include "plist.h"
35 #include "stream.h"
36 #include "log.h"
37 #include "memory.h"
38 #include "privs.h"
39 #include "sigevent.h"
40 #include "zclient.h"
41 #include "keychain.h"
42 #include "distribute.h"
43 #include "libfrr.h"
44 #include "routemap.h"
45 #include "nexthop_group.h"
46
47 #include "sharp_zebra.h"
48 #include "sharp_vty.h"
49 #include "sharp_globals.h"
50 #include "sharp_nht.h"
51
52 DEFINE_MGROUP(SHARPD, "sharpd");
53
54 zebra_capabilities_t _caps_p[] = {
55 };
56
57 struct zebra_privs_t sharp_privs = {
58 #if defined(FRR_USER) && defined(FRR_GROUP)
59 .user = FRR_USER,
60 .group = FRR_GROUP,
61 #endif
62 #if defined(VTY_GROUP)
63 .vty_group = VTY_GROUP,
64 #endif
65 .caps_p = _caps_p,
66 .cap_num_p = array_size(_caps_p),
67 .cap_num_i = 0};
68
69 struct option longopts[] = {{0}};
70
71 /* Master of threads. */
72 struct thread_master *master;
73
74 /* SIGHUP handler. */
75 static void sighup(void)
76 {
77 zlog_info("SIGHUP received");
78 }
79
80 /* SIGINT / SIGTERM handler. */
81 static void sigint(void)
82 {
83 zlog_notice("Terminating on signal");
84
85 frr_fini();
86
87 exit(0);
88 }
89
90 /* SIGUSR1 handler. */
91 static void sigusr1(void)
92 {
93 zlog_rotate();
94 }
95
96 struct quagga_signal_t sharp_signals[] = {
97 {
98 .signal = SIGHUP,
99 .handler = &sighup,
100 },
101 {
102 .signal = SIGUSR1,
103 .handler = &sigusr1,
104 },
105 {
106 .signal = SIGINT,
107 .handler = &sigint,
108 },
109 {
110 .signal = SIGTERM,
111 .handler = &sigint,
112 },
113 };
114
115 #define SHARP_VTY_PORT 2614
116
117 static const struct frr_yang_module_info *const sharpd_yang_modules[] = {
118 &frr_filter_info,
119 &frr_interface_info,
120 &frr_route_map_info,
121 &frr_vrf_info,
122 };
123
124 FRR_DAEMON_INFO(sharpd, SHARP, .vty_port = SHARP_VTY_PORT,
125
126 .proghelp = "Implementation of a Sharp of routes daemon.",
127
128 .signals = sharp_signals,
129 .n_signals = array_size(sharp_signals),
130
131 .privs = &sharp_privs, .yang_modules = sharpd_yang_modules,
132 .n_yang_modules = array_size(sharpd_yang_modules),
133 );
134
135 struct sharp_global sg;
136
137 static void sharp_global_init(void)
138 {
139 memset(&sg, 0, sizeof(sg));
140 sg.nhs = list_new();
141 }
142
143 static void sharp_start_configuration(void)
144 {
145 zlog_debug("Configuration has started to be read");
146 }
147
148 static void sharp_end_configuration(void)
149 {
150 zlog_debug("Configuration has finished being read");
151 }
152
153 int main(int argc, char **argv, char **envp)
154 {
155 frr_preinit(&sharpd_di, argc, argv);
156 frr_opt_add("", longopts, "");
157
158 while (1) {
159 int opt;
160
161 opt = frr_getopt(argc, argv, NULL);
162
163 if (opt == EOF)
164 break;
165
166 switch (opt) {
167 case 0:
168 break;
169 default:
170 frr_help_exit(1);
171 break;
172 }
173 }
174
175 master = frr_init();
176
177 cmd_init_config_callbacks(sharp_start_configuration,
178 sharp_end_configuration);
179 sharp_global_init();
180
181 sharp_nhgroup_init();
182 vrf_init(NULL, NULL, NULL, NULL, NULL);
183
184 sharp_zebra_init();
185
186 /* Get configuration file. */
187 sharp_vty_init();
188
189 frr_config_fork();
190 frr_run(master);
191
192 /* Not reached. */
193 return 0;
194 }