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 () */
47 #include "eigrpd/eigrp_structs.h"
48 #include "eigrpd/eigrpd.h"
49 #include "eigrpd/eigrp_interface.h"
50 #include "eigrpd/eigrp_zebra.h"
51 #include "eigrpd/eigrp_vty.h"
52 #include "eigrpd/eigrp_neighbor.h"
53 #include "eigrpd/eigrp_packet.h"
54 #include "eigrpd/eigrp_network.h"
55 #include "eigrpd/eigrp_topology.h"
56 #include "eigrpd/eigrp_memory.h"
58 DEFINE_QOBJ_TYPE(eigrp
)
60 static struct eigrp_master eigrp_master
;
62 struct eigrp_master
*eigrp_om
;
64 static void eigrp_delete(struct eigrp
*);
65 static struct eigrp
*eigrp_new(const char *);
66 static void eigrp_add(struct eigrp
*);
68 extern struct zclient
*zclient
;
69 extern struct in_addr router_id_zebra
;
73 * void eigrp_router_id_update(struct eigrp *eigrp)
76 * update routerid associated with this instance of EIGRP.
77 * If the id changes, then call if_update for each interface
78 * to resync the topology database with all neighbors
80 * Select the router ID based on these priorities:
81 * 1. Statically assigned router ID is always the first choice.
82 * 2. If there is no statically assigned router ID, then try to stick
83 * with the most recent value, since changing router ID's is very
85 * 3. Last choice: just go with whatever the zebra daemon recommends.
88 * router id for EIGRP is really just a 32 bit number. Cisco historically
89 * displays it in dotted decimal notation, and will pickup an IP address
90 * from an interface so it can be 'auto-configed" to a uniqe value
92 * This does not work for IPv6, and to make the code simpler, its
93 * stored and processed internerall as a 32bit number
95 void eigrp_router_id_update(struct eigrp
*eigrp
)
97 struct interface
*ifp
;
98 struct listnode
*node
;
99 u_int32_t router_id
, router_id_old
;
101 router_id_old
= eigrp
->router_id
;
103 if (eigrp
->router_id_static
!= 0)
104 router_id
= eigrp
->router_id_static
;
106 else if (eigrp
->router_id
!= 0)
107 router_id
= eigrp
->router_id
;
110 router_id
= router_id_zebra
.s_addr
;
112 eigrp
->router_id
= router_id
;
113 if (router_id_old
!= router_id
) {
114 // if (IS_DEBUG_EIGRP_EVENT)
115 // zlog_debug("Router-ID[NEW:%s]: Update",
116 // inet_ntoa(eigrp->router_id));
118 /* update eigrp_interface's */
119 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT
), node
, ifp
))
120 eigrp_if_update(ifp
);
124 void eigrp_master_init()
128 memset(&eigrp_master
, 0, sizeof(struct eigrp_master
));
130 eigrp_om
= &eigrp_master
;
131 eigrp_om
->eigrp
= list_new();
134 eigrp_om
->start_time
= tv
.tv_sec
;
137 /* Allocate new eigrp structure. */
138 static struct eigrp
*eigrp_new(const char *AS
)
140 struct eigrp
*eigrp
= XCALLOC(MTYPE_EIGRP_TOP
, sizeof(struct eigrp
));
143 /* init information relevant to peers */
145 eigrp
->AS
= atoi(AS
);
146 eigrp
->router_id
= 0L;
147 eigrp
->router_id_static
= 0L;
148 eigrp
->sequence_number
= 1;
150 /*Configure default K Values for EIGRP Process*/
151 eigrp
->k_values
[0] = EIGRP_K1_DEFAULT
;
152 eigrp
->k_values
[1] = EIGRP_K2_DEFAULT
;
153 eigrp
->k_values
[2] = EIGRP_K3_DEFAULT
;
154 eigrp
->k_values
[3] = EIGRP_K4_DEFAULT
;
155 eigrp
->k_values
[4] = EIGRP_K5_DEFAULT
;
156 eigrp
->k_values
[5] = EIGRP_K6_DEFAULT
;
158 /* init internal data structures */
159 eigrp
->eiflist
= list_new();
160 eigrp
->passive_interface_default
= EIGRP_IF_ACTIVE
;
161 eigrp
->networks
= route_table_init();
163 if ((eigrp_socket
= eigrp_sock_init()) < 0) {
165 "eigrp_new: fatal error: eigrp_sock_init was unable to open "
170 eigrp
->fd
= eigrp_socket
;
171 eigrp
->maxsndbuflen
= getsockopt_so_sendbuf(eigrp
->fd
);
173 if ((eigrp
->ibuf
= stream_new(EIGRP_PACKET_MAX_LEN
+ 1)) == NULL
) {
175 "eigrp_new: fatal error: stream_new (%u) failed allocating ibuf",
176 EIGRP_PACKET_MAX_LEN
+ 1);
180 eigrp
->t_read
= NULL
;
181 thread_add_read(master
, eigrp_read
, eigrp
, eigrp
->fd
, &eigrp
->t_read
);
182 eigrp
->oi_write_q
= list_new();
184 eigrp
->topology_table
= eigrp_topology_new();
186 eigrp
->neighbor_self
= eigrp_nbr_new(NULL
);
187 eigrp
->neighbor_self
->src
.s_addr
= INADDR_ANY
;
189 eigrp
->variance
= EIGRP_VARIANCE_DEFAULT
;
190 eigrp
->max_paths
= EIGRP_MAX_PATHS_DEFAULT
;
193 eigrp
->serno_last_update
= 0;
194 eigrp
->topology_changes_externalIPV4
= list_new();
195 eigrp
->topology_changes_internalIPV4
= list_new();
197 eigrp
->list
[EIGRP_FILTER_IN
] = NULL
;
198 eigrp
->list
[EIGRP_FILTER_OUT
] = NULL
;
200 eigrp
->prefix
[EIGRP_FILTER_IN
] = NULL
;
201 eigrp
->prefix
[EIGRP_FILTER_OUT
] = NULL
;
203 eigrp
->routemap
[EIGRP_FILTER_IN
] = NULL
;
204 eigrp
->routemap
[EIGRP_FILTER_OUT
] = NULL
;
206 QOBJ_REG(eigrp
, eigrp
);
210 static void eigrp_add(struct eigrp
*eigrp
)
212 listnode_add(eigrp_om
->eigrp
, eigrp
);
215 static void eigrp_delete(struct eigrp
*eigrp
)
217 listnode_delete(eigrp_om
->eigrp
, eigrp
);
220 struct eigrp
*eigrp_get(const char *AS
)
224 eigrp
= eigrp_lookup();
226 eigrp
= eigrp_new(AS
);
233 /* Shut down the entire process */
234 void eigrp_terminate(void)
237 struct listnode
*node
, *nnode
;
239 /* shutdown already in progress */
240 if (CHECK_FLAG(eigrp_om
->options
, EIGRP_MASTER_SHUTDOWN
))
243 SET_FLAG(eigrp_om
->options
, EIGRP_MASTER_SHUTDOWN
);
245 for (ALL_LIST_ELEMENTS(eigrp_om
->eigrp
, node
, nnode
, eigrp
))
251 void eigrp_finish(struct eigrp
*eigrp
)
253 eigrp_finish_final(eigrp
);
255 /* eigrp being shut-down? If so, was this the last eigrp instance? */
256 if (CHECK_FLAG(eigrp_om
->options
, EIGRP_MASTER_SHUTDOWN
)
257 && (listcount(eigrp_om
->eigrp
) == 0)) {
259 zclient_stop(zclient
);
260 zclient_free(zclient
);
268 /* Final cleanup of eigrp instance */
269 void eigrp_finish_final(struct eigrp
*eigrp
)
271 struct eigrp_interface
*ei
;
272 struct eigrp_neighbor
*nbr
;
273 struct listnode
*node
, *nnode
, *node2
, *nnode2
;
275 for (ALL_LIST_ELEMENTS(eigrp
->eiflist
, node
, nnode
, ei
)) {
276 for (ALL_LIST_ELEMENTS(ei
->nbrs
, node2
, nnode2
, nbr
))
277 eigrp_nbr_delete(nbr
);
278 eigrp_if_free(ei
, INTERFACE_DOWN_BY_FINAL
);
281 THREAD_OFF(eigrp
->t_write
);
282 THREAD_OFF(eigrp
->t_read
);
285 list_delete(eigrp
->eiflist
);
286 list_delete(eigrp
->oi_write_q
);
287 list_delete(eigrp
->topology_changes_externalIPV4
);
288 list_delete(eigrp
->topology_changes_internalIPV4
);
290 eigrp_topology_cleanup(eigrp
->topology_table
);
291 eigrp_topology_free(eigrp
->topology_table
);
293 eigrp_nbr_delete(eigrp
->neighbor_self
);
297 XFREE(MTYPE_EIGRP_TOP
, eigrp
);
300 /*Look for existing eigrp process*/
301 struct eigrp
*eigrp_lookup(void)
303 if (listcount(eigrp_om
->eigrp
) == 0)
306 return listgetdata(listhead(eigrp_om
->eigrp
));