]> git.proxmox.com Git - mirror_frr.git/blame - nhrpd/nhrp_main.c
Merge pull request #2726 from sworleys/Netlink-Filter-AFI
[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
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 "version.h"
18#include "log.h"
19#include "memory.h"
819dc8bb 20#include "memory_vty.h"
2fb975da 21#include "command.h"
4f04a76b 22#include "libfrr.h"
2fb975da
TT
23
24#include "nhrpd.h"
25#include "netlink.h"
26
819dc8bb
DL
27DEFINE_MGROUP(NHRPD, "NHRP")
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,
53 .cap_num_p = ZEBRA_NUM_OF(_caps_p),
54};
55
4f04a76b 56static void parse_arguments(int argc, char **argv)
2fb975da
TT
57{
58 int opt;
59
60 while (1) {
4f04a76b 61 opt = frr_getopt(argc, argv, 0);
996c9314
LB
62 if (opt < 0)
63 break;
2fb975da
TT
64
65 switch (opt) {
66 case 0:
67 break;
2fb975da 68 default:
4f04a76b 69 frr_help_exit(1);
2fb975da
TT
70 break;
71 }
72 }
73}
74
75static void nhrp_sigusr1(void)
76{
dd8376fe 77 zlog_rotate();
2fb975da
TT
78}
79
80static void nhrp_request_stop(void)
81{
82 debugf(NHRP_DEBUG_COMMON, "Exiting...");
03951374 83 frr_early_fini();
2fb975da
TT
84
85 nhrp_shortcut_terminate();
86 nhrp_nhs_terminate();
87 nhrp_zebra_terminate();
88 vici_terminate();
89 evmgr_terminate();
90 nhrp_vc_terminate();
91 vrf_terminate();
2fb975da 92
2fb975da 93 debugf(NHRP_DEBUG_COMMON, "Done.");
03951374 94 frr_fini();
2fb975da
TT
95
96 exit(0);
97}
98
99static struct quagga_signal_t sighandlers[] = {
996c9314
LB
100 {
101 .signal = SIGUSR1,
102 .handler = &nhrp_sigusr1,
103 },
104 {
105 .signal = SIGINT,
106 .handler = &nhrp_request_stop,
107 },
108 {
109 .signal = SIGTERM,
110 .handler = &nhrp_request_stop,
111 },
2fb975da
TT
112};
113
996c9314 114FRR_DAEMON_INFO(nhrpd, NHRP, .vty_port = NHRP_VTY_PORT,
4f04a76b 115
996c9314 116 .proghelp = "Implementation of the NHRP routing protocol.",
4f04a76b 117
996c9314 118 .signals = sighandlers, .n_signals = array_size(sighandlers),
4f04a76b 119
996c9314 120 .privs = &nhrpd_privs, )
4f04a76b 121
2fb975da
TT
122int main(int argc, char **argv)
123{
4f04a76b 124 frr_preinit(&nhrpd_di, argc, argv);
eb05883f 125 frr_opt_add("", longopts, "");
2fb975da 126
4f04a76b 127 parse_arguments(argc, argv);
2fb975da
TT
128
129 /* Library inits. */
4f04a76b 130 master = frr_init();
6df85364 131 vrf_init(NULL, NULL, NULL, NULL);
818c8515 132 nhrp_interface_init();
2fb975da
TT
133 resolver_init();
134
135 /* Run with elevated capabilities, as for all netlink activity
136 * we need privileges anyway. */
137 nhrpd_privs.change(ZPRIVS_RAISE);
138
139 netlink_init();
140 evmgr_init();
141 nhrp_vc_init();
142 nhrp_packet_init();
143 vici_init();
144 nhrp_zebra_init();
145 nhrp_shortcut_init();
146
147 nhrp_config_init();
148
eb05883f 149 frr_config_fork();
16077f2f 150 frr_run(master);
2fb975da
TT
151 return 0;
152}