]>
Commit | Line | Data |
---|---|---|
7f57883e DS |
1 | /* |
2 | * EIGRP Daemon Program. | |
3 | * Copyright (C) 2013-2014 | |
4 | * Authors: | |
5 | * Donnie Savage | |
6 | * Jan Janovic | |
7 | * Matej Perina | |
8 | * Peter Orsag | |
9 | * Peter Paluch | |
10 | * | |
11 | * This file is part of GNU Zebra. | |
12 | * | |
13 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
14 | * under the terms of the GNU General Public License as published by the | |
15 | * Free Software Foundation; either version 2, or (at your option) any | |
16 | * later version. | |
17 | * | |
18 | * GNU Zebra is distributed in the hope that it will be useful, but | |
19 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
21 | * General Public License for more details. | |
22 | * | |
896014f4 DL |
23 | * You should have received a copy of the GNU General Public License along |
24 | * with this program; see the file COPYING; if not, write to the Free Software | |
25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
7f57883e DS |
26 | */ |
27 | ||
28 | #include <zebra.h> | |
29 | ||
30 | #include "thread.h" | |
31 | #include "vty.h" | |
32 | #include "command.h" | |
33 | #include "linklist.h" | |
34 | #include "prefix.h" | |
35 | #include "table.h" | |
36 | #include "if.h" | |
37 | #include "memory.h" | |
38 | #include "stream.h" | |
39 | #include "log.h" | |
d62a17ae | 40 | #include "sockunion.h" /* for inet_aton () */ |
7f57883e DS |
41 | #include "zclient.h" |
42 | #include "plist.h" | |
43 | #include "sockopt.h" | |
44 | #include "keychain.h" | |
8879bd22 | 45 | #include "libfrr.h" |
8b0a80f1 | 46 | #include "lib_errors.h" |
03a38493 | 47 | #include "distribute.h" |
7f57883e DS |
48 | |
49 | #include "eigrpd/eigrp_structs.h" | |
50 | #include "eigrpd/eigrpd.h" | |
51 | #include "eigrpd/eigrp_interface.h" | |
52 | #include "eigrpd/eigrp_zebra.h" | |
53 | #include "eigrpd/eigrp_vty.h" | |
54 | #include "eigrpd/eigrp_neighbor.h" | |
55 | #include "eigrpd/eigrp_packet.h" | |
56 | #include "eigrpd/eigrp_network.h" | |
57 | #include "eigrpd/eigrp_topology.h" | |
58 | #include "eigrpd/eigrp_memory.h" | |
03a38493 | 59 | #include "eigrpd/eigrp_filter.h" |
7f57883e | 60 | |
96244aca | 61 | DEFINE_QOBJ_TYPE(eigrp); |
7f57883e DS |
62 | |
63 | static struct eigrp_master eigrp_master; | |
64 | ||
65 | struct eigrp_master *eigrp_om; | |
66 | ||
7f57883e DS |
67 | extern struct zclient *zclient; |
68 | extern struct in_addr router_id_zebra; | |
69 | ||
70 | ||
71 | /* | |
72 | * void eigrp_router_id_update(struct eigrp *eigrp) | |
73 | * | |
74 | * Description: | |
75 | * update routerid associated with this instance of EIGRP. | |
76 | * If the id changes, then call if_update for each interface | |
77 | * to resync the topology database with all neighbors | |
78 | * | |
79 | * Select the router ID based on these priorities: | |
80 | * 1. Statically assigned router ID is always the first choice. | |
81 | * 2. If there is no statically assigned router ID, then try to stick | |
82 | * with the most recent value, since changing router ID's is very | |
83 | * disruptive. | |
84 | * 3. Last choice: just go with whatever the zebra daemon recommends. | |
85 | * | |
86 | * Note: | |
87 | * router id for EIGRP is really just a 32 bit number. Cisco historically | |
88 | * displays it in dotted decimal notation, and will pickup an IP address | |
89 | * from an interface so it can be 'auto-configed" to a uniqe value | |
90 | * | |
91 | * This does not work for IPv6, and to make the code simpler, its | |
92 | * stored and processed internerall as a 32bit number | |
93 | */ | |
d62a17ae | 94 | void eigrp_router_id_update(struct eigrp *eigrp) |
7f57883e | 95 | { |
daa64bdf | 96 | struct vrf *vrf = vrf_lookup_by_id(eigrp->vrf_id); |
d62a17ae | 97 | struct interface *ifp; |
900e2d42 | 98 | struct in_addr router_id, router_id_old; |
7f57883e | 99 | |
d62a17ae | 100 | router_id_old = eigrp->router_id; |
7f57883e | 101 | |
975a328e | 102 | if (eigrp->router_id_static.s_addr != INADDR_ANY) |
d62a17ae | 103 | router_id = eigrp->router_id_static; |
7f57883e | 104 | |
975a328e | 105 | else if (eigrp->router_id.s_addr != INADDR_ANY) |
d62a17ae | 106 | router_id = eigrp->router_id; |
7f57883e | 107 | |
d62a17ae | 108 | else |
900e2d42 | 109 | router_id = router_id_zebra; |
7f57883e | 110 | |
d62a17ae | 111 | eigrp->router_id = router_id; |
900e2d42 | 112 | if (router_id_old.s_addr != router_id.s_addr) { |
d62a17ae | 113 | /* update eigrp_interface's */ |
451fda4f | 114 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 115 | eigrp_if_update(ifp); |
116 | } | |
7f57883e DS |
117 | } |
118 | ||
4d762f26 | 119 | void eigrp_master_init(void) |
7f57883e | 120 | { |
d62a17ae | 121 | struct timeval tv; |
7f57883e | 122 | |
d62a17ae | 123 | memset(&eigrp_master, 0, sizeof(struct eigrp_master)); |
7f57883e | 124 | |
d62a17ae | 125 | eigrp_om = &eigrp_master; |
126 | eigrp_om->eigrp = list_new(); | |
7f57883e | 127 | |
d62a17ae | 128 | monotime(&tv); |
129 | eigrp_om->start_time = tv.tv_sec; | |
7f57883e DS |
130 | } |
131 | ||
7f57883e | 132 | /* Allocate new eigrp structure. */ |
e9449961 | 133 | static struct eigrp *eigrp_new(uint16_t as, vrf_id_t vrf_id) |
7f57883e | 134 | { |
d62a17ae | 135 | struct eigrp *eigrp = XCALLOC(MTYPE_EIGRP_TOP, sizeof(struct eigrp)); |
d62a17ae | 136 | |
137 | /* init information relevant to peers */ | |
c371cd6b | 138 | eigrp->vrf_id = vrf_id; |
d62a17ae | 139 | eigrp->vrid = 0; |
e9449961 | 140 | eigrp->AS = as; |
975a328e DA |
141 | eigrp->router_id.s_addr = INADDR_ANY; |
142 | eigrp->router_id_static.s_addr = INADDR_ANY; | |
d62a17ae | 143 | eigrp->sequence_number = 1; |
144 | ||
145 | /*Configure default K Values for EIGRP Process*/ | |
146 | eigrp->k_values[0] = EIGRP_K1_DEFAULT; | |
147 | eigrp->k_values[1] = EIGRP_K2_DEFAULT; | |
148 | eigrp->k_values[2] = EIGRP_K3_DEFAULT; | |
149 | eigrp->k_values[3] = EIGRP_K4_DEFAULT; | |
150 | eigrp->k_values[4] = EIGRP_K5_DEFAULT; | |
151 | eigrp->k_values[5] = EIGRP_K6_DEFAULT; | |
152 | ||
153 | /* init internal data structures */ | |
154 | eigrp->eiflist = list_new(); | |
155 | eigrp->passive_interface_default = EIGRP_IF_ACTIVE; | |
9ca66cc7 | 156 | eigrp->networks = eigrp_topology_new(); |
d62a17ae | 157 | |
128ed760 DS |
158 | eigrp->fd = eigrp_sock_init(vrf_lookup_by_id(vrf_id)); |
159 | ||
160 | if (eigrp->fd < 0) { | |
09c866e3 | 161 | flog_err_sys( |
450971aa | 162 | EC_LIB_SOCKET, |
09c866e3 | 163 | "eigrp_new: fatal error: eigrp_sock_init was unable to open a socket"); |
d62a17ae | 164 | exit(1); |
165 | } | |
166 | ||
d62a17ae | 167 | eigrp->maxsndbuflen = getsockopt_so_sendbuf(eigrp->fd); |
168 | ||
6ae7ed45 | 169 | eigrp->ibuf = stream_new(EIGRP_PACKET_MAX_LEN + 1); |
d62a17ae | 170 | |
171 | eigrp->t_read = NULL; | |
172 | thread_add_read(master, eigrp_read, eigrp, eigrp->fd, &eigrp->t_read); | |
173 | eigrp->oi_write_q = list_new(); | |
174 | ||
9ca66cc7 | 175 | eigrp->topology_table = route_table_init(); |
d62a17ae | 176 | |
177 | eigrp->neighbor_self = eigrp_nbr_new(NULL); | |
178 | eigrp->neighbor_self->src.s_addr = INADDR_ANY; | |
179 | ||
180 | eigrp->variance = EIGRP_VARIANCE_DEFAULT; | |
181 | eigrp->max_paths = EIGRP_MAX_PATHS_DEFAULT; | |
182 | ||
183 | eigrp->serno = 0; | |
184 | eigrp->serno_last_update = 0; | |
185 | eigrp->topology_changes_externalIPV4 = list_new(); | |
186 | eigrp->topology_changes_internalIPV4 = list_new(); | |
187 | ||
188 | eigrp->list[EIGRP_FILTER_IN] = NULL; | |
189 | eigrp->list[EIGRP_FILTER_OUT] = NULL; | |
190 | ||
191 | eigrp->prefix[EIGRP_FILTER_IN] = NULL; | |
192 | eigrp->prefix[EIGRP_FILTER_OUT] = NULL; | |
193 | ||
194 | eigrp->routemap[EIGRP_FILTER_IN] = NULL; | |
195 | eigrp->routemap[EIGRP_FILTER_OUT] = NULL; | |
196 | ||
03a38493 | 197 | /* Distribute list install. */ |
daa64bdf DS |
198 | eigrp->distribute_ctx = |
199 | distribute_list_ctx_create(vrf_lookup_by_id(eigrp->vrf_id)); | |
03a38493 PG |
200 | distribute_list_add_hook(eigrp->distribute_ctx, |
201 | eigrp_distribute_update); | |
202 | distribute_list_delete_hook(eigrp->distribute_ctx, | |
203 | eigrp_distribute_update); | |
4b23867c PG |
204 | |
205 | /* | |
daa64bdf | 206 | eigrp->if_rmap_ctx = if_rmap_ctx_create(eigrp->vrf_id); |
4b23867c PG |
207 | if_rmap_hook_add (eigrp_if_rmap_update); |
208 | if_rmap_hook_delete (eigrp_if_rmap_update); | |
209 | */ | |
d62a17ae | 210 | QOBJ_REG(eigrp, eigrp); |
211 | return eigrp; | |
7f57883e DS |
212 | } |
213 | ||
e9449961 | 214 | struct eigrp *eigrp_get(uint16_t as, vrf_id_t vrf_id) |
7f57883e | 215 | { |
d62a17ae | 216 | struct eigrp *eigrp; |
7f57883e | 217 | |
e9449961 | 218 | eigrp = eigrp_lookup(vrf_id); |
d62a17ae | 219 | if (eigrp == NULL) { |
e9449961 | 220 | eigrp = eigrp_new(as, vrf_id); |
7eee7ef6 | 221 | listnode_add(eigrp_om->eigrp, eigrp); |
d62a17ae | 222 | } |
7f57883e | 223 | |
d62a17ae | 224 | return eigrp; |
7f57883e DS |
225 | } |
226 | ||
227 | /* Shut down the entire process */ | |
d62a17ae | 228 | void eigrp_terminate(void) |
7f57883e | 229 | { |
d62a17ae | 230 | struct eigrp *eigrp; |
231 | struct listnode *node, *nnode; | |
7f57883e | 232 | |
d62a17ae | 233 | /* shutdown already in progress */ |
234 | if (CHECK_FLAG(eigrp_om->options, EIGRP_MASTER_SHUTDOWN)) | |
235 | return; | |
7f57883e | 236 | |
d62a17ae | 237 | SET_FLAG(eigrp_om->options, EIGRP_MASTER_SHUTDOWN); |
7f57883e | 238 | |
d62a17ae | 239 | for (ALL_LIST_ELEMENTS(eigrp_om->eigrp, node, nnode, eigrp)) |
240 | eigrp_finish(eigrp); | |
8879bd22 RW |
241 | |
242 | frr_fini(); | |
7f57883e DS |
243 | } |
244 | ||
d62a17ae | 245 | void eigrp_finish(struct eigrp *eigrp) |
7f57883e | 246 | { |
d62a17ae | 247 | eigrp_finish_final(eigrp); |
248 | ||
249 | /* eigrp being shut-down? If so, was this the last eigrp instance? */ | |
250 | if (CHECK_FLAG(eigrp_om->options, EIGRP_MASTER_SHUTDOWN) | |
251 | && (listcount(eigrp_om->eigrp) == 0)) { | |
252 | if (zclient) { | |
253 | zclient_stop(zclient); | |
254 | zclient_free(zclient); | |
255 | } | |
256 | exit(0); | |
edaf6c01 | 257 | } |
7f57883e | 258 | |
d62a17ae | 259 | return; |
7f57883e DS |
260 | } |
261 | ||
262 | /* Final cleanup of eigrp instance */ | |
d62a17ae | 263 | void eigrp_finish_final(struct eigrp *eigrp) |
7f57883e | 264 | { |
d62a17ae | 265 | struct eigrp_interface *ei; |
266 | struct eigrp_neighbor *nbr; | |
267 | struct listnode *node, *nnode, *node2, *nnode2; | |
268 | ||
269 | for (ALL_LIST_ELEMENTS(eigrp->eiflist, node, nnode, ei)) { | |
270 | for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) | |
271 | eigrp_nbr_delete(nbr); | |
272 | eigrp_if_free(ei, INTERFACE_DOWN_BY_FINAL); | |
273 | } | |
7f57883e | 274 | |
d62a17ae | 275 | THREAD_OFF(eigrp->t_write); |
276 | THREAD_OFF(eigrp->t_read); | |
277 | close(eigrp->fd); | |
7f57883e | 278 | |
6a154c88 DL |
279 | list_delete(&eigrp->eiflist); |
280 | list_delete(&eigrp->oi_write_q); | |
7f57883e | 281 | |
0da93ecf | 282 | eigrp_topology_free(eigrp, eigrp->topology_table); |
7f57883e | 283 | |
d62a17ae | 284 | eigrp_nbr_delete(eigrp->neighbor_self); |
7f57883e | 285 | |
6a154c88 DL |
286 | list_delete(&eigrp->topology_changes_externalIPV4); |
287 | list_delete(&eigrp->topology_changes_internalIPV4); | |
052fe054 | 288 | |
7eee7ef6 | 289 | listnode_delete(eigrp_om->eigrp, eigrp); |
7f57883e | 290 | |
7eee7ef6 | 291 | stream_free(eigrp->ibuf); |
03a38493 | 292 | distribute_list_delete(&eigrp->distribute_ctx); |
d62a17ae | 293 | XFREE(MTYPE_EIGRP_TOP, eigrp); |
7f57883e DS |
294 | } |
295 | ||
296 | /*Look for existing eigrp process*/ | |
e9449961 | 297 | struct eigrp *eigrp_lookup(vrf_id_t vrf_id) |
7f57883e | 298 | { |
e9449961 DS |
299 | struct eigrp *eigrp; |
300 | struct listnode *node, *nnode; | |
301 | ||
302 | for (ALL_LIST_ELEMENTS(eigrp_om->eigrp, node, nnode, eigrp)) | |
303 | if (eigrp->vrf_id == vrf_id) | |
304 | return eigrp; | |
7f57883e | 305 | |
e9449961 | 306 | return NULL; |
7f57883e | 307 | } |