]> git.proxmox.com Git - mirror_frr.git/blob - nhrpd/nhrp_main.c
Merge pull request #2848 from donaldsharp/more_init
[mirror_frr.git] / nhrpd / nhrp_main.c
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"
20 #include "memory_vty.h"
21 #include "command.h"
22 #include "libfrr.h"
23
24 #include "nhrpd.h"
25 #include "netlink.h"
26 #include "nhrp_errors.h"
27
28 DEFINE_MGROUP(NHRPD, "NHRP")
29
30 unsigned int debug_flags = 0;
31
32 struct thread_master *master;
33 struct timeval current_time;
34
35 /* nhrpd options. */
36 struct option longopts[] = {{0}};
37
38 /* nhrpd privileges */
39 static zebra_capabilities_t _caps_p[] = {
40 ZCAP_NET_RAW, ZCAP_NET_ADMIN,
41 ZCAP_DAC_OVERRIDE, /* for now needed to write to
42 /proc/sys/net/ipv4/<if>/send_redirect */
43 };
44
45 struct zebra_privs_t nhrpd_privs = {
46 #if defined(FRR_USER) && defined(FRR_GROUP)
47 .user = FRR_USER,
48 .group = FRR_GROUP,
49 #endif
50 #ifdef VTY_GROUP
51 .vty_group = VTY_GROUP,
52 #endif
53 .caps_p = _caps_p,
54 .cap_num_p = ZEBRA_NUM_OF(_caps_p),
55 };
56
57 static void parse_arguments(int argc, char **argv)
58 {
59 int opt;
60
61 while (1) {
62 opt = frr_getopt(argc, argv, 0);
63 if (opt < 0)
64 break;
65
66 switch (opt) {
67 case 0:
68 break;
69 default:
70 frr_help_exit(1);
71 break;
72 }
73 }
74 }
75
76 static void nhrp_sigusr1(void)
77 {
78 zlog_rotate();
79 }
80
81 static void nhrp_request_stop(void)
82 {
83 debugf(NHRP_DEBUG_COMMON, "Exiting...");
84 frr_early_fini();
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();
93
94 debugf(NHRP_DEBUG_COMMON, "Done.");
95 frr_fini();
96
97 exit(0);
98 }
99
100 static struct quagga_signal_t sighandlers[] = {
101 {
102 .signal = SIGUSR1,
103 .handler = &nhrp_sigusr1,
104 },
105 {
106 .signal = SIGINT,
107 .handler = &nhrp_request_stop,
108 },
109 {
110 .signal = SIGTERM,
111 .handler = &nhrp_request_stop,
112 },
113 };
114
115 FRR_DAEMON_INFO(nhrpd, NHRP, .vty_port = NHRP_VTY_PORT,
116
117 .proghelp = "Implementation of the NHRP routing protocol.",
118
119 .signals = sighandlers, .n_signals = array_size(sighandlers),
120
121 .privs = &nhrpd_privs, )
122
123 int main(int argc, char **argv)
124 {
125 frr_preinit(&nhrpd_di, argc, argv);
126 frr_opt_add("", longopts, "");
127
128 parse_arguments(argc, argv);
129
130 /* Library inits. */
131 master = frr_init();
132 nhrp_error_init();
133 vrf_init(NULL, NULL, NULL, NULL);
134 nhrp_interface_init();
135 resolver_init();
136
137 /* Run with elevated capabilities, as for all netlink activity
138 * we need privileges anyway. */
139 nhrpd_privs.change(ZPRIVS_RAISE);
140
141 netlink_init();
142 evmgr_init();
143 nhrp_vc_init();
144 nhrp_packet_init();
145 vici_init();
146 nhrp_zebra_init();
147 nhrp_shortcut_init();
148
149 nhrp_config_init();
150
151 frr_config_fork();
152 frr_run(master);
153 return 0;
154 }