1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* NHRP daemon main functions
3 * Copyright (c) 2014-2015 Timo Teräs
17 #include "lib/version.h"
25 #include "nhrp_errors.h"
27 DEFINE_MGROUP(NHRPD
, "NHRP");
29 unsigned int debug_flags
= 0;
31 struct event_loop
*master
;
32 struct timeval current_time
;
35 struct option longopts
[] = {{0}};
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 */
44 struct zebra_privs_t nhrpd_privs
= {
45 #if defined(FRR_USER) && defined(FRR_GROUP)
50 .vty_group
= VTY_GROUP
,
53 .cap_num_p
= array_size(_caps_p
),
58 static void parse_arguments(int argc
, char **argv
)
63 opt
= frr_getopt(argc
, argv
, 0);
76 static void nhrp_sigusr1(void)
81 static void nhrp_request_stop(void)
83 debugf(NHRP_DEBUG_COMMON
, "Exiting...");
86 nhrp_shortcut_terminate();
88 nhrp_zebra_terminate();
94 debugf(NHRP_DEBUG_COMMON
, "Done.");
100 static struct frr_signal_t sighandlers
[] = {
103 .handler
= &nhrp_sigusr1
,
107 .handler
= &nhrp_request_stop
,
111 .handler
= &nhrp_request_stop
,
115 static const struct frr_yang_module_info
*const nhrpd_yang_modules
[] = {
121 FRR_DAEMON_INFO(nhrpd
, NHRP
, .vty_port
= NHRP_VTY_PORT
,
123 .proghelp
= "Implementation of the NHRP routing protocol.",
125 .signals
= sighandlers
, .n_signals
= array_size(sighandlers
),
127 .privs
= &nhrpd_privs
, .yang_modules
= nhrpd_yang_modules
,
128 .n_yang_modules
= array_size(nhrpd_yang_modules
),
131 int main(int argc
, char **argv
)
133 frr_preinit(&nhrpd_di
, argc
, argv
);
134 frr_opt_add("", longopts
, "");
136 parse_arguments(argc
, argv
);
141 vrf_init(NULL
, NULL
, NULL
, NULL
);
142 nhrp_interface_init();
143 resolver_init(master
);
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
151 assert(nhrpd_privs
.change
);
152 nhrpd_privs
.change(ZPRIVS_RAISE
);
158 if_zapi_callbacks(nhrp_ifp_create
, nhrp_ifp_up
,
159 nhrp_ifp_down
, nhrp_ifp_destroy
);
161 nhrp_shortcut_init();