1 /* NHRP daemon main functions
2 * Copyright (c) 2014-2015 Timo Teräs
4 * This file is free software: you may copy, redistribute and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
21 #include "lib/version.h"
29 #include "nhrp_errors.h"
31 DEFINE_MGROUP(NHRPD
, "NHRP");
33 unsigned int debug_flags
= 0;
35 struct thread_master
*master
;
36 struct timeval current_time
;
39 struct option longopts
[] = {{0}};
41 /* nhrpd privileges */
42 static zebra_capabilities_t _caps_p
[] = {
43 ZCAP_NET_RAW
, ZCAP_NET_ADMIN
,
44 ZCAP_DAC_OVERRIDE
, /* for now needed to write to
45 /proc/sys/net/ipv4/<if>/send_redirect */
48 struct zebra_privs_t nhrpd_privs
= {
49 #if defined(FRR_USER) && defined(FRR_GROUP)
54 .vty_group
= VTY_GROUP
,
57 .cap_num_p
= array_size(_caps_p
),
62 static void parse_arguments(int argc
, char **argv
)
67 opt
= frr_getopt(argc
, argv
, 0);
80 static void nhrp_sigusr1(void)
85 static void nhrp_request_stop(void)
87 debugf(NHRP_DEBUG_COMMON
, "Exiting...");
90 nhrp_shortcut_terminate();
92 nhrp_zebra_terminate();
98 debugf(NHRP_DEBUG_COMMON
, "Done.");
104 static struct frr_signal_t sighandlers
[] = {
107 .handler
= &nhrp_sigusr1
,
111 .handler
= &nhrp_request_stop
,
115 .handler
= &nhrp_request_stop
,
119 static const struct frr_yang_module_info
*const nhrpd_yang_modules
[] = {
125 FRR_DAEMON_INFO(nhrpd
, NHRP
, .vty_port
= NHRP_VTY_PORT
,
127 .proghelp
= "Implementation of the NHRP routing protocol.",
129 .signals
= sighandlers
, .n_signals
= array_size(sighandlers
),
131 .privs
= &nhrpd_privs
, .yang_modules
= nhrpd_yang_modules
,
132 .n_yang_modules
= array_size(nhrpd_yang_modules
),
135 int main(int argc
, char **argv
)
137 frr_preinit(&nhrpd_di
, argc
, argv
);
138 frr_opt_add("", longopts
, "");
140 parse_arguments(argc
, argv
);
145 vrf_init(NULL
, NULL
, NULL
, NULL
);
146 nhrp_interface_init();
147 resolver_init(master
);
150 * Run with elevated capabilities, as for all netlink activity
151 * we need privileges anyway.
152 * The assert is for clang SA code where it does
153 * not see the change function being set in lib
155 assert(nhrpd_privs
.change
);
156 nhrpd_privs
.change(ZPRIVS_RAISE
);
162 if_zapi_callbacks(nhrp_ifp_create
, nhrp_ifp_up
,
163 nhrp_ifp_down
, nhrp_ifp_destroy
);
165 nhrp_shortcut_init();