]> git.proxmox.com Git - mirror_frr.git/blob - nhrpd/nhrp_main.c
Merge pull request #5669 from donaldsharp/nhg_ip
[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 #ifdef HAVE_CONFIG_H
11 #include "config.h"
12 #endif
13
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"
24 #include "command.h"
25 #include "libfrr.h"
26
27 #include "nhrpd.h"
28 #include "netlink.h"
29 #include "nhrp_errors.h"
30
31 DEFINE_MGROUP(NHRPD, "NHRP")
32
33 unsigned int debug_flags = 0;
34
35 struct thread_master *master;
36 struct timeval current_time;
37
38 /* nhrpd options. */
39 struct option longopts[] = {{0}};
40
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 */
46 };
47
48 struct zebra_privs_t nhrpd_privs = {
49 #if defined(FRR_USER) && defined(FRR_GROUP)
50 .user = FRR_USER,
51 .group = FRR_GROUP,
52 #endif
53 #ifdef VTY_GROUP
54 .vty_group = VTY_GROUP,
55 #endif
56 .caps_p = _caps_p,
57 .cap_num_p = array_size(_caps_p),
58 };
59
60 static void parse_arguments(int argc, char **argv)
61 {
62 int opt;
63
64 while (1) {
65 opt = frr_getopt(argc, argv, 0);
66 if (opt < 0)
67 break;
68
69 switch (opt) {
70 case 0:
71 break;
72 default:
73 frr_help_exit(1);
74 break;
75 }
76 }
77 }
78
79 static void nhrp_sigusr1(void)
80 {
81 zlog_rotate();
82 }
83
84 static void nhrp_request_stop(void)
85 {
86 debugf(NHRP_DEBUG_COMMON, "Exiting...");
87 frr_early_fini();
88
89 nhrp_shortcut_terminate();
90 nhrp_nhs_terminate();
91 nhrp_zebra_terminate();
92 vici_terminate();
93 evmgr_terminate();
94 nhrp_vc_terminate();
95 vrf_terminate();
96
97 debugf(NHRP_DEBUG_COMMON, "Done.");
98 frr_fini();
99
100 exit(0);
101 }
102
103 static struct quagga_signal_t sighandlers[] = {
104 {
105 .signal = SIGUSR1,
106 .handler = &nhrp_sigusr1,
107 },
108 {
109 .signal = SIGINT,
110 .handler = &nhrp_request_stop,
111 },
112 {
113 .signal = SIGTERM,
114 .handler = &nhrp_request_stop,
115 },
116 };
117
118 static const struct frr_yang_module_info *const nhrpd_yang_modules[] = {
119 &frr_interface_info,
120 };
121
122 FRR_DAEMON_INFO(nhrpd, NHRP, .vty_port = NHRP_VTY_PORT,
123
124 .proghelp = "Implementation of the NHRP routing protocol.",
125
126 .signals = sighandlers, .n_signals = array_size(sighandlers),
127
128 .privs = &nhrpd_privs, .yang_modules = nhrpd_yang_modules,
129 .n_yang_modules = array_size(nhrpd_yang_modules), )
130
131 int main(int argc, char **argv)
132 {
133 frr_preinit(&nhrpd_di, argc, argv);
134 frr_opt_add("", longopts, "");
135
136 parse_arguments(argc, argv);
137
138 /* Library inits. */
139 master = frr_init();
140 nhrp_error_init();
141 vrf_init(NULL, NULL, NULL, NULL, NULL);
142 nhrp_interface_init();
143 resolver_init(master);
144
145 /* Run with elevated capabilities, as for all netlink activity
146 * we need privileges anyway. */
147 nhrpd_privs.change(ZPRIVS_RAISE);
148
149 netlink_init();
150 evmgr_init();
151 nhrp_vc_init();
152 nhrp_packet_init();
153 vici_init();
154 if_zapi_callbacks(nhrp_ifp_create, nhrp_ifp_up,
155 nhrp_ifp_down, nhrp_ifp_destroy);
156 nhrp_zebra_init();
157 nhrp_shortcut_init();
158
159 nhrp_config_init();
160
161 frr_config_fork();
162 frr_run(master);
163 return 0;
164 }