]>
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" | |
03a38493 | 58 | #include "eigrpd/eigrp_filter.h" |
7f57883e | 59 | |
b4216e2c DL |
60 | DEFINE_MGROUP(EIGRPD, "eigrpd"); |
61 | ||
62 | DEFINE_MTYPE_STATIC(EIGRPD, EIGRP_TOP, "EIGRP structure"); | |
63 | ||
96244aca | 64 | DEFINE_QOBJ_TYPE(eigrp); |
7f57883e DS |
65 | |
66 | static struct eigrp_master eigrp_master; | |
67 | ||
68 | struct eigrp_master *eigrp_om; | |
69 | ||
7f57883e DS |
70 | extern struct zclient *zclient; |
71 | extern struct in_addr router_id_zebra; | |
72 | ||
73 | ||
74 | /* | |
75 | * void eigrp_router_id_update(struct eigrp *eigrp) | |
76 | * | |
77 | * Description: | |
78 | * update routerid associated with this instance of EIGRP. | |
79 | * If the id changes, then call if_update for each interface | |
80 | * to resync the topology database with all neighbors | |
81 | * | |
82 | * Select the router ID based on these priorities: | |
83 | * 1. Statically assigned router ID is always the first choice. | |
84 | * 2. If there is no statically assigned router ID, then try to stick | |
85 | * with the most recent value, since changing router ID's is very | |
86 | * disruptive. | |
87 | * 3. Last choice: just go with whatever the zebra daemon recommends. | |
88 | * | |
89 | * Note: | |
90 | * router id for EIGRP is really just a 32 bit number. Cisco historically | |
91 | * displays it in dotted decimal notation, and will pickup an IP address | |
92 | * from an interface so it can be 'auto-configed" to a uniqe value | |
93 | * | |
94 | * This does not work for IPv6, and to make the code simpler, its | |
95 | * stored and processed internerall as a 32bit number | |
96 | */ | |
d62a17ae | 97 | void eigrp_router_id_update(struct eigrp *eigrp) |
7f57883e | 98 | { |
daa64bdf | 99 | struct vrf *vrf = vrf_lookup_by_id(eigrp->vrf_id); |
d62a17ae | 100 | struct interface *ifp; |
900e2d42 | 101 | struct in_addr router_id, router_id_old; |
7f57883e | 102 | |
d62a17ae | 103 | router_id_old = eigrp->router_id; |
7f57883e | 104 | |
975a328e | 105 | if (eigrp->router_id_static.s_addr != INADDR_ANY) |
d62a17ae | 106 | router_id = eigrp->router_id_static; |
7f57883e | 107 | |
975a328e | 108 | else if (eigrp->router_id.s_addr != INADDR_ANY) |
d62a17ae | 109 | router_id = eigrp->router_id; |
7f57883e | 110 | |
d62a17ae | 111 | else |
900e2d42 | 112 | router_id = router_id_zebra; |
7f57883e | 113 | |
d62a17ae | 114 | eigrp->router_id = router_id; |
900e2d42 | 115 | if (router_id_old.s_addr != router_id.s_addr) { |
d62a17ae | 116 | /* update eigrp_interface's */ |
451fda4f | 117 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 118 | eigrp_if_update(ifp); |
119 | } | |
7f57883e DS |
120 | } |
121 | ||
4d762f26 | 122 | void eigrp_master_init(void) |
7f57883e | 123 | { |
d62a17ae | 124 | struct timeval tv; |
7f57883e | 125 | |
6006b807 | 126 | memset(&eigrp_master, 0, sizeof(eigrp_master)); |
7f57883e | 127 | |
d62a17ae | 128 | eigrp_om = &eigrp_master; |
129 | eigrp_om->eigrp = list_new(); | |
7f57883e | 130 | |
d62a17ae | 131 | monotime(&tv); |
132 | eigrp_om->start_time = tv.tv_sec; | |
7f57883e DS |
133 | } |
134 | ||
7f57883e | 135 | /* Allocate new eigrp structure. */ |
e9449961 | 136 | static struct eigrp *eigrp_new(uint16_t as, vrf_id_t vrf_id) |
7f57883e | 137 | { |
d62a17ae | 138 | struct eigrp *eigrp = XCALLOC(MTYPE_EIGRP_TOP, sizeof(struct eigrp)); |
d62a17ae | 139 | |
140 | /* init information relevant to peers */ | |
c371cd6b | 141 | eigrp->vrf_id = vrf_id; |
d62a17ae | 142 | eigrp->vrid = 0; |
e9449961 | 143 | eigrp->AS = as; |
975a328e DA |
144 | eigrp->router_id.s_addr = INADDR_ANY; |
145 | eigrp->router_id_static.s_addr = INADDR_ANY; | |
d62a17ae | 146 | eigrp->sequence_number = 1; |
147 | ||
148 | /*Configure default K Values for EIGRP Process*/ | |
149 | eigrp->k_values[0] = EIGRP_K1_DEFAULT; | |
150 | eigrp->k_values[1] = EIGRP_K2_DEFAULT; | |
151 | eigrp->k_values[2] = EIGRP_K3_DEFAULT; | |
152 | eigrp->k_values[3] = EIGRP_K4_DEFAULT; | |
153 | eigrp->k_values[4] = EIGRP_K5_DEFAULT; | |
154 | eigrp->k_values[5] = EIGRP_K6_DEFAULT; | |
155 | ||
156 | /* init internal data structures */ | |
157 | eigrp->eiflist = list_new(); | |
158 | eigrp->passive_interface_default = EIGRP_IF_ACTIVE; | |
9ca66cc7 | 159 | eigrp->networks = eigrp_topology_new(); |
d62a17ae | 160 | |
128ed760 DS |
161 | eigrp->fd = eigrp_sock_init(vrf_lookup_by_id(vrf_id)); |
162 | ||
163 | if (eigrp->fd < 0) { | |
09c866e3 | 164 | flog_err_sys( |
450971aa | 165 | EC_LIB_SOCKET, |
09c866e3 | 166 | "eigrp_new: fatal error: eigrp_sock_init was unable to open a socket"); |
d62a17ae | 167 | exit(1); |
168 | } | |
169 | ||
d62a17ae | 170 | eigrp->maxsndbuflen = getsockopt_so_sendbuf(eigrp->fd); |
171 | ||
6ae7ed45 | 172 | eigrp->ibuf = stream_new(EIGRP_PACKET_MAX_LEN + 1); |
d62a17ae | 173 | |
d62a17ae | 174 | thread_add_read(master, eigrp_read, eigrp, eigrp->fd, &eigrp->t_read); |
175 | eigrp->oi_write_q = list_new(); | |
176 | ||
9ca66cc7 | 177 | eigrp->topology_table = route_table_init(); |
d62a17ae | 178 | |
179 | eigrp->neighbor_self = eigrp_nbr_new(NULL); | |
180 | eigrp->neighbor_self->src.s_addr = INADDR_ANY; | |
181 | ||
182 | eigrp->variance = EIGRP_VARIANCE_DEFAULT; | |
183 | eigrp->max_paths = EIGRP_MAX_PATHS_DEFAULT; | |
184 | ||
185 | eigrp->serno = 0; | |
186 | eigrp->serno_last_update = 0; | |
187 | eigrp->topology_changes_externalIPV4 = list_new(); | |
188 | eigrp->topology_changes_internalIPV4 = list_new(); | |
189 | ||
190 | eigrp->list[EIGRP_FILTER_IN] = NULL; | |
191 | eigrp->list[EIGRP_FILTER_OUT] = NULL; | |
192 | ||
193 | eigrp->prefix[EIGRP_FILTER_IN] = NULL; | |
194 | eigrp->prefix[EIGRP_FILTER_OUT] = NULL; | |
195 | ||
196 | eigrp->routemap[EIGRP_FILTER_IN] = NULL; | |
197 | eigrp->routemap[EIGRP_FILTER_OUT] = NULL; | |
198 | ||
03a38493 | 199 | /* Distribute list install. */ |
daa64bdf DS |
200 | eigrp->distribute_ctx = |
201 | distribute_list_ctx_create(vrf_lookup_by_id(eigrp->vrf_id)); | |
03a38493 PG |
202 | distribute_list_add_hook(eigrp->distribute_ctx, |
203 | eigrp_distribute_update); | |
204 | distribute_list_delete_hook(eigrp->distribute_ctx, | |
205 | eigrp_distribute_update); | |
4b23867c PG |
206 | |
207 | /* | |
daa64bdf | 208 | eigrp->if_rmap_ctx = if_rmap_ctx_create(eigrp->vrf_id); |
4b23867c PG |
209 | if_rmap_hook_add (eigrp_if_rmap_update); |
210 | if_rmap_hook_delete (eigrp_if_rmap_update); | |
211 | */ | |
d62a17ae | 212 | QOBJ_REG(eigrp, eigrp); |
213 | return eigrp; | |
7f57883e DS |
214 | } |
215 | ||
e9449961 | 216 | struct eigrp *eigrp_get(uint16_t as, vrf_id_t vrf_id) |
7f57883e | 217 | { |
d62a17ae | 218 | struct eigrp *eigrp; |
7f57883e | 219 | |
e9449961 | 220 | eigrp = eigrp_lookup(vrf_id); |
d62a17ae | 221 | if (eigrp == NULL) { |
e9449961 | 222 | eigrp = eigrp_new(as, vrf_id); |
7eee7ef6 | 223 | listnode_add(eigrp_om->eigrp, eigrp); |
d62a17ae | 224 | } |
7f57883e | 225 | |
d62a17ae | 226 | return eigrp; |
7f57883e DS |
227 | } |
228 | ||
229 | /* Shut down the entire process */ | |
d62a17ae | 230 | void eigrp_terminate(void) |
7f57883e | 231 | { |
d62a17ae | 232 | struct eigrp *eigrp; |
233 | struct listnode *node, *nnode; | |
7f57883e | 234 | |
d62a17ae | 235 | /* shutdown already in progress */ |
236 | if (CHECK_FLAG(eigrp_om->options, EIGRP_MASTER_SHUTDOWN)) | |
237 | return; | |
7f57883e | 238 | |
d62a17ae | 239 | SET_FLAG(eigrp_om->options, EIGRP_MASTER_SHUTDOWN); |
7f57883e | 240 | |
d62a17ae | 241 | for (ALL_LIST_ELEMENTS(eigrp_om->eigrp, node, nnode, eigrp)) |
242 | eigrp_finish(eigrp); | |
8879bd22 RW |
243 | |
244 | frr_fini(); | |
7f57883e DS |
245 | } |
246 | ||
d62a17ae | 247 | void eigrp_finish(struct eigrp *eigrp) |
7f57883e | 248 | { |
d62a17ae | 249 | eigrp_finish_final(eigrp); |
250 | ||
251 | /* eigrp being shut-down? If so, was this the last eigrp instance? */ | |
252 | if (CHECK_FLAG(eigrp_om->options, EIGRP_MASTER_SHUTDOWN) | |
253 | && (listcount(eigrp_om->eigrp) == 0)) { | |
254 | if (zclient) { | |
255 | zclient_stop(zclient); | |
256 | zclient_free(zclient); | |
257 | } | |
258 | exit(0); | |
edaf6c01 | 259 | } |
7f57883e | 260 | |
d62a17ae | 261 | return; |
7f57883e DS |
262 | } |
263 | ||
264 | /* Final cleanup of eigrp instance */ | |
d62a17ae | 265 | void eigrp_finish_final(struct eigrp *eigrp) |
7f57883e | 266 | { |
d62a17ae | 267 | struct eigrp_interface *ei; |
268 | struct eigrp_neighbor *nbr; | |
269 | struct listnode *node, *nnode, *node2, *nnode2; | |
270 | ||
271 | for (ALL_LIST_ELEMENTS(eigrp->eiflist, node, nnode, ei)) { | |
272 | for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) | |
273 | eigrp_nbr_delete(nbr); | |
274 | eigrp_if_free(ei, INTERFACE_DOWN_BY_FINAL); | |
275 | } | |
7f57883e | 276 | |
d62a17ae | 277 | THREAD_OFF(eigrp->t_write); |
278 | THREAD_OFF(eigrp->t_read); | |
279 | close(eigrp->fd); | |
7f57883e | 280 | |
6a154c88 DL |
281 | list_delete(&eigrp->eiflist); |
282 | list_delete(&eigrp->oi_write_q); | |
7f57883e | 283 | |
0da93ecf | 284 | eigrp_topology_free(eigrp, eigrp->topology_table); |
7f57883e | 285 | |
d62a17ae | 286 | eigrp_nbr_delete(eigrp->neighbor_self); |
7f57883e | 287 | |
6a154c88 DL |
288 | list_delete(&eigrp->topology_changes_externalIPV4); |
289 | list_delete(&eigrp->topology_changes_internalIPV4); | |
052fe054 | 290 | |
7eee7ef6 | 291 | listnode_delete(eigrp_om->eigrp, eigrp); |
7f57883e | 292 | |
7eee7ef6 | 293 | stream_free(eigrp->ibuf); |
03a38493 | 294 | distribute_list_delete(&eigrp->distribute_ctx); |
d62a17ae | 295 | XFREE(MTYPE_EIGRP_TOP, eigrp); |
7f57883e DS |
296 | } |
297 | ||
298 | /*Look for existing eigrp process*/ | |
e9449961 | 299 | struct eigrp *eigrp_lookup(vrf_id_t vrf_id) |
7f57883e | 300 | { |
e9449961 DS |
301 | struct eigrp *eigrp; |
302 | struct listnode *node, *nnode; | |
303 | ||
304 | for (ALL_LIST_ELEMENTS(eigrp_om->eigrp, node, nnode, eigrp)) | |
305 | if (eigrp->vrf_id == vrf_id) | |
306 | return eigrp; | |
7f57883e | 307 | |
e9449961 | 308 | return NULL; |
7f57883e | 309 | } |