]>
Commit | Line | Data |
---|---|---|
7f57883e DS |
1 | /* |
2 | * EIGRP Interface Functions. | |
3 | * Copyright (C) 2013-2016 | |
4 | * Authors: | |
5 | * Donnie Savage | |
6 | * Jan Janovic | |
7 | * Matej Perina | |
8 | * Peter Orsag | |
9 | * Peter Paluch | |
10 | * Frantisek Gazo | |
11 | * Tomas Hvorkovy | |
12 | * Martin Kontsek | |
13 | * Lukas Koribsky | |
14 | * | |
15 | * This file is part of GNU Zebra. | |
16 | * | |
17 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
18 | * under the terms of the GNU General Public License as published by the | |
19 | * Free Software Foundation; either version 2, or (at your option) any | |
20 | * later version. | |
21 | * | |
22 | * GNU Zebra is distributed in the hope that it will be useful, but | |
23 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
25 | * General Public License for more details. | |
26 | * | |
896014f4 DL |
27 | * You should have received a copy of the GNU General Public License along |
28 | * with this program; see the file COPYING; if not, write to the Free Software | |
29 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
7f57883e DS |
30 | */ |
31 | ||
32 | #include <zebra.h> | |
33 | ||
34 | #include "thread.h" | |
35 | #include "linklist.h" | |
36 | #include "prefix.h" | |
37 | #include "if.h" | |
38 | #include "table.h" | |
39 | #include "memory.h" | |
40 | #include "command.h" | |
41 | #include "stream.h" | |
42 | #include "log.h" | |
43 | #include "keychain.h" | |
44 | #include "vrf.h" | |
45 | ||
46 | #include "eigrpd/eigrp_structs.h" | |
47 | #include "eigrpd/eigrpd.h" | |
48 | #include "eigrpd/eigrp_interface.h" | |
49 | #include "eigrpd/eigrp_neighbor.h" | |
50 | #include "eigrpd/eigrp_packet.h" | |
51 | #include "eigrpd/eigrp_zebra.h" | |
52 | #include "eigrpd/eigrp_vty.h" | |
53 | #include "eigrpd/eigrp_network.h" | |
54 | #include "eigrpd/eigrp_topology.h" | |
55 | #include "eigrpd/eigrp_memory.h" | |
348addb4 | 56 | #include "eigrpd/eigrp_fsm.h" |
ddbf3e60 | 57 | #include "eigrpd/eigrp_dump.h" |
7f57883e | 58 | |
d62a17ae | 59 | struct eigrp_interface *eigrp_if_new(struct eigrp *eigrp, struct interface *ifp, |
60 | struct prefix *p) | |
7f57883e | 61 | { |
b748db67 | 62 | struct eigrp_interface *ei = ifp->info; |
d62a17ae | 63 | int i; |
7f57883e | 64 | |
b748db67 | 65 | if (ei) |
d62a17ae | 66 | return ei; |
7f57883e | 67 | |
b748db67 DS |
68 | ei = XCALLOC(MTYPE_EIGRP_IF, sizeof(struct eigrp_interface)); |
69 | ||
d62a17ae | 70 | /* Set zebra interface pointer. */ |
71 | ei->ifp = ifp; | |
b245781a | 72 | prefix_copy(&ei->address, p); |
7f57883e | 73 | |
b748db67 | 74 | ifp->info = ei; |
d62a17ae | 75 | listnode_add(eigrp->eiflist, ei); |
7f57883e | 76 | |
d62a17ae | 77 | ei->type = EIGRP_IFTYPE_BROADCAST; |
7f57883e | 78 | |
d62a17ae | 79 | /* Initialize neighbor list. */ |
80 | ei->nbrs = list_new(); | |
7f57883e | 81 | |
d62a17ae | 82 | ei->crypt_seqnum = time(NULL); |
7f57883e | 83 | |
d62a17ae | 84 | /* Initialize lists */ |
85 | for (i = 0; i < EIGRP_FILTER_MAX; i++) { | |
86 | ei->list[i] = NULL; | |
87 | ei->prefix[i] = NULL; | |
88 | ei->routemap[i] = NULL; | |
89 | } | |
7f57883e | 90 | |
b748db67 | 91 | ei->eigrp = eigrp; |
7f57883e | 92 | |
b748db67 DS |
93 | ei->params.v_hello = EIGRP_HELLO_INTERVAL_DEFAULT; |
94 | ei->params.v_wait = EIGRP_HOLD_INTERVAL_DEFAULT; | |
95 | ei->params.bandwidth = EIGRP_BANDWIDTH_DEFAULT; | |
96 | ei->params.delay = EIGRP_DELAY_DEFAULT; | |
97 | ei->params.reliability = EIGRP_RELIABILITY_DEFAULT; | |
98 | ei->params.load = EIGRP_LOAD_DEFAULT; | |
99 | ei->params.auth_type = EIGRP_AUTH_TYPE_NONE; | |
100 | ei->params.auth_keychain = NULL; | |
7f57883e | 101 | |
b748db67 | 102 | return ei; |
7f57883e DS |
103 | } |
104 | ||
d62a17ae | 105 | int eigrp_if_delete_hook(struct interface *ifp) |
7f57883e | 106 | { |
b748db67 DS |
107 | struct eigrp_interface *ei = ifp->info; |
108 | struct eigrp *eigrp; | |
7f57883e | 109 | |
b748db67 DS |
110 | if (!ei) |
111 | return 0; | |
112 | ||
6a154c88 | 113 | list_delete(&ei->nbrs); |
7f57883e | 114 | |
b748db67 DS |
115 | eigrp = ei->eigrp; |
116 | listnode_delete(eigrp->eiflist, ei); | |
7f57883e | 117 | |
c45db77d DS |
118 | eigrp_fifo_free(ei->obuf); |
119 | ||
d62a17ae | 120 | XFREE(MTYPE_EIGRP_IF_INFO, ifp->info); |
121 | ifp->info = NULL; | |
7f57883e | 122 | |
d62a17ae | 123 | return 0; |
7f57883e DS |
124 | } |
125 | ||
138c5a74 DS |
126 | static int eigrp_ifp_create(struct interface *ifp) |
127 | { | |
ef7bd2a3 DS |
128 | struct eigrp_interface *ei = ifp->info; |
129 | ||
130 | if (!ei) | |
131 | return 0; | |
132 | ||
133 | ei->params.type = eigrp_default_iftype(ifp); | |
134 | ||
135 | eigrp_if_update(ifp); | |
136 | ||
138c5a74 DS |
137 | return 0; |
138 | } | |
139 | ||
140 | static int eigrp_ifp_up(struct interface *ifp) | |
141 | { | |
ddbf3e60 DS |
142 | /* Interface is already up. */ |
143 | if (if_is_operative(ifp)) { | |
144 | /* Temporarily keep ifp values. */ | |
145 | struct interface if_tmp; | |
146 | memcpy(&if_tmp, ifp, sizeof(struct interface)); | |
147 | ||
148 | if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE)) | |
149 | zlog_debug("Zebra: Interface[%s] state update.", | |
150 | ifp->name); | |
151 | ||
152 | if (if_tmp.bandwidth != ifp->bandwidth) { | |
153 | if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE)) | |
154 | zlog_debug( | |
155 | "Zebra: Interface[%s] bandwidth change %d -> %d.", | |
156 | ifp->name, if_tmp.bandwidth, | |
157 | ifp->bandwidth); | |
158 | ||
159 | // eigrp_if_recalculate_output_cost (ifp); | |
160 | } | |
161 | ||
162 | if (if_tmp.mtu != ifp->mtu) { | |
163 | if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE)) | |
164 | zlog_debug( | |
165 | "Zebra: Interface[%s] MTU change %u -> %u.", | |
166 | ifp->name, if_tmp.mtu, ifp->mtu); | |
167 | ||
168 | /* Must reset the interface (simulate down/up) when MTU | |
169 | * changes. */ | |
170 | eigrp_if_reset(ifp); | |
171 | } | |
172 | return 0; | |
173 | } | |
174 | ||
175 | if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE)) | |
176 | zlog_debug("Zebra: Interface[%s] state change to up.", | |
177 | ifp->name); | |
178 | ||
179 | if (ifp->info) | |
180 | eigrp_if_up(ifp->info); | |
181 | ||
138c5a74 DS |
182 | return 0; |
183 | } | |
184 | ||
185 | static int eigrp_ifp_down(struct interface *ifp) | |
186 | { | |
b0b69e59 DS |
187 | if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE)) |
188 | zlog_debug("Zebra: Interface[%s] state change to down.", | |
189 | ifp->name); | |
190 | ||
191 | if (ifp->info) | |
192 | eigrp_if_down(ifp->info); | |
193 | ||
138c5a74 DS |
194 | return 0; |
195 | } | |
196 | ||
197 | static int eigrp_ifp_destroy(struct interface *ifp) | |
198 | { | |
3c3c3252 DS |
199 | if (if_is_up(ifp)) |
200 | zlog_warn("Zebra: got delete of %s, but interface is still up", | |
201 | ifp->name); | |
202 | ||
203 | if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE)) | |
204 | zlog_debug( | |
205 | "Zebra: interface delete %s index %d flags %llx metric %d mtu %d", | |
206 | ifp->name, ifp->ifindex, (unsigned long long)ifp->flags, | |
207 | ifp->metric, ifp->mtu); | |
208 | ||
209 | if (ifp->info) | |
210 | eigrp_if_free(ifp->info, INTERFACE_DOWN_BY_ZEBRA); | |
211 | ||
138c5a74 DS |
212 | return 0; |
213 | } | |
214 | ||
7f57883e DS |
215 | struct list *eigrp_iflist; |
216 | ||
4d762f26 | 217 | void eigrp_if_init(void) |
7f57883e | 218 | { |
138c5a74 DS |
219 | if_zapi_callbacks(eigrp_ifp_create, eigrp_ifp_up, |
220 | eigrp_ifp_down, eigrp_ifp_destroy); | |
d62a17ae | 221 | /* Initialize Zebra interface data structure. */ |
996c9314 | 222 | // hook_register_prio(if_add, 0, eigrp_if_new); |
ce19a04a | 223 | hook_register_prio(if_del, 0, eigrp_if_delete_hook); |
7f57883e DS |
224 | } |
225 | ||
7f57883e | 226 | |
d62a17ae | 227 | void eigrp_del_if_params(struct eigrp_if_params *eip) |
7f57883e | 228 | { |
d62a17ae | 229 | if (eip->auth_keychain) |
230 | free(eip->auth_keychain); | |
7f57883e DS |
231 | } |
232 | ||
d62a17ae | 233 | int eigrp_if_up(struct eigrp_interface *ei) |
7f57883e | 234 | { |
d62a17ae | 235 | struct eigrp_prefix_entry *pe; |
255ab940 | 236 | struct eigrp_nexthop_entry *ne; |
d62a17ae | 237 | struct eigrp_metrics metric; |
238 | struct eigrp_interface *ei2; | |
239 | struct listnode *node, *nnode; | |
dbfd865b | 240 | struct eigrp *eigrp; |
d62a17ae | 241 | |
242 | if (ei == NULL) | |
243 | return 0; | |
244 | ||
dbfd865b DS |
245 | eigrp = ei->eigrp; |
246 | eigrp_adjust_sndbuflen(eigrp, ei->ifp->mtu); | |
247 | ||
d62a17ae | 248 | eigrp_if_stream_set(ei); |
249 | ||
250 | /* Set multicast memberships appropriately for new state. */ | |
251 | eigrp_if_set_multicast(ei); | |
252 | ||
253 | thread_add_event(master, eigrp_hello_timer, ei, (1), NULL); | |
254 | ||
255 | /*Prepare metrics*/ | |
996c9314 | 256 | metric.bandwidth = eigrp_bandwidth_to_scaled(ei->params.bandwidth); |
b748db67 DS |
257 | metric.delay = eigrp_delay_to_scaled(ei->params.delay); |
258 | metric.load = ei->params.load; | |
259 | metric.reliability = ei->params.reliability; | |
d62a17ae | 260 | metric.mtu[0] = 0xDC; |
261 | metric.mtu[1] = 0x05; | |
262 | metric.mtu[2] = 0x00; | |
263 | metric.hop_count = 0; | |
264 | metric.flags = 0; | |
265 | metric.tag = 0; | |
266 | ||
267 | /*Add connected entry to topology table*/ | |
268 | ||
255ab940 | 269 | ne = eigrp_nexthop_entry_new(); |
348addb4 DS |
270 | ne->ei = ei; |
271 | ne->reported_metric = metric; | |
272 | ne->total_metric = metric; | |
273 | ne->distance = eigrp_calculate_metrics(eigrp, metric); | |
274 | ne->reported_distance = 0; | |
275 | ne->adv_router = eigrp->neighbor_self; | |
255ab940 | 276 | ne->flags = EIGRP_NEXTHOP_ENTRY_SUCCESSOR_FLAG; |
348addb4 | 277 | |
02b45998 | 278 | struct prefix dest_addr; |
d62a17ae | 279 | |
b245781a | 280 | dest_addr = ei->address; |
02b45998 | 281 | apply_mask(&dest_addr); |
d62a17ae | 282 | pe = eigrp_topology_table_lookup_ipv4(eigrp->topology_table, |
476a1469 | 283 | &dest_addr); |
d62a17ae | 284 | |
285 | if (pe == NULL) { | |
286 | pe = eigrp_prefix_entry_new(); | |
287 | pe->serno = eigrp->serno; | |
02b45998 DS |
288 | pe->destination = (struct prefix *)prefix_ipv4_new(); |
289 | prefix_copy(pe->destination, &dest_addr); | |
d62a17ae | 290 | pe->af = AF_INET; |
291 | pe->nt = EIGRP_TOPOLOGY_TYPE_CONNECTED; | |
292 | ||
348addb4 | 293 | ne->prefix = pe; |
cd6c573c | 294 | pe->reported_metric = metric; |
d62a17ae | 295 | pe->state = EIGRP_FSM_STATE_PASSIVE; |
296 | pe->fdistance = eigrp_calculate_metrics(eigrp, metric); | |
297 | pe->req_action |= EIGRP_FSM_NEED_UPDATE; | |
298 | eigrp_prefix_entry_add(eigrp->topology_table, pe); | |
299 | listnode_add(eigrp->topology_changes_internalIPV4, pe); | |
d62a17ae | 300 | |
0da93ecf | 301 | eigrp_nexthop_entry_add(eigrp, pe, ne); |
d62a17ae | 302 | |
348addb4 DS |
303 | for (ALL_LIST_ELEMENTS(eigrp->eiflist, node, nnode, ei2)) { |
304 | eigrp_update_send(ei2); | |
305 | } | |
306 | ||
307 | pe->req_action &= ~EIGRP_FSM_NEED_UPDATE; | |
308 | listnode_delete(eigrp->topology_changes_internalIPV4, pe); | |
309 | } else { | |
310 | struct eigrp_fsm_action_message msg; | |
311 | ||
312 | ne->prefix = pe; | |
0da93ecf | 313 | eigrp_nexthop_entry_add(eigrp, pe, ne); |
348addb4 DS |
314 | |
315 | msg.packet_type = EIGRP_OPC_UPDATE; | |
316 | msg.eigrp = eigrp; | |
317 | msg.data_type = EIGRP_CONNECTED; | |
318 | msg.adv_router = NULL; | |
319 | msg.entry = ne; | |
320 | msg.prefix = pe; | |
321 | ||
322 | eigrp_fsm_event(&msg); | |
323 | } | |
d62a17ae | 324 | |
325 | return 1; | |
7f57883e DS |
326 | } |
327 | ||
d62a17ae | 328 | int eigrp_if_down(struct eigrp_interface *ei) |
7f57883e | 329 | { |
d62a17ae | 330 | struct listnode *node, *nnode; |
331 | struct eigrp_neighbor *nbr; | |
7f57883e | 332 | |
d62a17ae | 333 | if (ei == NULL) |
334 | return 0; | |
7f57883e | 335 | |
d62a17ae | 336 | /* Shutdown packet reception and sending */ |
337 | if (ei->t_hello) | |
338 | THREAD_OFF(ei->t_hello); | |
7f57883e | 339 | |
d62a17ae | 340 | eigrp_if_stream_unset(ei); |
7f57883e | 341 | |
d62a17ae | 342 | /*Set infinite metrics to routes learned by this interface and start |
343 | * query process*/ | |
344 | for (ALL_LIST_ELEMENTS(ei->nbrs, node, nnode, nbr)) { | |
345 | eigrp_nbr_delete(nbr); | |
346 | } | |
7f57883e | 347 | |
d62a17ae | 348 | return 1; |
7f57883e DS |
349 | } |
350 | ||
d62a17ae | 351 | void eigrp_if_stream_set(struct eigrp_interface *ei) |
7f57883e | 352 | { |
d62a17ae | 353 | /* set output fifo queue. */ |
354 | if (ei->obuf == NULL) | |
355 | ei->obuf = eigrp_fifo_new(); | |
7f57883e DS |
356 | } |
357 | ||
d62a17ae | 358 | void eigrp_if_stream_unset(struct eigrp_interface *ei) |
7f57883e | 359 | { |
d62a17ae | 360 | struct eigrp *eigrp = ei->eigrp; |
361 | ||
c45db77d DS |
362 | if (ei->on_write_q) { |
363 | listnode_delete(eigrp->oi_write_q, ei); | |
364 | if (list_isempty(eigrp->oi_write_q)) | |
365 | thread_cancel(eigrp->t_write); | |
366 | ei->on_write_q = 0; | |
d62a17ae | 367 | } |
7f57883e DS |
368 | } |
369 | ||
b748db67 DS |
370 | bool eigrp_if_is_passive(struct eigrp_interface *ei) |
371 | { | |
372 | if (ei->params.passive_interface == EIGRP_IF_ACTIVE) | |
373 | return false; | |
374 | ||
375 | if (ei->eigrp->passive_interface_default == EIGRP_IF_ACTIVE) | |
376 | return false; | |
377 | ||
378 | return true; | |
379 | } | |
380 | ||
d62a17ae | 381 | void eigrp_if_set_multicast(struct eigrp_interface *ei) |
7f57883e | 382 | { |
b748db67 | 383 | if (!eigrp_if_is_passive(ei)) { |
d62a17ae | 384 | /* The interface should belong to the EIGRP-all-routers group. |
385 | */ | |
b748db67 | 386 | if (!ei->member_allrouters |
b245781a | 387 | && (eigrp_if_add_allspfrouters(ei->eigrp, &ei->address, |
d62a17ae | 388 | ei->ifp->ifindex) |
389 | >= 0)) | |
390 | /* Set the flag only if the system call to join | |
391 | * succeeded. */ | |
b748db67 | 392 | ei->member_allrouters = true; |
d62a17ae | 393 | } else { |
394 | /* The interface should NOT belong to the EIGRP-all-routers | |
395 | * group. */ | |
b748db67 | 396 | if (ei->member_allrouters) { |
d62a17ae | 397 | /* Only actually drop if this is the last reference */ |
b245781a | 398 | eigrp_if_drop_allspfrouters(ei->eigrp, &ei->address, |
b748db67 | 399 | ei->ifp->ifindex); |
d62a17ae | 400 | /* Unset the flag regardless of whether the system call |
401 | to leave | |
402 | the group succeeded, since it's much safer to assume | |
403 | that | |
404 | we are not a member. */ | |
b748db67 | 405 | ei->member_allrouters = false; |
d62a17ae | 406 | } |
407 | } | |
7f57883e DS |
408 | } |
409 | ||
d7c0a89a | 410 | uint8_t eigrp_default_iftype(struct interface *ifp) |
7f57883e | 411 | { |
d62a17ae | 412 | if (if_is_pointopoint(ifp)) |
413 | return EIGRP_IFTYPE_POINTOPOINT; | |
414 | else if (if_is_loopback(ifp)) | |
415 | return EIGRP_IFTYPE_LOOPBACK; | |
416 | else | |
417 | return EIGRP_IFTYPE_BROADCAST; | |
7f57883e DS |
418 | } |
419 | ||
996c9314 | 420 | void eigrp_if_free(struct eigrp_interface *ei, int source) |
7f57883e | 421 | { |
476a1469 | 422 | struct prefix dest_addr; |
d62a17ae | 423 | struct eigrp_prefix_entry *pe; |
e9449961 | 424 | struct eigrp *eigrp = ei->eigrp; |
0bf75bd5 | 425 | |
d62a17ae | 426 | if (source == INTERFACE_DOWN_BY_VTY) { |
427 | THREAD_OFF(ei->t_hello); | |
428 | eigrp_hello_send(ei, EIGRP_HELLO_GRACEFUL_SHUTDOWN, NULL); | |
429 | } | |
430 | ||
b245781a | 431 | dest_addr = ei->address; |
476a1469 | 432 | apply_mask(&dest_addr); |
d62a17ae | 433 | pe = eigrp_topology_table_lookup_ipv4(eigrp->topology_table, |
434 | &dest_addr); | |
435 | if (pe) | |
0da93ecf | 436 | eigrp_prefix_entry_delete(eigrp, eigrp->topology_table, pe); |
d62a17ae | 437 | |
438 | eigrp_if_down(ei); | |
439 | ||
d62a17ae | 440 | listnode_delete(ei->eigrp->eiflist, ei); |
7f57883e DS |
441 | } |
442 | ||
443 | /* Simulate down/up on the interface. This is needed, for example, when | |
f9e5c9ca | 444 | the MTU changes. */ |
d62a17ae | 445 | void eigrp_if_reset(struct interface *ifp) |
7f57883e | 446 | { |
b748db67 | 447 | struct eigrp_interface *ei = ifp->info; |
7f57883e | 448 | |
b748db67 DS |
449 | if (!ei) |
450 | return; | |
7f57883e | 451 | |
b748db67 DS |
452 | eigrp_if_down(ei); |
453 | eigrp_if_up(ei); | |
7f57883e DS |
454 | } |
455 | ||
d62a17ae | 456 | struct eigrp_interface *eigrp_if_lookup_by_local_addr(struct eigrp *eigrp, |
457 | struct interface *ifp, | |
458 | struct in_addr address) | |
7f57883e | 459 | { |
d62a17ae | 460 | struct listnode *node; |
461 | struct eigrp_interface *ei; | |
7f57883e | 462 | |
d62a17ae | 463 | for (ALL_LIST_ELEMENTS_RO(eigrp->eiflist, node, ei)) { |
464 | if (ifp && ei->ifp != ifp) | |
465 | continue; | |
7f57883e | 466 | |
b245781a | 467 | if (IPV4_ADDR_SAME(&address, &ei->address.u.prefix4)) |
d62a17ae | 468 | return ei; |
469 | } | |
7f57883e | 470 | |
d62a17ae | 471 | return NULL; |
7f57883e DS |
472 | } |
473 | ||
474 | /** | |
475 | * @fn eigrp_if_lookup_by_name | |
476 | * | |
477 | * @param[in] eigrp EIGRP process | |
478 | * @param[in] if_name Name of the interface | |
479 | * | |
480 | * @return struct eigrp_interface * | |
481 | * | |
482 | * @par | |
483 | * Function is used for lookup interface by name. | |
484 | */ | |
d62a17ae | 485 | struct eigrp_interface *eigrp_if_lookup_by_name(struct eigrp *eigrp, |
486 | const char *if_name) | |
7f57883e | 487 | { |
d62a17ae | 488 | struct eigrp_interface *ei; |
489 | struct listnode *node; | |
490 | ||
491 | /* iterate over all eigrp interfaces */ | |
492 | for (ALL_LIST_ELEMENTS_RO(eigrp->eiflist, node, ei)) { | |
493 | /* compare int name with eigrp interface's name */ | |
494 | if (strcmp(ei->ifp->name, if_name) == 0) { | |
495 | return ei; | |
496 | } | |
497 | } | |
498 | ||
499 | return NULL; | |
7f57883e DS |
500 | } |
501 | ||
d7c0a89a | 502 | uint32_t eigrp_bandwidth_to_scaled(uint32_t bandwidth) |
7f57883e | 503 | { |
d62a17ae | 504 | uint64_t temp_bandwidth = (256ull * 10000000) / bandwidth; |
7f57883e | 505 | |
d62a17ae | 506 | temp_bandwidth = temp_bandwidth < EIGRP_MAX_METRIC ? temp_bandwidth |
507 | : EIGRP_MAX_METRIC; | |
7f57883e | 508 | |
d7c0a89a | 509 | return (uint32_t)temp_bandwidth; |
7f57883e DS |
510 | } |
511 | ||
d7c0a89a | 512 | uint32_t eigrp_scaled_to_bandwidth(uint32_t scaled) |
7f57883e | 513 | { |
d62a17ae | 514 | uint64_t temp_scaled = scaled * (256ull * 10000000); |
7f57883e | 515 | |
d62a17ae | 516 | temp_scaled = |
517 | temp_scaled < EIGRP_MAX_METRIC ? temp_scaled : EIGRP_MAX_METRIC; | |
7f57883e | 518 | |
d7c0a89a | 519 | return (uint32_t)temp_scaled; |
7f57883e DS |
520 | } |
521 | ||
d7c0a89a | 522 | uint32_t eigrp_delay_to_scaled(uint32_t delay) |
7f57883e | 523 | { |
d62a17ae | 524 | return delay * 256; |
7f57883e DS |
525 | } |
526 | ||
d7c0a89a | 527 | uint32_t eigrp_scaled_to_delay(uint32_t scaled) |
7f57883e | 528 | { |
d62a17ae | 529 | return scaled / 256; |
7f57883e | 530 | } |