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