]> git.proxmox.com Git - mirror_frr.git/blame - eigrpd/eigrp_interface.c
Merge pull request #1037 from donaldsharp/eigrp_split_horizon
[mirror_frr.git] / eigrpd / eigrp_interface.c
CommitLineData
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"
7f57883e 57
d62a17ae 58static void eigrp_delete_from_if(struct interface *, struct eigrp_interface *);
7f57883e 59
d62a17ae 60static void eigrp_add_to_if(struct interface *ifp, struct eigrp_interface *ei)
7f57883e 61{
d62a17ae 62 struct route_node *rn;
63 struct prefix p;
64
65 p = *ei->address;
66 p.prefixlen = IPV4_MAX_PREFIXLEN;
67
68 rn = route_node_get(IF_OIFS(ifp), &p);
69 /* rn->info should either be NULL or equal to this ei
70 * as route_node_get may return an existing node
71 */
72 assert(!rn->info || rn->info == ei);
73 rn->info = ei;
7f57883e
DS
74}
75
d62a17ae 76struct eigrp_interface *eigrp_if_new(struct eigrp *eigrp, struct interface *ifp,
77 struct prefix *p)
7f57883e 78{
d62a17ae 79 struct eigrp_interface *ei;
80 int i;
7f57883e 81
d62a17ae 82 if ((ei = eigrp_if_table_lookup(ifp, p)) == NULL) {
83 ei = XCALLOC(MTYPE_EIGRP_IF, sizeof(struct eigrp_interface));
84 memset(ei, 0, sizeof(struct eigrp_interface));
85 } else
86 return ei;
7f57883e 87
d62a17ae 88 /* Set zebra interface pointer. */
89 ei->ifp = ifp;
90 ei->address = p;
7f57883e 91
d62a17ae 92 eigrp_add_to_if(ifp, ei);
93 listnode_add(eigrp->eiflist, ei);
7f57883e 94
d62a17ae 95 ei->type = EIGRP_IFTYPE_BROADCAST;
7f57883e 96
d62a17ae 97 /* Initialize neighbor list. */
98 ei->nbrs = list_new();
7f57883e 99
d62a17ae 100 ei->crypt_seqnum = time(NULL);
7f57883e 101
d62a17ae 102 /* Initialize lists */
103 for (i = 0; i < EIGRP_FILTER_MAX; i++) {
104 ei->list[i] = NULL;
105 ei->prefix[i] = NULL;
106 ei->routemap[i] = NULL;
107 }
7f57883e 108
d62a17ae 109 return ei;
7f57883e
DS
110}
111
112/* lookup ei for specified prefix/ifp */
d62a17ae 113struct eigrp_interface *eigrp_if_table_lookup(struct interface *ifp,
114 struct prefix *prefix)
7f57883e 115{
d62a17ae 116 struct prefix p;
117 struct route_node *rn;
118 struct eigrp_interface *rninfo = NULL;
7f57883e 119
d62a17ae 120 p = *prefix;
121 p.prefixlen = IPV4_MAX_PREFIXLEN;
7f57883e 122
d62a17ae 123 /* route_node_get implicitly locks */
124 if ((rn = route_node_lookup(IF_OIFS(ifp), &p))) {
125 rninfo = (struct eigrp_interface *)rn->info;
126 route_unlock_node(rn);
127 }
7f57883e 128
d62a17ae 129 return rninfo;
7f57883e
DS
130}
131
d62a17ae 132int eigrp_if_delete_hook(struct interface *ifp)
7f57883e 133{
d62a17ae 134 struct route_node *rn;
7f57883e 135
d62a17ae 136 route_table_finish(IF_OIFS(ifp));
7f57883e 137
d62a17ae 138 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn))
139 if (rn->info)
140 eigrp_del_if_params(rn->info);
141 route_table_finish(IF_OIFS_PARAMS(ifp));
7f57883e 142
d62a17ae 143 XFREE(MTYPE_EIGRP_IF_INFO, ifp->info);
144 ifp->info = NULL;
7f57883e 145
d62a17ae 146 return 0;
7f57883e
DS
147}
148
149struct list *eigrp_iflist;
150
d62a17ae 151void eigrp_if_init()
7f57883e 152{
d62a17ae 153 /* Initialize Zebra interface data structure. */
ce19a04a
DL
154 hook_register_prio(if_add, 0, eigrp_if_new_hook);
155 hook_register_prio(if_del, 0, eigrp_if_delete_hook);
7f57883e
DS
156}
157
d62a17ae 158int eigrp_if_new_hook(struct interface *ifp)
7f57883e 159{
d62a17ae 160 int rc = 0;
7f57883e 161
d62a17ae 162 ifp->info = XCALLOC(MTYPE_EIGRP_IF_INFO, sizeof(struct eigrp_if_info));
7f57883e 163
d62a17ae 164 IF_OIFS(ifp) = route_table_init();
165 IF_OIFS_PARAMS(ifp) = route_table_init();
7f57883e 166
d62a17ae 167 IF_DEF_PARAMS(ifp) = eigrp_new_if_params();
7f57883e 168
d62a17ae 169 SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_hello);
170 IF_DEF_PARAMS(ifp)->v_hello = (u_int32_t)EIGRP_HELLO_INTERVAL_DEFAULT;
7f57883e 171
d62a17ae 172 SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait);
173 IF_DEF_PARAMS(ifp)->v_wait = (u_int16_t)EIGRP_HOLD_INTERVAL_DEFAULT;
7f57883e 174
d62a17ae 175 SET_IF_PARAM(IF_DEF_PARAMS(ifp), bandwidth);
176 IF_DEF_PARAMS(ifp)->bandwidth = (u_int32_t)EIGRP_BANDWIDTH_DEFAULT;
7f57883e 177
d62a17ae 178 SET_IF_PARAM(IF_DEF_PARAMS(ifp), delay);
179 IF_DEF_PARAMS(ifp)->delay = (u_int32_t)EIGRP_DELAY_DEFAULT;
7f57883e 180
d62a17ae 181 SET_IF_PARAM(IF_DEF_PARAMS(ifp), reliability);
182 IF_DEF_PARAMS(ifp)->reliability = (u_char)EIGRP_RELIABILITY_DEFAULT;
7f57883e 183
d62a17ae 184 SET_IF_PARAM(IF_DEF_PARAMS(ifp), load);
185 IF_DEF_PARAMS(ifp)->load = (u_char)EIGRP_LOAD_DEFAULT;
7f57883e 186
d62a17ae 187 SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type);
188 IF_DEF_PARAMS(ifp)->auth_type = EIGRP_AUTH_TYPE_NONE;
7f57883e 189
d62a17ae 190 SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_keychain);
191 IF_DEF_PARAMS(ifp)->auth_keychain = NULL;
7f57883e 192
d62a17ae 193 return rc;
7f57883e
DS
194}
195
d62a17ae 196struct eigrp_if_params *eigrp_new_if_params(void)
7f57883e 197{
d62a17ae 198 struct eigrp_if_params *eip;
199
200 eip = XCALLOC(MTYPE_EIGRP_IF_PARAMS, sizeof(struct eigrp_if_params));
201 if (!eip)
202 return NULL;
203
204 UNSET_IF_PARAM(eip, passive_interface);
205 UNSET_IF_PARAM(eip, v_hello);
206 UNSET_IF_PARAM(eip, v_wait);
207 UNSET_IF_PARAM(eip, bandwidth);
208 UNSET_IF_PARAM(eip, delay);
209 UNSET_IF_PARAM(eip, reliability);
210 UNSET_IF_PARAM(eip, load);
211 UNSET_IF_PARAM(eip, auth_keychain);
212 UNSET_IF_PARAM(eip, auth_type);
213
214 return eip;
7f57883e
DS
215}
216
d62a17ae 217void eigrp_del_if_params(struct eigrp_if_params *eip)
7f57883e 218{
d62a17ae 219 if (eip->auth_keychain)
220 free(eip->auth_keychain);
7f57883e 221
d62a17ae 222 XFREE(MTYPE_EIGRP_IF_PARAMS, eip);
7f57883e
DS
223}
224
d62a17ae 225struct eigrp_if_params *eigrp_lookup_if_params(struct interface *ifp,
226 struct in_addr addr)
7f57883e 227{
0ffa8407 228 struct prefix p;
d62a17ae 229 struct route_node *rn;
7f57883e 230
d62a17ae 231 p.family = AF_INET;
232 p.prefixlen = IPV4_MAX_PREFIXLEN;
0ffa8407 233 p.u.prefix4 = addr;
7f57883e 234
0ffa8407 235 rn = route_node_lookup(IF_OIFS_PARAMS(ifp), &p);
7f57883e 236
d62a17ae 237 if (rn) {
238 route_unlock_node(rn);
239 return rn->info;
240 }
7f57883e 241
d62a17ae 242 return NULL;
7f57883e
DS
243}
244
d62a17ae 245int eigrp_if_up(struct eigrp_interface *ei)
7f57883e 246{
d62a17ae 247 struct eigrp_prefix_entry *pe;
248 struct eigrp_neighbor_entry *ne;
249 struct eigrp_metrics metric;
250 struct eigrp_interface *ei2;
251 struct listnode *node, *nnode;
252 struct eigrp *eigrp = eigrp_lookup();
253
254 if (ei == NULL)
255 return 0;
256
257 if (eigrp != NULL)
258 eigrp_adjust_sndbuflen(eigrp, ei->ifp->mtu);
259 else
260 zlog_warn("%s: eigrp_lookup () returned NULL", __func__);
261 eigrp_if_stream_set(ei);
262
263 /* Set multicast memberships appropriately for new state. */
264 eigrp_if_set_multicast(ei);
265
266 thread_add_event(master, eigrp_hello_timer, ei, (1), NULL);
267
268 /*Prepare metrics*/
b1968f83 269 metric.bandwidth =
d62a17ae 270 eigrp_bandwidth_to_scaled(EIGRP_IF_PARAM(ei, bandwidth));
271 metric.delay = eigrp_delay_to_scaled(EIGRP_IF_PARAM(ei, delay));
272 metric.load = EIGRP_IF_PARAM(ei, load);
273 metric.reliability = EIGRP_IF_PARAM(ei, reliability);
274 metric.mtu[0] = 0xDC;
275 metric.mtu[1] = 0x05;
276 metric.mtu[2] = 0x00;
277 metric.hop_count = 0;
278 metric.flags = 0;
279 metric.tag = 0;
280
281 /*Add connected entry to topology table*/
282
348addb4
DS
283 ne = eigrp_neighbor_entry_new();
284 ne->ei = ei;
285 ne->reported_metric = metric;
286 ne->total_metric = metric;
287 ne->distance = eigrp_calculate_metrics(eigrp, metric);
288 ne->reported_distance = 0;
289 ne->adv_router = eigrp->neighbor_self;
290 ne->flags = EIGRP_NEIGHBOR_ENTRY_SUCCESSOR_FLAG;
291
02b45998 292 struct prefix dest_addr;
d62a17ae 293
294 dest_addr.family = AF_INET;
02b45998 295 dest_addr.u.prefix4 = ei->connected->address->u.prefix4;
d62a17ae 296 dest_addr.prefixlen = ei->connected->address->prefixlen;
02b45998 297 apply_mask(&dest_addr);
d62a17ae 298 pe = eigrp_topology_table_lookup_ipv4(eigrp->topology_table,
476a1469 299 &dest_addr);
d62a17ae 300
301 if (pe == NULL) {
302 pe = eigrp_prefix_entry_new();
303 pe->serno = eigrp->serno;
02b45998
DS
304 pe->destination = (struct prefix *)prefix_ipv4_new();
305 prefix_copy(pe->destination, &dest_addr);
d62a17ae 306 pe->af = AF_INET;
307 pe->nt = EIGRP_TOPOLOGY_TYPE_CONNECTED;
308
348addb4 309 ne->prefix = pe;
d62a17ae 310 pe->state = EIGRP_FSM_STATE_PASSIVE;
311 pe->fdistance = eigrp_calculate_metrics(eigrp, metric);
312 pe->req_action |= EIGRP_FSM_NEED_UPDATE;
313 eigrp_prefix_entry_add(eigrp->topology_table, pe);
314 listnode_add(eigrp->topology_changes_internalIPV4, pe);
d62a17ae 315
348addb4 316 eigrp_neighbor_entry_add(pe, ne);
d62a17ae 317
348addb4
DS
318 for (ALL_LIST_ELEMENTS(eigrp->eiflist, node, nnode, ei2)) {
319 eigrp_update_send(ei2);
320 }
321
322 pe->req_action &= ~EIGRP_FSM_NEED_UPDATE;
323 listnode_delete(eigrp->topology_changes_internalIPV4, pe);
324 } else {
325 struct eigrp_fsm_action_message msg;
326
327 ne->prefix = pe;
328 eigrp_neighbor_entry_add(pe, ne);
329
330 msg.packet_type = EIGRP_OPC_UPDATE;
331 msg.eigrp = eigrp;
332 msg.data_type = EIGRP_CONNECTED;
333 msg.adv_router = NULL;
334 msg.entry = ne;
335 msg.prefix = pe;
336
337 eigrp_fsm_event(&msg);
338 }
d62a17ae 339
340 return 1;
7f57883e
DS
341}
342
d62a17ae 343int eigrp_if_down(struct eigrp_interface *ei)
7f57883e 344{
d62a17ae 345 struct listnode *node, *nnode;
346 struct eigrp_neighbor *nbr;
7f57883e 347
d62a17ae 348 if (ei == NULL)
349 return 0;
7f57883e 350
d62a17ae 351 /* Shutdown packet reception and sending */
352 if (ei->t_hello)
353 THREAD_OFF(ei->t_hello);
7f57883e 354
d62a17ae 355 eigrp_if_stream_unset(ei);
7f57883e 356
d62a17ae 357 /*Set infinite metrics to routes learned by this interface and start
358 * query process*/
359 for (ALL_LIST_ELEMENTS(ei->nbrs, node, nnode, nbr)) {
360 eigrp_nbr_delete(nbr);
361 }
7f57883e 362
d62a17ae 363 return 1;
7f57883e
DS
364}
365
d62a17ae 366void eigrp_if_stream_set(struct eigrp_interface *ei)
7f57883e 367{
d62a17ae 368 /* set output fifo queue. */
369 if (ei->obuf == NULL)
370 ei->obuf = eigrp_fifo_new();
7f57883e
DS
371}
372
d62a17ae 373void eigrp_if_stream_unset(struct eigrp_interface *ei)
7f57883e 374{
d62a17ae 375 struct eigrp *eigrp = ei->eigrp;
376
377 if (ei->obuf) {
378 eigrp_fifo_free(ei->obuf);
379 ei->obuf = NULL;
380
381 if (ei->on_write_q) {
382 listnode_delete(eigrp->oi_write_q, ei);
383 if (list_isempty(eigrp->oi_write_q))
384 thread_cancel(eigrp->t_write);
385 ei->on_write_q = 0;
386 }
387 }
7f57883e
DS
388}
389
d62a17ae 390void eigrp_if_set_multicast(struct eigrp_interface *ei)
7f57883e 391{
d62a17ae 392 if ((EIGRP_IF_PASSIVE_STATUS(ei) == EIGRP_IF_ACTIVE)) {
393 /* The interface should belong to the EIGRP-all-routers group.
394 */
395 if (!EI_MEMBER_CHECK(ei, MEMBER_ALLROUTERS)
396 && (eigrp_if_add_allspfrouters(ei->eigrp, ei->address,
397 ei->ifp->ifindex)
398 >= 0))
399 /* Set the flag only if the system call to join
400 * succeeded. */
401 EI_MEMBER_JOINED(ei, MEMBER_ALLROUTERS);
402 } else {
403 /* The interface should NOT belong to the EIGRP-all-routers
404 * group. */
405 if (EI_MEMBER_CHECK(ei, MEMBER_ALLROUTERS)) {
406 /* Only actually drop if this is the last reference */
407 if (EI_MEMBER_COUNT(ei, MEMBER_ALLROUTERS) == 1)
408 eigrp_if_drop_allspfrouters(ei->eigrp,
409 ei->address,
410 ei->ifp->ifindex);
411 /* Unset the flag regardless of whether the system call
412 to leave
413 the group succeeded, since it's much safer to assume
414 that
415 we are not a member. */
416 EI_MEMBER_LEFT(ei, MEMBER_ALLROUTERS);
417 }
418 }
7f57883e
DS
419}
420
d62a17ae 421u_char eigrp_default_iftype(struct interface *ifp)
7f57883e 422{
d62a17ae 423 if (if_is_pointopoint(ifp))
424 return EIGRP_IFTYPE_POINTOPOINT;
425 else if (if_is_loopback(ifp))
426 return EIGRP_IFTYPE_LOOPBACK;
427 else
428 return EIGRP_IFTYPE_BROADCAST;
7f57883e
DS
429}
430
d62a17ae 431void eigrp_if_free(struct eigrp_interface *ei, int source)
7f57883e 432{
476a1469 433 struct prefix dest_addr;
d62a17ae 434 struct eigrp_prefix_entry *pe;
435 struct eigrp *eigrp = eigrp_lookup();
436
437 if (source == INTERFACE_DOWN_BY_VTY) {
438 THREAD_OFF(ei->t_hello);
439 eigrp_hello_send(ei, EIGRP_HELLO_GRACEFUL_SHUTDOWN, NULL);
440 }
441
476a1469
DS
442 dest_addr = *ei->connected->address;
443 apply_mask(&dest_addr);
d62a17ae 444 pe = eigrp_topology_table_lookup_ipv4(eigrp->topology_table,
445 &dest_addr);
446 if (pe)
447 eigrp_prefix_entry_delete(eigrp->topology_table, pe);
448
449 eigrp_if_down(ei);
450
451 list_delete(ei->nbrs);
452 eigrp_delete_from_if(ei->ifp, ei);
453 listnode_delete(ei->eigrp->eiflist, ei);
454
455 thread_cancel_event(master, ei);
456
457 memset(ei, 0, sizeof(*ei));
458 XFREE(MTYPE_EIGRP_IF, ei);
7f57883e
DS
459}
460
d62a17ae 461static void eigrp_delete_from_if(struct interface *ifp,
462 struct eigrp_interface *ei)
7f57883e 463{
d62a17ae 464 struct route_node *rn;
465 struct prefix p;
466
467 p = *ei->address;
468 p.prefixlen = IPV4_MAX_PREFIXLEN;
469
470 rn = route_node_lookup(IF_OIFS(ei->ifp), &p);
471 assert(rn);
472 assert(rn->info);
473 rn->info = NULL;
474 route_unlock_node(rn);
475 route_unlock_node(rn);
7f57883e
DS
476}
477
478/* Simulate down/up on the interface. This is needed, for example, when
f9e5c9ca 479 the MTU changes. */
d62a17ae 480void eigrp_if_reset(struct interface *ifp)
7f57883e 481{
d62a17ae 482 struct route_node *rn;
7f57883e 483
d62a17ae 484 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
485 struct eigrp_interface *ei;
7f57883e 486
d62a17ae 487 if ((ei = rn->info) == NULL)
488 continue;
7f57883e 489
d62a17ae 490 eigrp_if_down(ei);
491 eigrp_if_up(ei);
492 }
7f57883e
DS
493}
494
d62a17ae 495struct eigrp_interface *eigrp_if_lookup_by_local_addr(struct eigrp *eigrp,
496 struct interface *ifp,
497 struct in_addr address)
7f57883e 498{
d62a17ae 499 struct listnode *node;
500 struct eigrp_interface *ei;
7f57883e 501
d62a17ae 502 for (ALL_LIST_ELEMENTS_RO(eigrp->eiflist, node, ei)) {
503 if (ifp && ei->ifp != ifp)
504 continue;
7f57883e 505
d62a17ae 506 if (IPV4_ADDR_SAME(&address, &ei->address->u.prefix4))
507 return ei;
508 }
7f57883e 509
d62a17ae 510 return NULL;
7f57883e
DS
511}
512
513/**
514 * @fn eigrp_if_lookup_by_name
515 *
516 * @param[in] eigrp EIGRP process
517 * @param[in] if_name Name of the interface
518 *
519 * @return struct eigrp_interface *
520 *
521 * @par
522 * Function is used for lookup interface by name.
523 */
d62a17ae 524struct eigrp_interface *eigrp_if_lookup_by_name(struct eigrp *eigrp,
525 const char *if_name)
7f57883e 526{
d62a17ae 527 struct eigrp_interface *ei;
528 struct listnode *node;
529
530 /* iterate over all eigrp interfaces */
531 for (ALL_LIST_ELEMENTS_RO(eigrp->eiflist, node, ei)) {
532 /* compare int name with eigrp interface's name */
533 if (strcmp(ei->ifp->name, if_name) == 0) {
534 return ei;
535 }
536 }
537
538 return NULL;
7f57883e
DS
539}
540
541/* determine receiving interface by ifp and source address */
d62a17ae 542struct eigrp_interface *eigrp_if_lookup_recv_if(struct eigrp *eigrp,
543 struct in_addr src,
544 struct interface *ifp)
7f57883e 545{
d62a17ae 546 struct route_node *rn;
0ffa8407 547 struct prefix addr;
d62a17ae 548 struct eigrp_interface *ei, *match;
7f57883e 549
d62a17ae 550 addr.family = AF_INET;
0ffa8407 551 addr.u.prefix4 = src;
d62a17ae 552 addr.prefixlen = IPV4_MAX_BITLEN;
7f57883e 553
d62a17ae 554 match = NULL;
7f57883e 555
d62a17ae 556 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
557 ei = rn->info;
7f57883e 558
d62a17ae 559 if (!ei) /* oi can be NULL for PtP aliases */
560 continue;
7f57883e 561
d62a17ae 562 if (if_is_loopback(ei->ifp))
563 continue;
7f57883e 564
d62a17ae 565 if (prefix_match(CONNECTED_PREFIX(ei->connected),
0ffa8407 566 &addr)) {
9d303b37
DL
567 if ((match == NULL) || (match->address->prefixlen
568 < ei->address->prefixlen))
d62a17ae 569 match = ei;
570 }
571 }
7f57883e 572
d62a17ae 573 return match;
7f57883e
DS
574}
575
d62a17ae 576u_int32_t eigrp_bandwidth_to_scaled(u_int32_t bandwidth)
7f57883e 577{
d62a17ae 578 uint64_t temp_bandwidth = (256ull * 10000000) / bandwidth;
7f57883e 579
d62a17ae 580 temp_bandwidth = temp_bandwidth < EIGRP_MAX_METRIC ? temp_bandwidth
581 : EIGRP_MAX_METRIC;
7f57883e 582
d62a17ae 583 return (u_int32_t)temp_bandwidth;
7f57883e
DS
584}
585
d62a17ae 586u_int32_t eigrp_scaled_to_bandwidth(u_int32_t scaled)
7f57883e 587{
d62a17ae 588 uint64_t temp_scaled = scaled * (256ull * 10000000);
7f57883e 589
d62a17ae 590 temp_scaled =
591 temp_scaled < EIGRP_MAX_METRIC ? temp_scaled : EIGRP_MAX_METRIC;
7f57883e 592
d62a17ae 593 return (u_int32_t)temp_scaled;
7f57883e
DS
594}
595
d62a17ae 596u_int32_t eigrp_delay_to_scaled(u_int32_t delay)
7f57883e 597{
d62a17ae 598 return delay * 256;
7f57883e
DS
599}
600
d62a17ae 601u_int32_t eigrp_scaled_to_delay(u_int32_t scaled)
7f57883e 602{
d62a17ae 603 return scaled / 256;
7f57883e 604}