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