]> git.proxmox.com Git - mirror_frr.git/blame - sharpd/sharp_main.c
Merge pull request #5810 from donaldsharp/fix_yang_routemap
[mirror_frr.git] / sharpd / sharp_main.c
CommitLineData
8a71d93d
DS
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"
694b242f 45#include "nexthop_group.h"
8a71d93d
DS
46
47#include "sharp_zebra.h"
48#include "sharp_vty.h"
d21f1a93 49#include "sharp_globals.h"
8a71d93d 50
86da53ab
DS
51DEFINE_MGROUP(SHARPD, "sharpd")
52
8a71d93d 53zebra_capabilities_t _caps_p[] = {
8a71d93d
DS
54};
55
56struct zebra_privs_t sharp_privs = {
57#if defined(FRR_USER) && defined(FRR_GROUP)
58 .user = FRR_USER,
59 .group = FRR_GROUP,
60#endif
61#if defined(VTY_GROUP)
62 .vty_group = VTY_GROUP,
63#endif
64 .caps_p = _caps_p,
65 .cap_num_p = array_size(_caps_p),
66 .cap_num_i = 0};
67
68struct option longopts[] = {{0}};
69
70/* Master of threads. */
71struct thread_master *master;
72
73/* SIGHUP handler. */
74static void sighup(void)
75{
76 zlog_info("SIGHUP received");
77}
78
79/* SIGINT / SIGTERM handler. */
80static void sigint(void)
81{
82 zlog_notice("Terminating on signal");
83
84 exit(0);
85}
86
87/* SIGUSR1 handler. */
88static void sigusr1(void)
89{
90 zlog_rotate();
91}
92
93struct quagga_signal_t sharp_signals[] = {
94 {
95 .signal = SIGHUP,
96 .handler = &sighup,
97 },
98 {
99 .signal = SIGUSR1,
100 .handler = &sigusr1,
101 },
102 {
103 .signal = SIGINT,
104 .handler = &sigint,
105 },
106 {
107 .signal = SIGTERM,
108 .handler = &sigint,
109 },
110};
111
112#define SHARP_VTY_PORT 2614
113
0d8c7a26 114static const struct frr_yang_module_info *const sharpd_yang_modules[] = {
6c6959e8
DS
115 &frr_interface_info,
116 &frr_route_map_info,
8fcdd0d6
RW
117};
118
8a71d93d
DS
119FRR_DAEMON_INFO(sharpd, SHARP, .vty_port = SHARP_VTY_PORT,
120
121 .proghelp = "Implementation of a Sharp of routes daemon.",
122
123 .signals = sharp_signals,
124 .n_signals = array_size(sharp_signals),
125
8fcdd0d6
RW
126 .privs = &sharp_privs, .yang_modules = sharpd_yang_modules,
127 .n_yang_modules = array_size(sharpd_yang_modules), )
8a71d93d 128
d21f1a93
DS
129struct sharp_global sg;
130
131static void sharp_global_init(void)
132{
133 memset(&sg, 0, sizeof(sg));
86da53ab 134 sg.nhs = list_new();
d21f1a93 135}
8a71d93d
DS
136
137int main(int argc, char **argv, char **envp)
138{
139 frr_preinit(&sharpd_di, argc, argv);
140 frr_opt_add("", longopts, "");
141
142 while (1) {
143 int opt;
144
145 opt = frr_getopt(argc, argv, NULL);
146
147 if (opt == EOF)
148 break;
149
150 switch (opt) {
151 case 0:
152 break;
153 default:
154 frr_help_exit(1);
155 break;
156 }
157 }
158
159 master = frr_init();
160
d21f1a93
DS
161 sharp_global_init();
162
81dd71eb 163 nexthop_group_init(NULL, NULL, NULL, NULL);
ecbc5a37 164 vrf_init(NULL, NULL, NULL, NULL, NULL);
8a71d93d 165
29348bd7 166 access_list_init();
808afce9
DS
167 route_map_init();
168
8a71d93d
DS
169 sharp_zebra_init();
170
171 /* Get configuration file. */
172 sharp_vty_init();
173
174 frr_config_fork();
175 frr_run(master);
176
177 /* Not reached. */
178 return 0;
179}