]> git.proxmox.com Git - mirror_frr.git/blame - sharpd/sharp_main.c
*: auto-convert to SPDX License IDs
[mirror_frr.git] / sharpd / sharp_main.c
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
8a71d93d
DS
2/*
3 * SHARP - main code
4 * Copyright (C) Cumulus Networks, Inc.
5 * Donald Sharp
8a71d93d
DS
6 */
7#include <zebra.h>
8
9#include <lib/version.h>
10#include "getopt.h"
11#include "thread.h"
12#include "prefix.h"
13#include "linklist.h"
14#include "if.h"
15#include "vector.h"
16#include "vty.h"
17#include "command.h"
18#include "filter.h"
19#include "plist.h"
20#include "stream.h"
21#include "log.h"
22#include "memory.h"
23#include "privs.h"
24#include "sigevent.h"
25#include "zclient.h"
26#include "keychain.h"
27#include "distribute.h"
28#include "libfrr.h"
29#include "routemap.h"
694b242f 30#include "nexthop_group.h"
1888e243 31#include "link_state.h"
8a71d93d
DS
32
33#include "sharp_zebra.h"
34#include "sharp_vty.h"
d21f1a93 35#include "sharp_globals.h"
569e87c0 36#include "sharp_nht.h"
8a71d93d 37
bf8d3d6a 38DEFINE_MGROUP(SHARPD, "sharpd");
86da53ab 39
8a71d93d 40zebra_capabilities_t _caps_p[] = {
8a71d93d
DS
41};
42
43struct zebra_privs_t sharp_privs = {
44#if defined(FRR_USER) && defined(FRR_GROUP)
45 .user = FRR_USER,
46 .group = FRR_GROUP,
47#endif
48#if defined(VTY_GROUP)
49 .vty_group = VTY_GROUP,
50#endif
51 .caps_p = _caps_p,
52 .cap_num_p = array_size(_caps_p),
53 .cap_num_i = 0};
54
55struct option longopts[] = {{0}};
56
57/* Master of threads. */
58struct thread_master *master;
59
60/* SIGHUP handler. */
61static void sighup(void)
62{
63 zlog_info("SIGHUP received");
64}
65
66/* SIGINT / SIGTERM handler. */
67static void sigint(void)
68{
69 zlog_notice("Terminating on signal");
70
41b21bfa
MS
71 frr_fini();
72
8a71d93d
DS
73 exit(0);
74}
75
76/* SIGUSR1 handler. */
77static void sigusr1(void)
78{
79 zlog_rotate();
80}
81
7cc91e67 82struct frr_signal_t sharp_signals[] = {
8a71d93d
DS
83 {
84 .signal = SIGHUP,
85 .handler = &sighup,
86 },
87 {
88 .signal = SIGUSR1,
89 .handler = &sigusr1,
90 },
91 {
92 .signal = SIGINT,
93 .handler = &sigint,
94 },
95 {
96 .signal = SIGTERM,
97 .handler = &sigint,
98 },
99};
100
101#define SHARP_VTY_PORT 2614
102
0d8c7a26 103static const struct frr_yang_module_info *const sharpd_yang_modules[] = {
fb7f5aa8 104 &frr_filter_info,
6c6959e8
DS
105 &frr_interface_info,
106 &frr_route_map_info,
6fd8972a 107 &frr_vrf_info,
8fcdd0d6
RW
108};
109
8a71d93d
DS
110FRR_DAEMON_INFO(sharpd, SHARP, .vty_port = SHARP_VTY_PORT,
111
112 .proghelp = "Implementation of a Sharp of routes daemon.",
113
114 .signals = sharp_signals,
115 .n_signals = array_size(sharp_signals),
116
8fcdd0d6 117 .privs = &sharp_privs, .yang_modules = sharpd_yang_modules,
80413c20
DL
118 .n_yang_modules = array_size(sharpd_yang_modules),
119);
8a71d93d 120
d21f1a93
DS
121struct sharp_global sg;
122
123static void sharp_global_init(void)
124{
125 memset(&sg, 0, sizeof(sg));
86da53ab 126 sg.nhs = list_new();
1888e243 127 sg.ted = NULL;
ade3eebc 128 sg.srv6_locators = list_new();
d21f1a93 129}
8a71d93d 130
f8e6ada8
DS
131static void sharp_start_configuration(void)
132{
133 zlog_debug("Configuration has started to be read");
134}
135
136static void sharp_end_configuration(void)
137{
138 zlog_debug("Configuration has finished being read");
139}
140
8a71d93d
DS
141int main(int argc, char **argv, char **envp)
142{
143 frr_preinit(&sharpd_di, argc, argv);
144 frr_opt_add("", longopts, "");
145
146 while (1) {
147 int opt;
148
149 opt = frr_getopt(argc, argv, NULL);
150
151 if (opt == EOF)
152 break;
153
154 switch (opt) {
155 case 0:
156 break;
157 default:
158 frr_help_exit(1);
8a71d93d
DS
159 }
160 }
161
162 master = frr_init();
163
f8e6ada8
DS
164 cmd_init_config_callbacks(sharp_start_configuration,
165 sharp_end_configuration);
d21f1a93
DS
166 sharp_global_init();
167
569e87c0 168 sharp_nhgroup_init();
ac2cb9bf 169 vrf_init(NULL, NULL, NULL, NULL);
8a71d93d
DS
170
171 sharp_zebra_init();
172
173 /* Get configuration file. */
174 sharp_vty_init();
175
176 frr_config_fork();
177 frr_run(master);
178
179 /* Not reached. */
180 return 0;
181}