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