]> git.proxmox.com Git - mirror_frr.git/blob - nhrpd/nhrp_main.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / nhrpd / nhrp_main.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* NHRP daemon main functions
3 * Copyright (c) 2014-2015 Timo Teräs
4 */
5
6 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif
9
10 #include <unistd.h>
11
12 #include "zebra.h"
13 #include "privs.h"
14 #include "getopt.h"
15 #include "thread.h"
16 #include "sigevent.h"
17 #include "lib/version.h"
18 #include "log.h"
19 #include "memory.h"
20 #include "command.h"
21 #include "libfrr.h"
22 #include "filter.h"
23
24 #include "nhrpd.h"
25 #include "nhrp_errors.h"
26
27 DEFINE_MGROUP(NHRPD, "NHRP");
28
29 unsigned int debug_flags = 0;
30
31 struct thread_master *master;
32 struct timeval current_time;
33
34 /* nhrpd options. */
35 struct option longopts[] = {{0}};
36
37 /* nhrpd privileges */
38 static zebra_capabilities_t _caps_p[] = {
39 ZCAP_NET_RAW, ZCAP_NET_ADMIN,
40 ZCAP_DAC_OVERRIDE, /* for now needed to write to
41 /proc/sys/net/ipv4/<if>/send_redirect */
42 };
43
44 struct zebra_privs_t nhrpd_privs = {
45 #if defined(FRR_USER) && defined(FRR_GROUP)
46 .user = FRR_USER,
47 .group = FRR_GROUP,
48 #endif
49 #ifdef VTY_GROUP
50 .vty_group = VTY_GROUP,
51 #endif
52 .caps_p = _caps_p,
53 .cap_num_p = array_size(_caps_p),
54 .cap_num_i = 0
55 };
56
57
58 static void parse_arguments(int argc, char **argv)
59 {
60 int opt;
61
62 while (1) {
63 opt = frr_getopt(argc, argv, 0);
64 if (opt < 0)
65 break;
66
67 switch (opt) {
68 case 0:
69 break;
70 default:
71 frr_help_exit(1);
72 }
73 }
74 }
75
76 static void nhrp_sigusr1(void)
77 {
78 zlog_rotate();
79 }
80
81 static void nhrp_request_stop(void)
82 {
83 debugf(NHRP_DEBUG_COMMON, "Exiting...");
84 frr_early_fini();
85
86 nhrp_shortcut_terminate();
87 nhrp_nhs_terminate();
88 nhrp_zebra_terminate();
89 vici_terminate();
90 evmgr_terminate();
91 nhrp_vc_terminate();
92 vrf_terminate();
93
94 debugf(NHRP_DEBUG_COMMON, "Done.");
95 frr_fini();
96
97 exit(0);
98 }
99
100 static struct frr_signal_t sighandlers[] = {
101 {
102 .signal = SIGUSR1,
103 .handler = &nhrp_sigusr1,
104 },
105 {
106 .signal = SIGINT,
107 .handler = &nhrp_request_stop,
108 },
109 {
110 .signal = SIGTERM,
111 .handler = &nhrp_request_stop,
112 },
113 };
114
115 static const struct frr_yang_module_info *const nhrpd_yang_modules[] = {
116 &frr_filter_info,
117 &frr_interface_info,
118 &frr_vrf_info,
119 };
120
121 FRR_DAEMON_INFO(nhrpd, NHRP, .vty_port = NHRP_VTY_PORT,
122
123 .proghelp = "Implementation of the NHRP routing protocol.",
124
125 .signals = sighandlers, .n_signals = array_size(sighandlers),
126
127 .privs = &nhrpd_privs, .yang_modules = nhrpd_yang_modules,
128 .n_yang_modules = array_size(nhrpd_yang_modules),
129 );
130
131 int main(int argc, char **argv)
132 {
133 frr_preinit(&nhrpd_di, argc, argv);
134 frr_opt_add("", longopts, "");
135
136 parse_arguments(argc, argv);
137
138 /* Library inits. */
139 master = frr_init();
140 nhrp_error_init();
141 vrf_init(NULL, NULL, NULL, NULL);
142 nhrp_interface_init();
143 resolver_init(master);
144
145 /*
146 * Run with elevated capabilities, as for all netlink activity
147 * we need privileges anyway.
148 * The assert is for clang SA code where it does
149 * not see the change function being set in lib
150 */
151 assert(nhrpd_privs.change);
152 nhrpd_privs.change(ZPRIVS_RAISE);
153
154 evmgr_init();
155 nhrp_vc_init();
156 nhrp_packet_init();
157 vici_init();
158 if_zapi_callbacks(nhrp_ifp_create, nhrp_ifp_up,
159 nhrp_ifp_down, nhrp_ifp_destroy);
160 nhrp_zebra_init();
161 nhrp_shortcut_init();
162
163 nhrp_config_init();
164
165 frr_config_fork();
166 frr_run(master);
167 return 0;
168 }