]> git.proxmox.com Git - mirror_frr.git/blame - nhrpd/nhrp_main.c
babeld: Make the zebra_privs_t available for use
[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. */
35struct option longopts[] = {
2fb975da
TT
36 { 0 }
37};
38
39/* nhrpd privileges */
40static zebra_capabilities_t _caps_p [] = {
41 ZCAP_NET_RAW,
42 ZCAP_NET_ADMIN,
43 ZCAP_DAC_OVERRIDE, /* for now needed to write to /proc/sys/net/ipv4/<if>/send_redirect */
44};
45
46static struct zebra_privs_t nhrpd_privs = {
54b7b88b
HWC
47#if defined(FRR_USER) && defined(FRR_GROUP)
48 .user = FRR_USER,
49 .group = FRR_GROUP,
2fb975da
TT
50#endif
51#ifdef VTY_GROUP
52 .vty_group = VTY_GROUP,
53#endif
54 .caps_p = _caps_p,
55 .cap_num_p = ZEBRA_NUM_OF(_caps_p),
56};
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);
2fb975da
TT
64 if(opt < 0) break;
65
66 switch (opt) {
67 case 0:
68 break;
2fb975da 69 default:
4f04a76b 70 frr_help_exit(1);
2fb975da
TT
71 break;
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
100static struct quagga_signal_t sighandlers[] = {
101 { .signal = SIGUSR1, .handler = &nhrp_sigusr1, },
102 { .signal = SIGINT, .handler = &nhrp_request_stop, },
103 { .signal = SIGTERM, .handler = &nhrp_request_stop, },
104};
105
4f04a76b
DL
106FRR_DAEMON_INFO(nhrpd, NHRP,
107 .vty_port = NHRP_VTY_PORT,
108
109 .proghelp = "Implementation of the NHRP routing protocol.",
110
111 .signals = sighandlers,
112 .n_signals = array_size(sighandlers),
113
114 .privs = &nhrpd_privs,
115)
116
2fb975da
TT
117int main(int argc, char **argv)
118{
4f04a76b 119 frr_preinit(&nhrpd_di, argc, argv);
eb05883f 120 frr_opt_add("", longopts, "");
2fb975da 121
4f04a76b 122 parse_arguments(argc, argv);
2fb975da
TT
123
124 /* Library inits. */
4f04a76b 125 master = frr_init();
6df85364 126 vrf_init(NULL, NULL, NULL, NULL);
818c8515 127 nhrp_interface_init();
2fb975da
TT
128 resolver_init();
129
130 /* Run with elevated capabilities, as for all netlink activity
131 * we need privileges anyway. */
132 nhrpd_privs.change(ZPRIVS_RAISE);
133
134 netlink_init();
135 evmgr_init();
136 nhrp_vc_init();
137 nhrp_packet_init();
138 vici_init();
139 nhrp_zebra_init();
140 nhrp_shortcut_init();
141
142 nhrp_config_init();
143
eb05883f 144 frr_config_fork();
16077f2f 145 frr_run(master);
2fb975da
TT
146 return 0;
147}