]> git.proxmox.com Git - mirror_frr.git/blob - sharpd/sharp_main.c
Merge pull request #2231 from ppmathis/fix/clear-bgp-afi
[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
46 #include "sharp_zebra.h"
47 #include "sharp_vty.h"
48
49 uint32_t total_routes = 0;
50 uint32_t installed_routes = 0;
51 uint32_t removed_routes = 0;
52
53 zebra_capabilities_t _caps_p[] = {
54 ZCAP_NET_RAW, ZCAP_BIND, ZCAP_NET_ADMIN,
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 exit(0);
86 }
87
88 /* SIGUSR1 handler. */
89 static void sigusr1(void)
90 {
91 zlog_rotate();
92 }
93
94 struct quagga_signal_t sharp_signals[] = {
95 {
96 .signal = SIGHUP,
97 .handler = &sighup,
98 },
99 {
100 .signal = SIGUSR1,
101 .handler = &sigusr1,
102 },
103 {
104 .signal = SIGINT,
105 .handler = &sigint,
106 },
107 {
108 .signal = SIGTERM,
109 .handler = &sigint,
110 },
111 };
112
113 #define SHARP_VTY_PORT 2614
114
115 FRR_DAEMON_INFO(sharpd, SHARP, .vty_port = SHARP_VTY_PORT,
116
117 .proghelp = "Implementation of a Sharp of routes daemon.",
118
119 .signals = sharp_signals,
120 .n_signals = array_size(sharp_signals),
121
122 .privs = &sharp_privs, )
123
124 extern void sharp_vty_init(void);
125
126 int main(int argc, char **argv, char **envp)
127 {
128 frr_preinit(&sharpd_di, argc, argv);
129 frr_opt_add("", longopts, "");
130
131 while (1) {
132 int opt;
133
134 opt = frr_getopt(argc, argv, NULL);
135
136 if (opt == EOF)
137 break;
138
139 switch (opt) {
140 case 0:
141 break;
142 default:
143 frr_help_exit(1);
144 break;
145 }
146 }
147
148 master = frr_init();
149
150 vrf_init(NULL, NULL, NULL, NULL);
151
152 route_map_init();
153
154 sharp_zebra_init();
155
156 /* Get configuration file. */
157 sharp_vty_init();
158
159 frr_config_fork();
160 frr_run(master);
161
162 /* Not reached. */
163 return 0;
164 }