]>
Commit | Line | Data |
---|---|---|
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" |
1888e243 | 46 | #include "link_state.h" |
8a71d93d DS |
47 | |
48 | #include "sharp_zebra.h" | |
49 | #include "sharp_vty.h" | |
d21f1a93 | 50 | #include "sharp_globals.h" |
569e87c0 | 51 | #include "sharp_nht.h" |
8a71d93d | 52 | |
bf8d3d6a | 53 | DEFINE_MGROUP(SHARPD, "sharpd"); |
86da53ab | 54 | |
8a71d93d | 55 | zebra_capabilities_t _caps_p[] = { |
8a71d93d DS |
56 | }; |
57 | ||
58 | struct zebra_privs_t sharp_privs = { | |
59 | #if defined(FRR_USER) && defined(FRR_GROUP) | |
60 | .user = FRR_USER, | |
61 | .group = FRR_GROUP, | |
62 | #endif | |
63 | #if defined(VTY_GROUP) | |
64 | .vty_group = VTY_GROUP, | |
65 | #endif | |
66 | .caps_p = _caps_p, | |
67 | .cap_num_p = array_size(_caps_p), | |
68 | .cap_num_i = 0}; | |
69 | ||
70 | struct option longopts[] = {{0}}; | |
71 | ||
72 | /* Master of threads. */ | |
73 | struct thread_master *master; | |
74 | ||
75 | /* SIGHUP handler. */ | |
76 | static void sighup(void) | |
77 | { | |
78 | zlog_info("SIGHUP received"); | |
79 | } | |
80 | ||
81 | /* SIGINT / SIGTERM handler. */ | |
82 | static void sigint(void) | |
83 | { | |
84 | zlog_notice("Terminating on signal"); | |
85 | ||
41b21bfa MS |
86 | frr_fini(); |
87 | ||
8a71d93d DS |
88 | exit(0); |
89 | } | |
90 | ||
91 | /* SIGUSR1 handler. */ | |
92 | static void sigusr1(void) | |
93 | { | |
94 | zlog_rotate(); | |
95 | } | |
96 | ||
97 | struct quagga_signal_t sharp_signals[] = { | |
98 | { | |
99 | .signal = SIGHUP, | |
100 | .handler = &sighup, | |
101 | }, | |
102 | { | |
103 | .signal = SIGUSR1, | |
104 | .handler = &sigusr1, | |
105 | }, | |
106 | { | |
107 | .signal = SIGINT, | |
108 | .handler = &sigint, | |
109 | }, | |
110 | { | |
111 | .signal = SIGTERM, | |
112 | .handler = &sigint, | |
113 | }, | |
114 | }; | |
115 | ||
116 | #define SHARP_VTY_PORT 2614 | |
117 | ||
0d8c7a26 | 118 | static const struct frr_yang_module_info *const sharpd_yang_modules[] = { |
fb7f5aa8 | 119 | &frr_filter_info, |
6c6959e8 DS |
120 | &frr_interface_info, |
121 | &frr_route_map_info, | |
6fd8972a | 122 | &frr_vrf_info, |
8fcdd0d6 RW |
123 | }; |
124 | ||
8a71d93d DS |
125 | FRR_DAEMON_INFO(sharpd, SHARP, .vty_port = SHARP_VTY_PORT, |
126 | ||
127 | .proghelp = "Implementation of a Sharp of routes daemon.", | |
128 | ||
129 | .signals = sharp_signals, | |
130 | .n_signals = array_size(sharp_signals), | |
131 | ||
8fcdd0d6 | 132 | .privs = &sharp_privs, .yang_modules = sharpd_yang_modules, |
80413c20 DL |
133 | .n_yang_modules = array_size(sharpd_yang_modules), |
134 | ); | |
8a71d93d | 135 | |
d21f1a93 DS |
136 | struct sharp_global sg; |
137 | ||
138 | static void sharp_global_init(void) | |
139 | { | |
140 | memset(&sg, 0, sizeof(sg)); | |
86da53ab | 141 | sg.nhs = list_new(); |
1888e243 | 142 | sg.ted = NULL; |
ade3eebc | 143 | sg.srv6_locators = list_new(); |
d21f1a93 | 144 | } |
8a71d93d | 145 | |
f8e6ada8 DS |
146 | static void sharp_start_configuration(void) |
147 | { | |
148 | zlog_debug("Configuration has started to be read"); | |
149 | } | |
150 | ||
151 | static void sharp_end_configuration(void) | |
152 | { | |
153 | zlog_debug("Configuration has finished being read"); | |
154 | } | |
155 | ||
8a71d93d DS |
156 | int main(int argc, char **argv, char **envp) |
157 | { | |
158 | frr_preinit(&sharpd_di, argc, argv); | |
159 | frr_opt_add("", longopts, ""); | |
160 | ||
161 | while (1) { | |
162 | int opt; | |
163 | ||
164 | opt = frr_getopt(argc, argv, NULL); | |
165 | ||
166 | if (opt == EOF) | |
167 | break; | |
168 | ||
169 | switch (opt) { | |
170 | case 0: | |
171 | break; | |
172 | default: | |
173 | frr_help_exit(1); | |
8a71d93d DS |
174 | } |
175 | } | |
176 | ||
177 | master = frr_init(); | |
178 | ||
f8e6ada8 DS |
179 | cmd_init_config_callbacks(sharp_start_configuration, |
180 | sharp_end_configuration); | |
d21f1a93 DS |
181 | sharp_global_init(); |
182 | ||
569e87c0 | 183 | sharp_nhgroup_init(); |
ecbc5a37 | 184 | vrf_init(NULL, NULL, NULL, NULL, NULL); |
8a71d93d DS |
185 | |
186 | sharp_zebra_init(); | |
187 | ||
188 | /* Get configuration file. */ | |
189 | sharp_vty_init(); | |
190 | ||
191 | frr_config_fork(); | |
192 | frr_run(master); | |
193 | ||
194 | /* Not reached. */ | |
195 | return 0; | |
196 | } |