]> git.proxmox.com Git - mirror_frr.git/blame - nhrpd/nhrp_main.c
zebra: Allow ns delete to happen after under/over flow checks
[mirror_frr.git] / nhrpd / nhrp_main.c
CommitLineData
2fb975da
TT
1/* NHRP daemon main functions
2 * Copyright (c) 2014-2015 Timo Teräs
3 *
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.
8 */
9
b45ac5f5
DL
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
2fb975da
TT
14#include <unistd.h>
15
16#include "zebra.h"
17#include "privs.h"
18#include "getopt.h"
19#include "thread.h"
20#include "sigevent.h"
21#include "version.h"
22#include "log.h"
23#include "memory.h"
819dc8bb 24#include "memory_vty.h"
2fb975da 25#include "command.h"
4f04a76b 26#include "libfrr.h"
2fb975da
TT
27
28#include "nhrpd.h"
29#include "netlink.h"
aed07011 30#include "nhrp_errors.h"
2fb975da 31
819dc8bb
DL
32DEFINE_MGROUP(NHRPD, "NHRP")
33
2fb975da
TT
34unsigned int debug_flags = 0;
35
36struct thread_master *master;
37struct timeval current_time;
2fb975da
TT
38
39/* nhrpd options. */
996c9314 40struct option longopts[] = {{0}};
2fb975da
TT
41
42/* nhrpd privileges */
996c9314
LB
43static zebra_capabilities_t _caps_p[] = {
44 ZCAP_NET_RAW, ZCAP_NET_ADMIN,
45 ZCAP_DAC_OVERRIDE, /* for now needed to write to
46 /proc/sys/net/ipv4/<if>/send_redirect */
2fb975da
TT
47};
48
26efbc7b 49struct zebra_privs_t nhrpd_privs = {
54b7b88b
HWC
50#if defined(FRR_USER) && defined(FRR_GROUP)
51 .user = FRR_USER,
52 .group = FRR_GROUP,
2fb975da
TT
53#endif
54#ifdef VTY_GROUP
55 .vty_group = VTY_GROUP,
56#endif
57 .caps_p = _caps_p,
58 .cap_num_p = ZEBRA_NUM_OF(_caps_p),
59};
60
4f04a76b 61static void parse_arguments(int argc, char **argv)
2fb975da
TT
62{
63 int opt;
64
65 while (1) {
4f04a76b 66 opt = frr_getopt(argc, argv, 0);
996c9314
LB
67 if (opt < 0)
68 break;
2fb975da
TT
69
70 switch (opt) {
71 case 0:
72 break;
2fb975da 73 default:
4f04a76b 74 frr_help_exit(1);
2fb975da
TT
75 break;
76 }
77 }
78}
79
80static void nhrp_sigusr1(void)
81{
dd8376fe 82 zlog_rotate();
2fb975da
TT
83}
84
85static void nhrp_request_stop(void)
86{
87 debugf(NHRP_DEBUG_COMMON, "Exiting...");
03951374 88 frr_early_fini();
2fb975da
TT
89
90 nhrp_shortcut_terminate();
91 nhrp_nhs_terminate();
92 nhrp_zebra_terminate();
93 vici_terminate();
94 evmgr_terminate();
95 nhrp_vc_terminate();
96 vrf_terminate();
2fb975da 97
2fb975da 98 debugf(NHRP_DEBUG_COMMON, "Done.");
03951374 99 frr_fini();
2fb975da
TT
100
101 exit(0);
102}
103
104static struct quagga_signal_t sighandlers[] = {
996c9314
LB
105 {
106 .signal = SIGUSR1,
107 .handler = &nhrp_sigusr1,
108 },
109 {
110 .signal = SIGINT,
111 .handler = &nhrp_request_stop,
112 },
113 {
114 .signal = SIGTERM,
115 .handler = &nhrp_request_stop,
116 },
2fb975da
TT
117};
118
8fcdd0d6 119static const struct frr_yang_module_info *nhrpd_yang_modules[] = {
a4bed468 120 &frr_interface_info,
8fcdd0d6
RW
121};
122
996c9314 123FRR_DAEMON_INFO(nhrpd, NHRP, .vty_port = NHRP_VTY_PORT,
4f04a76b 124
996c9314 125 .proghelp = "Implementation of the NHRP routing protocol.",
4f04a76b 126
996c9314 127 .signals = sighandlers, .n_signals = array_size(sighandlers),
4f04a76b 128
8fcdd0d6
RW
129 .privs = &nhrpd_privs, .yang_modules = nhrpd_yang_modules,
130 .n_yang_modules = array_size(nhrpd_yang_modules), )
4f04a76b 131
2fb975da
TT
132int main(int argc, char **argv)
133{
4f04a76b 134 frr_preinit(&nhrpd_di, argc, argv);
eb05883f 135 frr_opt_add("", longopts, "");
2fb975da 136
4f04a76b 137 parse_arguments(argc, argv);
2fb975da
TT
138
139 /* Library inits. */
4f04a76b 140 master = frr_init();
aed07011 141 nhrp_error_init();
ecbc5a37 142 vrf_init(NULL, NULL, NULL, NULL, NULL);
818c8515 143 nhrp_interface_init();
2fb975da
TT
144 resolver_init();
145
146 /* Run with elevated capabilities, as for all netlink activity
147 * we need privileges anyway. */
148 nhrpd_privs.change(ZPRIVS_RAISE);
149
150 netlink_init();
151 evmgr_init();
152 nhrp_vc_init();
153 nhrp_packet_init();
154 vici_init();
155 nhrp_zebra_init();
156 nhrp_shortcut_init();
157
158 nhrp_config_init();
159
eb05883f 160 frr_config_fork();
16077f2f 161 frr_run(master);
2fb975da
TT
162 return 0;
163}