]>
Commit | Line | Data |
---|---|---|
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" | |
09781197 | 21 | #include "lib/version.h" |
2fb975da TT |
22 | #include "log.h" |
23 | #include "memory.h" | |
24 | #include "command.h" | |
4f04a76b | 25 | #include "libfrr.h" |
fb7f5aa8 | 26 | #include "filter.h" |
2fb975da TT |
27 | |
28 | #include "nhrpd.h" | |
aed07011 | 29 | #include "nhrp_errors.h" |
2fb975da | 30 | |
bf8d3d6a | 31 | DEFINE_MGROUP(NHRPD, "NHRP"); |
819dc8bb | 32 | |
2fb975da TT |
33 | unsigned int debug_flags = 0; |
34 | ||
35 | struct thread_master *master; | |
36 | struct timeval current_time; | |
2fb975da TT |
37 | |
38 | /* nhrpd options. */ | |
996c9314 | 39 | struct option longopts[] = {{0}}; |
2fb975da TT |
40 | |
41 | /* nhrpd privileges */ | |
996c9314 LB |
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 */ | |
2fb975da TT |
46 | }; |
47 | ||
26efbc7b | 48 | struct zebra_privs_t nhrpd_privs = { |
54b7b88b HWC |
49 | #if defined(FRR_USER) && defined(FRR_GROUP) |
50 | .user = FRR_USER, | |
51 | .group = FRR_GROUP, | |
2fb975da TT |
52 | #endif |
53 | #ifdef VTY_GROUP | |
54 | .vty_group = VTY_GROUP, | |
55 | #endif | |
56 | .caps_p = _caps_p, | |
7e3a1ec7 | 57 | .cap_num_p = array_size(_caps_p), |
db52be55 | 58 | .cap_num_i = 0 |
2fb975da TT |
59 | }; |
60 | ||
db52be55 | 61 | |
4f04a76b | 62 | static void parse_arguments(int argc, char **argv) |
2fb975da TT |
63 | { |
64 | int opt; | |
65 | ||
66 | while (1) { | |
4f04a76b | 67 | opt = frr_getopt(argc, argv, 0); |
996c9314 LB |
68 | if (opt < 0) |
69 | break; | |
2fb975da TT |
70 | |
71 | switch (opt) { | |
72 | case 0: | |
73 | break; | |
2fb975da | 74 | default: |
4f04a76b | 75 | frr_help_exit(1); |
2fb975da TT |
76 | } |
77 | } | |
78 | } | |
79 | ||
80 | static void nhrp_sigusr1(void) | |
81 | { | |
dd8376fe | 82 | zlog_rotate(); |
2fb975da TT |
83 | } |
84 | ||
85 | static 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 | ||
7cc91e67 | 104 | static struct frr_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 | ||
0d8c7a26 | 119 | static const struct frr_yang_module_info *const nhrpd_yang_modules[] = { |
fb7f5aa8 | 120 | &frr_filter_info, |
a4bed468 | 121 | &frr_interface_info, |
f5eef2d5 | 122 | &frr_vrf_info, |
8fcdd0d6 RW |
123 | }; |
124 | ||
996c9314 | 125 | FRR_DAEMON_INFO(nhrpd, NHRP, .vty_port = NHRP_VTY_PORT, |
4f04a76b | 126 | |
996c9314 | 127 | .proghelp = "Implementation of the NHRP routing protocol.", |
4f04a76b | 128 | |
996c9314 | 129 | .signals = sighandlers, .n_signals = array_size(sighandlers), |
4f04a76b | 130 | |
8fcdd0d6 | 131 | .privs = &nhrpd_privs, .yang_modules = nhrpd_yang_modules, |
80413c20 DL |
132 | .n_yang_modules = array_size(nhrpd_yang_modules), |
133 | ); | |
4f04a76b | 134 | |
2fb975da TT |
135 | int main(int argc, char **argv) |
136 | { | |
4f04a76b | 137 | frr_preinit(&nhrpd_di, argc, argv); |
eb05883f | 138 | frr_opt_add("", longopts, ""); |
2fb975da | 139 | |
4f04a76b | 140 | parse_arguments(argc, argv); |
2fb975da TT |
141 | |
142 | /* Library inits. */ | |
4f04a76b | 143 | master = frr_init(); |
aed07011 | 144 | nhrp_error_init(); |
ac2cb9bf | 145 | vrf_init(NULL, NULL, NULL, NULL); |
818c8515 | 146 | nhrp_interface_init(); |
fe9e7b71 | 147 | resolver_init(master); |
2fb975da | 148 | |
8ca7a3ed DS |
149 | /* |
150 | * Run with elevated capabilities, as for all netlink activity | |
151 | * we need privileges anyway. | |
152 | * The assert is for clang SA code where it does | |
153 | * not see the change function being set in lib | |
154 | */ | |
155 | assert(nhrpd_privs.change); | |
2fb975da TT |
156 | nhrpd_privs.change(ZPRIVS_RAISE); |
157 | ||
2fb975da TT |
158 | evmgr_init(); |
159 | nhrp_vc_init(); | |
160 | nhrp_packet_init(); | |
161 | vici_init(); | |
138c5a74 DS |
162 | if_zapi_callbacks(nhrp_ifp_create, nhrp_ifp_up, |
163 | nhrp_ifp_down, nhrp_ifp_destroy); | |
2fb975da TT |
164 | nhrp_zebra_init(); |
165 | nhrp_shortcut_init(); | |
166 | ||
167 | nhrp_config_init(); | |
168 | ||
eb05883f | 169 | frr_config_fork(); |
16077f2f | 170 | frr_run(master); |
2fb975da TT |
171 | return 0; |
172 | } |