]> git.proxmox.com Git - mirror_frr.git/blame - nhrpd/nhrp_main.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / nhrpd / nhrp_main.c
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
2fb975da
TT
2/* NHRP daemon main functions
3 * Copyright (c) 2014-2015 Timo Teräs
2fb975da
TT
4 */
5
b45ac5f5
DL
6#ifdef HAVE_CONFIG_H
7#include "config.h"
8#endif
9
2fb975da
TT
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"
09781197 17#include "lib/version.h"
2fb975da
TT
18#include "log.h"
19#include "memory.h"
20#include "command.h"
4f04a76b 21#include "libfrr.h"
fb7f5aa8 22#include "filter.h"
2fb975da
TT
23
24#include "nhrpd.h"
aed07011 25#include "nhrp_errors.h"
2fb975da 26
bf8d3d6a 27DEFINE_MGROUP(NHRPD, "NHRP");
819dc8bb 28
2fb975da
TT
29unsigned int debug_flags = 0;
30
31struct thread_master *master;
32struct timeval current_time;
2fb975da
TT
33
34/* nhrpd options. */
996c9314 35struct option longopts[] = {{0}};
2fb975da
TT
36
37/* nhrpd privileges */
996c9314
LB
38static 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 */
2fb975da
TT
42};
43
26efbc7b 44struct zebra_privs_t nhrpd_privs = {
54b7b88b
HWC
45#if defined(FRR_USER) && defined(FRR_GROUP)
46 .user = FRR_USER,
47 .group = FRR_GROUP,
2fb975da
TT
48#endif
49#ifdef VTY_GROUP
50 .vty_group = VTY_GROUP,
51#endif
52 .caps_p = _caps_p,
7e3a1ec7 53 .cap_num_p = array_size(_caps_p),
db52be55 54 .cap_num_i = 0
2fb975da
TT
55};
56
db52be55 57
4f04a76b 58static void parse_arguments(int argc, char **argv)
2fb975da
TT
59{
60 int opt;
61
62 while (1) {
4f04a76b 63 opt = frr_getopt(argc, argv, 0);
996c9314
LB
64 if (opt < 0)
65 break;
2fb975da
TT
66
67 switch (opt) {
68 case 0:
69 break;
2fb975da 70 default:
4f04a76b 71 frr_help_exit(1);
2fb975da
TT
72 }
73 }
74}
75
76static void nhrp_sigusr1(void)
77{
dd8376fe 78 zlog_rotate();
2fb975da
TT
79}
80
81static void nhrp_request_stop(void)
82{
83 debugf(NHRP_DEBUG_COMMON, "Exiting...");
03951374 84 frr_early_fini();
2fb975da
TT
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();
2fb975da 93
2fb975da 94 debugf(NHRP_DEBUG_COMMON, "Done.");
03951374 95 frr_fini();
2fb975da
TT
96
97 exit(0);
98}
99
7cc91e67 100static struct frr_signal_t sighandlers[] = {
996c9314
LB
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 },
2fb975da
TT
113};
114
0d8c7a26 115static const struct frr_yang_module_info *const nhrpd_yang_modules[] = {
fb7f5aa8 116 &frr_filter_info,
a4bed468 117 &frr_interface_info,
f5eef2d5 118 &frr_vrf_info,
8fcdd0d6
RW
119};
120
996c9314 121FRR_DAEMON_INFO(nhrpd, NHRP, .vty_port = NHRP_VTY_PORT,
4f04a76b 122
996c9314 123 .proghelp = "Implementation of the NHRP routing protocol.",
4f04a76b 124
996c9314 125 .signals = sighandlers, .n_signals = array_size(sighandlers),
4f04a76b 126
8fcdd0d6 127 .privs = &nhrpd_privs, .yang_modules = nhrpd_yang_modules,
80413c20
DL
128 .n_yang_modules = array_size(nhrpd_yang_modules),
129);
4f04a76b 130
2fb975da
TT
131int main(int argc, char **argv)
132{
4f04a76b 133 frr_preinit(&nhrpd_di, argc, argv);
eb05883f 134 frr_opt_add("", longopts, "");
2fb975da 135
4f04a76b 136 parse_arguments(argc, argv);
2fb975da
TT
137
138 /* Library inits. */
4f04a76b 139 master = frr_init();
aed07011 140 nhrp_error_init();
ac2cb9bf 141 vrf_init(NULL, NULL, NULL, NULL);
818c8515 142 nhrp_interface_init();
fe9e7b71 143 resolver_init(master);
2fb975da 144
8ca7a3ed
DS
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);
2fb975da
TT
152 nhrpd_privs.change(ZPRIVS_RAISE);
153
2fb975da
TT
154 evmgr_init();
155 nhrp_vc_init();
156 nhrp_packet_init();
157 vici_init();
138c5a74
DS
158 if_zapi_callbacks(nhrp_ifp_create, nhrp_ifp_up,
159 nhrp_ifp_down, nhrp_ifp_destroy);
2fb975da
TT
160 nhrp_zebra_init();
161 nhrp_shortcut_init();
162
163 nhrp_config_init();
164
eb05883f 165 frr_config_fork();
16077f2f 166 frr_run(master);
2fb975da
TT
167 return 0;
168}