2 * EIGRP Daemon Program.
3 * Copyright (C) 2013-2014
11 * This file is part of GNU Zebra.
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
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.
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
40 #include "sockunion.h" /* for inet_aton () */
46 #include "lib_errors.h"
47 #include "distribute.h"
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"
59 #include "eigrpd/eigrp_filter.h"
61 DEFINE_QOBJ_TYPE(eigrp
)
63 static struct eigrp_master eigrp_master
;
65 struct eigrp_master
*eigrp_om
;
67 extern struct zclient
*zclient
;
68 extern struct in_addr router_id_zebra
;
72 * void eigrp_router_id_update(struct eigrp *eigrp)
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
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
84 * 3. Last choice: just go with whatever the zebra daemon recommends.
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
91 * This does not work for IPv6, and to make the code simpler, its
92 * stored and processed internerall as a 32bit number
94 void eigrp_router_id_update(struct eigrp
*eigrp
)
96 struct vrf
*vrf
= vrf_lookup_by_id(eigrp
->vrf_id
);
97 struct interface
*ifp
;
98 struct in_addr router_id
, router_id_old
;
100 router_id_old
= eigrp
->router_id
;
102 if (eigrp
->router_id_static
.s_addr
!= INADDR_ANY
)
103 router_id
= eigrp
->router_id_static
;
105 else if (eigrp
->router_id
.s_addr
!= INADDR_ANY
)
106 router_id
= eigrp
->router_id
;
109 router_id
= router_id_zebra
;
111 eigrp
->router_id
= router_id
;
112 if (router_id_old
.s_addr
!= router_id
.s_addr
) {
113 // if (IS_DEBUG_EIGRP_EVENT)
114 // zlog_debug("Router-ID[NEW:%s]: Update",
115 // inet_ntoa(eigrp->router_id));
117 /* update eigrp_interface's */
118 FOR_ALL_INTERFACES (vrf
, ifp
)
119 eigrp_if_update(ifp
);
123 void eigrp_master_init(void)
127 memset(&eigrp_master
, 0, sizeof(struct eigrp_master
));
129 eigrp_om
= &eigrp_master
;
130 eigrp_om
->eigrp
= list_new();
133 eigrp_om
->start_time
= tv
.tv_sec
;
136 /* Allocate new eigrp structure. */
137 static struct eigrp
*eigrp_new(uint16_t as
, vrf_id_t vrf_id
)
139 struct eigrp
*eigrp
= XCALLOC(MTYPE_EIGRP_TOP
, sizeof(struct eigrp
));
141 /* init information relevant to peers */
142 eigrp
->vrf_id
= vrf_id
;
145 eigrp
->router_id
.s_addr
= INADDR_ANY
;
146 eigrp
->router_id_static
.s_addr
= INADDR_ANY
;
147 eigrp
->sequence_number
= 1;
149 /*Configure default K Values for EIGRP Process*/
150 eigrp
->k_values
[0] = EIGRP_K1_DEFAULT
;
151 eigrp
->k_values
[1] = EIGRP_K2_DEFAULT
;
152 eigrp
->k_values
[2] = EIGRP_K3_DEFAULT
;
153 eigrp
->k_values
[3] = EIGRP_K4_DEFAULT
;
154 eigrp
->k_values
[4] = EIGRP_K5_DEFAULT
;
155 eigrp
->k_values
[5] = EIGRP_K6_DEFAULT
;
157 /* init internal data structures */
158 eigrp
->eiflist
= list_new();
159 eigrp
->passive_interface_default
= EIGRP_IF_ACTIVE
;
160 eigrp
->networks
= eigrp_topology_new();
162 eigrp
->fd
= eigrp_sock_init(vrf_lookup_by_id(vrf_id
));
167 "eigrp_new: fatal error: eigrp_sock_init was unable to open a socket");
171 eigrp
->maxsndbuflen
= getsockopt_so_sendbuf(eigrp
->fd
);
173 eigrp
->ibuf
= stream_new(EIGRP_PACKET_MAX_LEN
+ 1);
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();
179 eigrp
->topology_table
= route_table_init();
181 eigrp
->neighbor_self
= eigrp_nbr_new(NULL
);
182 eigrp
->neighbor_self
->src
.s_addr
= INADDR_ANY
;
184 eigrp
->variance
= EIGRP_VARIANCE_DEFAULT
;
185 eigrp
->max_paths
= EIGRP_MAX_PATHS_DEFAULT
;
188 eigrp
->serno_last_update
= 0;
189 eigrp
->topology_changes_externalIPV4
= list_new();
190 eigrp
->topology_changes_internalIPV4
= list_new();
192 eigrp
->list
[EIGRP_FILTER_IN
] = NULL
;
193 eigrp
->list
[EIGRP_FILTER_OUT
] = NULL
;
195 eigrp
->prefix
[EIGRP_FILTER_IN
] = NULL
;
196 eigrp
->prefix
[EIGRP_FILTER_OUT
] = NULL
;
198 eigrp
->routemap
[EIGRP_FILTER_IN
] = NULL
;
199 eigrp
->routemap
[EIGRP_FILTER_OUT
] = NULL
;
201 /* Distribute list install. */
202 eigrp
->distribute_ctx
=
203 distribute_list_ctx_create(vrf_lookup_by_id(eigrp
->vrf_id
));
204 distribute_list_add_hook(eigrp
->distribute_ctx
,
205 eigrp_distribute_update
);
206 distribute_list_delete_hook(eigrp
->distribute_ctx
,
207 eigrp_distribute_update
);
210 eigrp->if_rmap_ctx = if_rmap_ctx_create(eigrp->vrf_id);
211 if_rmap_hook_add (eigrp_if_rmap_update);
212 if_rmap_hook_delete (eigrp_if_rmap_update);
214 QOBJ_REG(eigrp
, eigrp
);
218 struct eigrp
*eigrp_get(uint16_t as
, vrf_id_t vrf_id
)
222 eigrp
= eigrp_lookup(vrf_id
);
224 eigrp
= eigrp_new(as
, vrf_id
);
225 listnode_add(eigrp_om
->eigrp
, eigrp
);
231 /* Shut down the entire process */
232 void eigrp_terminate(void)
235 struct listnode
*node
, *nnode
;
237 /* shutdown already in progress */
238 if (CHECK_FLAG(eigrp_om
->options
, EIGRP_MASTER_SHUTDOWN
))
241 SET_FLAG(eigrp_om
->options
, EIGRP_MASTER_SHUTDOWN
);
243 for (ALL_LIST_ELEMENTS(eigrp_om
->eigrp
, node
, nnode
, eigrp
))
249 void eigrp_finish(struct eigrp
*eigrp
)
251 eigrp_finish_final(eigrp
);
253 /* eigrp being shut-down? If so, was this the last eigrp instance? */
254 if (CHECK_FLAG(eigrp_om
->options
, EIGRP_MASTER_SHUTDOWN
)
255 && (listcount(eigrp_om
->eigrp
) == 0)) {
257 zclient_stop(zclient
);
258 zclient_free(zclient
);
266 /* Final cleanup of eigrp instance */
267 void eigrp_finish_final(struct eigrp
*eigrp
)
269 struct eigrp_interface
*ei
;
270 struct eigrp_neighbor
*nbr
;
271 struct listnode
*node
, *nnode
, *node2
, *nnode2
;
273 for (ALL_LIST_ELEMENTS(eigrp
->eiflist
, node
, nnode
, ei
)) {
274 for (ALL_LIST_ELEMENTS(ei
->nbrs
, node2
, nnode2
, nbr
))
275 eigrp_nbr_delete(nbr
);
276 eigrp_if_free(ei
, INTERFACE_DOWN_BY_FINAL
);
279 THREAD_OFF(eigrp
->t_write
);
280 THREAD_OFF(eigrp
->t_read
);
283 list_delete(&eigrp
->eiflist
);
284 list_delete(&eigrp
->oi_write_q
);
286 eigrp_topology_free(eigrp
, eigrp
->topology_table
);
288 eigrp_nbr_delete(eigrp
->neighbor_self
);
290 list_delete(&eigrp
->topology_changes_externalIPV4
);
291 list_delete(&eigrp
->topology_changes_internalIPV4
);
293 listnode_delete(eigrp_om
->eigrp
, eigrp
);
295 stream_free(eigrp
->ibuf
);
296 distribute_list_delete(&eigrp
->distribute_ctx
);
297 XFREE(MTYPE_EIGRP_TOP
, eigrp
);
300 /*Look for existing eigrp process*/
301 struct eigrp
*eigrp_lookup(vrf_id_t vrf_id
)
304 struct listnode
*node
, *nnode
;
306 for (ALL_LIST_ELEMENTS(eigrp_om
->eigrp
, node
, nnode
, eigrp
))
307 if (eigrp
->vrf_id
== vrf_id
)