]> git.proxmox.com Git - mirror_frr.git/blob - sharpd/sharp_main.c
Merge pull request #13113 from sri-mohan1/sri-mohan-ldp
[mirror_frr.git] / sharpd / sharp_main.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * SHARP - main code
4 * Copyright (C) Cumulus Networks, Inc.
5 * Donald Sharp
6 */
7 #include <zebra.h>
8
9 #include <lib/version.h>
10 #include "getopt.h"
11 #include "frrevent.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"
30 #include "nexthop_group.h"
31 #include "link_state.h"
32
33 #include "sharp_zebra.h"
34 #include "sharp_vty.h"
35 #include "sharp_globals.h"
36 #include "sharp_nht.h"
37
38 DEFINE_MGROUP(SHARPD, "sharpd");
39
40 zebra_capabilities_t _caps_p[] = {
41 };
42
43 struct 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
55 struct option longopts[] = {{0}};
56
57 /* Master of threads. */
58 struct event_loop *master;
59
60 /* SIGHUP handler. */
61 static void sighup(void)
62 {
63 zlog_info("SIGHUP received");
64 }
65
66 /* SIGINT / SIGTERM handler. */
67 static void sigint(void)
68 {
69 zlog_notice("Terminating on signal");
70
71 frr_fini();
72
73 exit(0);
74 }
75
76 /* SIGUSR1 handler. */
77 static void sigusr1(void)
78 {
79 zlog_rotate();
80 }
81
82 struct frr_signal_t sharp_signals[] = {
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
103 static const struct frr_yang_module_info *const sharpd_yang_modules[] = {
104 &frr_filter_info,
105 &frr_interface_info,
106 &frr_route_map_info,
107 &frr_vrf_info,
108 };
109
110 FRR_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
117 .privs = &sharp_privs, .yang_modules = sharpd_yang_modules,
118 .n_yang_modules = array_size(sharpd_yang_modules),
119 );
120
121 struct sharp_global sg;
122
123 static void sharp_global_init(void)
124 {
125 memset(&sg, 0, sizeof(sg));
126 sg.nhs = list_new();
127 sg.ted = NULL;
128 sg.srv6_locators = list_new();
129 }
130
131 static void sharp_start_configuration(void)
132 {
133 zlog_debug("Configuration has started to be read");
134 }
135
136 static void sharp_end_configuration(void)
137 {
138 zlog_debug("Configuration has finished being read");
139 }
140
141 int 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);
159 }
160 }
161
162 master = frr_init();
163
164 cmd_init_config_callbacks(sharp_start_configuration,
165 sharp_end_configuration);
166 sharp_global_init();
167
168 sharp_nhgroup_init();
169 vrf_init(NULL, NULL, NULL, NULL);
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 }