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_filter.h"
60 DEFINE_MGROUP(EIGRPD
, "eigrpd");
62 DEFINE_MTYPE_STATIC(EIGRPD
, EIGRP_TOP
, "EIGRP structure");
64 DEFINE_QOBJ_TYPE(eigrp
);
66 static struct eigrp_master eigrp_master
;
68 struct eigrp_master
*eigrp_om
;
70 extern struct zclient
*zclient
;
71 extern struct in_addr router_id_zebra
;
75 * void eigrp_router_id_update(struct eigrp *eigrp)
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
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
87 * 3. Last choice: just go with whatever the zebra daemon recommends.
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
94 * This does not work for IPv6, and to make the code simpler, its
95 * stored and processed internerall as a 32bit number
97 void eigrp_router_id_update(struct eigrp
*eigrp
)
99 struct vrf
*vrf
= vrf_lookup_by_id(eigrp
->vrf_id
);
100 struct interface
*ifp
;
101 struct in_addr router_id
, router_id_old
;
103 router_id_old
= eigrp
->router_id
;
105 if (eigrp
->router_id_static
.s_addr
!= INADDR_ANY
)
106 router_id
= eigrp
->router_id_static
;
108 else if (eigrp
->router_id
.s_addr
!= INADDR_ANY
)
109 router_id
= eigrp
->router_id
;
112 router_id
= router_id_zebra
;
114 eigrp
->router_id
= router_id
;
115 if (router_id_old
.s_addr
!= router_id
.s_addr
) {
116 /* update eigrp_interface's */
117 FOR_ALL_INTERFACES (vrf
, ifp
)
118 eigrp_if_update(ifp
);
122 void eigrp_master_init(void)
126 memset(&eigrp_master
, 0, sizeof(struct eigrp_master
));
128 eigrp_om
= &eigrp_master
;
129 eigrp_om
->eigrp
= list_new();
132 eigrp_om
->start_time
= tv
.tv_sec
;
135 /* Allocate new eigrp structure. */
136 static struct eigrp
*eigrp_new(uint16_t as
, vrf_id_t vrf_id
)
138 struct eigrp
*eigrp
= XCALLOC(MTYPE_EIGRP_TOP
, sizeof(struct eigrp
));
140 /* init information relevant to peers */
141 eigrp
->vrf_id
= vrf_id
;
144 eigrp
->router_id
.s_addr
= INADDR_ANY
;
145 eigrp
->router_id_static
.s_addr
= INADDR_ANY
;
146 eigrp
->sequence_number
= 1;
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
;
156 /* init internal data structures */
157 eigrp
->eiflist
= list_new();
158 eigrp
->passive_interface_default
= EIGRP_IF_ACTIVE
;
159 eigrp
->networks
= eigrp_topology_new();
161 eigrp
->fd
= eigrp_sock_init(vrf_lookup_by_id(vrf_id
));
166 "eigrp_new: fatal error: eigrp_sock_init was unable to open a socket");
170 eigrp
->maxsndbuflen
= getsockopt_so_sendbuf(eigrp
->fd
);
172 eigrp
->ibuf
= stream_new(EIGRP_PACKET_MAX_LEN
+ 1);
174 eigrp
->t_read
= NULL
;
175 thread_add_read(master
, eigrp_read
, eigrp
, eigrp
->fd
, &eigrp
->t_read
);
176 eigrp
->oi_write_q
= list_new();
178 eigrp
->topology_table
= route_table_init();
180 eigrp
->neighbor_self
= eigrp_nbr_new(NULL
);
181 eigrp
->neighbor_self
->src
.s_addr
= INADDR_ANY
;
183 eigrp
->variance
= EIGRP_VARIANCE_DEFAULT
;
184 eigrp
->max_paths
= EIGRP_MAX_PATHS_DEFAULT
;
187 eigrp
->serno_last_update
= 0;
188 eigrp
->topology_changes_externalIPV4
= list_new();
189 eigrp
->topology_changes_internalIPV4
= list_new();
191 eigrp
->list
[EIGRP_FILTER_IN
] = NULL
;
192 eigrp
->list
[EIGRP_FILTER_OUT
] = NULL
;
194 eigrp
->prefix
[EIGRP_FILTER_IN
] = NULL
;
195 eigrp
->prefix
[EIGRP_FILTER_OUT
] = NULL
;
197 eigrp
->routemap
[EIGRP_FILTER_IN
] = NULL
;
198 eigrp
->routemap
[EIGRP_FILTER_OUT
] = NULL
;
200 /* Distribute list install. */
201 eigrp
->distribute_ctx
=
202 distribute_list_ctx_create(vrf_lookup_by_id(eigrp
->vrf_id
));
203 distribute_list_add_hook(eigrp
->distribute_ctx
,
204 eigrp_distribute_update
);
205 distribute_list_delete_hook(eigrp
->distribute_ctx
,
206 eigrp_distribute_update
);
209 eigrp->if_rmap_ctx = if_rmap_ctx_create(eigrp->vrf_id);
210 if_rmap_hook_add (eigrp_if_rmap_update);
211 if_rmap_hook_delete (eigrp_if_rmap_update);
213 QOBJ_REG(eigrp
, eigrp
);
217 struct eigrp
*eigrp_get(uint16_t as
, vrf_id_t vrf_id
)
221 eigrp
= eigrp_lookup(vrf_id
);
223 eigrp
= eigrp_new(as
, vrf_id
);
224 listnode_add(eigrp_om
->eigrp
, eigrp
);
230 /* Shut down the entire process */
231 void eigrp_terminate(void)
234 struct listnode
*node
, *nnode
;
236 /* shutdown already in progress */
237 if (CHECK_FLAG(eigrp_om
->options
, EIGRP_MASTER_SHUTDOWN
))
240 SET_FLAG(eigrp_om
->options
, EIGRP_MASTER_SHUTDOWN
);
242 for (ALL_LIST_ELEMENTS(eigrp_om
->eigrp
, node
, nnode
, eigrp
))
248 void eigrp_finish(struct eigrp
*eigrp
)
250 eigrp_finish_final(eigrp
);
252 /* eigrp being shut-down? If so, was this the last eigrp instance? */
253 if (CHECK_FLAG(eigrp_om
->options
, EIGRP_MASTER_SHUTDOWN
)
254 && (listcount(eigrp_om
->eigrp
) == 0)) {
256 zclient_stop(zclient
);
257 zclient_free(zclient
);
265 /* Final cleanup of eigrp instance */
266 void eigrp_finish_final(struct eigrp
*eigrp
)
268 struct eigrp_interface
*ei
;
269 struct eigrp_neighbor
*nbr
;
270 struct listnode
*node
, *nnode
, *node2
, *nnode2
;
272 for (ALL_LIST_ELEMENTS(eigrp
->eiflist
, node
, nnode
, ei
)) {
273 for (ALL_LIST_ELEMENTS(ei
->nbrs
, node2
, nnode2
, nbr
))
274 eigrp_nbr_delete(nbr
);
275 eigrp_if_free(ei
, INTERFACE_DOWN_BY_FINAL
);
278 THREAD_OFF(eigrp
->t_write
);
279 THREAD_OFF(eigrp
->t_read
);
282 list_delete(&eigrp
->eiflist
);
283 list_delete(&eigrp
->oi_write_q
);
285 eigrp_topology_free(eigrp
, eigrp
->topology_table
);
287 eigrp_nbr_delete(eigrp
->neighbor_self
);
289 list_delete(&eigrp
->topology_changes_externalIPV4
);
290 list_delete(&eigrp
->topology_changes_internalIPV4
);
292 listnode_delete(eigrp_om
->eigrp
, eigrp
);
294 stream_free(eigrp
->ibuf
);
295 distribute_list_delete(&eigrp
->distribute_ctx
);
296 XFREE(MTYPE_EIGRP_TOP
, eigrp
);
299 /*Look for existing eigrp process*/
300 struct eigrp
*eigrp_lookup(vrf_id_t vrf_id
)
303 struct listnode
*node
, *nnode
;
305 for (ALL_LIST_ELEMENTS(eigrp_om
->eigrp
, node
, nnode
, eigrp
))
306 if (eigrp
->vrf_id
== vrf_id
)