]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* RIPd main routine. |
2 | * Copyright (C) 1997, 98 Kunihiro Ishiguro <kunihiro@zebra.org> | |
3 | * | |
4 | * This file is part of GNU Zebra. | |
5 | * | |
6 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the | |
8 | * Free Software Foundation; either version 2, or (at your option) any | |
9 | * later version. | |
10 | * | |
11 | * GNU Zebra is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
896014f4 DL |
16 | * You should have received a copy of the GNU General Public License along |
17 | * with this program; see the file COPYING; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
718e3744 | 19 | */ |
20 | ||
21 | #include <zebra.h> | |
22 | ||
5e4fa164 | 23 | #include <lib/version.h> |
718e3744 | 24 | #include "getopt.h" |
25 | #include "thread.h" | |
26 | #include "command.h" | |
27 | #include "memory.h" | |
fc7948fa | 28 | #include "memory_vty.h" |
718e3744 | 29 | #include "prefix.h" |
30 | #include "filter.h" | |
31 | #include "keychain.h" | |
32 | #include "log.h" | |
edd7c245 | 33 | #include "privs.h" |
2d75d052 | 34 | #include "sigevent.h" |
b5114685 | 35 | #include "zclient.h" |
6a69b354 | 36 | #include "vrf.h" |
4f04a76b | 37 | #include "libfrr.h" |
718e3744 | 38 | |
39 | #include "ripd/ripd.h" | |
40 | ||
41 | /* ripd options. */ | |
d62a17ae | 42 | static struct option longopts[] = {{"retain", no_argument, NULL, 'r'}, {0}}; |
718e3744 | 43 | |
edd7c245 | 44 | /* ripd privileges */ |
d62a17ae | 45 | zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND}; |
edd7c245 | 46 | |
d62a17ae | 47 | struct zebra_privs_t ripd_privs = { |
b2f36157 | 48 | #if defined(FRR_USER) |
d62a17ae | 49 | .user = FRR_USER, |
edd7c245 | 50 | #endif |
b2f36157 | 51 | #if defined FRR_GROUP |
d62a17ae | 52 | .group = FRR_GROUP, |
d81fadfd | 53 | #endif |
54 | #ifdef VTY_GROUP | |
d62a17ae | 55 | .vty_group = VTY_GROUP, |
edd7c245 | 56 | #endif |
d62a17ae | 57 | .caps_p = _caps_p, |
58 | .cap_num_p = 2, | |
59 | .cap_num_i = 0}; | |
edd7c245 | 60 | |
718e3744 | 61 | /* Route retain mode flag. */ |
62 | int retain_mode = 0; | |
63 | ||
718e3744 | 64 | /* Master of threads. */ |
65 | struct thread_master *master; | |
66 | ||
eb05883f | 67 | static struct frr_daemon_info ripd_di; |
718e3744 | 68 | |
718e3744 | 69 | /* SIGHUP handler. */ |
d62a17ae | 70 | static void sighup(void) |
718e3744 | 71 | { |
d62a17ae | 72 | zlog_info("SIGHUP received"); |
73 | rip_clean(); | |
74 | rip_reset(); | |
75 | zlog_info("ripd restarting!"); | |
718e3744 | 76 | |
d62a17ae | 77 | /* Reload config file. */ |
78 | vty_read_config(ripd_di.config_file, config_default); | |
718e3744 | 79 | |
d62a17ae | 80 | /* Try to return to normal operation. */ |
718e3744 | 81 | } |
82 | ||
83 | /* SIGINT handler. */ | |
d62a17ae | 84 | static void sigint(void) |
718e3744 | 85 | { |
d62a17ae | 86 | zlog_notice("Terminating on signal"); |
718e3744 | 87 | |
d62a17ae | 88 | if (!retain_mode) |
89 | rip_clean(); | |
718e3744 | 90 | |
d62a17ae | 91 | rip_zclient_stop(); |
a2f9eb82 | 92 | |
d62a17ae | 93 | exit(0); |
718e3744 | 94 | } |
95 | ||
96 | /* SIGUSR1 handler. */ | |
d62a17ae | 97 | static void sigusr1(void) |
718e3744 | 98 | { |
d62a17ae | 99 | zlog_rotate(); |
718e3744 | 100 | } |
101 | ||
d62a17ae | 102 | static struct quagga_signal_t ripd_signals[] = { |
103 | { | |
104 | .signal = SIGHUP, | |
105 | .handler = &sighup, | |
106 | }, | |
107 | { | |
108 | .signal = SIGUSR1, | |
109 | .handler = &sigusr1, | |
110 | }, | |
111 | { | |
112 | .signal = SIGINT, | |
113 | .handler = &sigint, | |
114 | }, | |
115 | { | |
116 | .signal = SIGTERM, | |
117 | .handler = &sigint, | |
118 | }, | |
119 | }; | |
4f04a76b | 120 | |
d62a17ae | 121 | FRR_DAEMON_INFO(ripd, RIP, .vty_port = RIP_VTY_PORT, |
718e3744 | 122 | |
d62a17ae | 123 | .proghelp = "Implementation of the RIP routing protocol.", |
718e3744 | 124 | |
d62a17ae | 125 | .signals = ripd_signals, .n_signals = array_size(ripd_signals), |
718e3744 | 126 | |
d62a17ae | 127 | .privs = &ripd_privs, ) |
128 | ||
129 | /* Main routine of ripd. */ | |
130 | int main(int argc, char **argv) | |
131 | { | |
132 | frr_preinit(&ripd_di, argc, argv); | |
133 | frr_opt_add( | |
134 | "r", longopts, | |
135 | " -r, --retain When program terminates, retain added route by ripd.\n"); | |
136 | ||
137 | /* Command line option parse. */ | |
138 | while (1) { | |
139 | int opt; | |
140 | ||
141 | opt = frr_getopt(argc, argv, NULL); | |
142 | ||
143 | if (opt == EOF) | |
144 | break; | |
145 | ||
146 | switch (opt) { | |
147 | case 0: | |
148 | break; | |
149 | case 'r': | |
150 | retain_mode = 1; | |
151 | break; | |
152 | default: | |
153 | frr_help_exit(1); | |
154 | break; | |
155 | } | |
718e3744 | 156 | } |
718e3744 | 157 | |
d62a17ae | 158 | /* Prepare master thread. */ |
159 | master = frr_init(); | |
718e3744 | 160 | |
d62a17ae | 161 | /* Library initialization. */ |
162 | keychain_init(); | |
163 | vrf_init(NULL, NULL, NULL, NULL); | |
718e3744 | 164 | |
d62a17ae | 165 | /* RIP related initialization. */ |
166 | rip_init(); | |
167 | rip_if_init(); | |
168 | rip_zclient_init(master); | |
169 | rip_peer_init(); | |
718e3744 | 170 | |
d62a17ae | 171 | frr_config_fork(); |
172 | frr_run(master); | |
718e3744 | 173 | |
d62a17ae | 174 | /* Not reached. */ |
175 | return (0); | |
718e3744 | 176 | } |