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