]>
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 | |
85d25587 DS |
102 | ei->curr_bandwidth = ifp->bandwidth; |
103 | ei->curr_mtu = ifp->mtu; | |
104 | ||
b748db67 | 105 | return ei; |
7f57883e DS |
106 | } |
107 | ||
d62a17ae | 108 | int eigrp_if_delete_hook(struct interface *ifp) |
7f57883e | 109 | { |
b748db67 DS |
110 | struct eigrp_interface *ei = ifp->info; |
111 | struct eigrp *eigrp; | |
7f57883e | 112 | |
b748db67 DS |
113 | if (!ei) |
114 | return 0; | |
115 | ||
6a154c88 | 116 | list_delete(&ei->nbrs); |
7f57883e | 117 | |
b748db67 DS |
118 | eigrp = ei->eigrp; |
119 | listnode_delete(eigrp->eiflist, ei); | |
7f57883e | 120 | |
c45db77d DS |
121 | eigrp_fifo_free(ei->obuf); |
122 | ||
d62a17ae | 123 | XFREE(MTYPE_EIGRP_IF_INFO, ifp->info); |
7f57883e | 124 | |
d62a17ae | 125 | return 0; |
7f57883e DS |
126 | } |
127 | ||
138c5a74 DS |
128 | static int eigrp_ifp_create(struct interface *ifp) |
129 | { | |
ef7bd2a3 DS |
130 | struct eigrp_interface *ei = ifp->info; |
131 | ||
132 | if (!ei) | |
133 | return 0; | |
134 | ||
135 | ei->params.type = eigrp_default_iftype(ifp); | |
136 | ||
137 | eigrp_if_update(ifp); | |
138 | ||
138c5a74 DS |
139 | return 0; |
140 | } | |
141 | ||
142 | static int eigrp_ifp_up(struct interface *ifp) | |
143 | { | |
85d25587 | 144 | struct eigrp_interface *ei = ifp->info; |
ddbf3e60 DS |
145 | |
146 | if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE)) | |
147 | zlog_debug("Zebra: Interface[%s] state change to up.", | |
148 | ifp->name); | |
149 | ||
85d25587 DS |
150 | if (!ei) |
151 | return 0; | |
152 | ||
153 | if (ei->curr_bandwidth != ifp->bandwidth) { | |
154 | if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE)) | |
155 | zlog_debug( | |
156 | "Zebra: Interface[%s] bandwidth change %d -> %d.", | |
157 | ifp->name, ei->curr_bandwidth, | |
158 | ifp->bandwidth); | |
159 | ||
160 | ei->curr_bandwidth = ifp->bandwidth; | |
161 | // eigrp_if_recalculate_output_cost (ifp); | |
162 | } | |
163 | ||
164 | if (ei->curr_mtu != ifp->mtu) { | |
165 | if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE)) | |
166 | zlog_debug( | |
167 | "Zebra: Interface[%s] MTU change %u -> %u.", | |
168 | ifp->name, ei->curr_mtu, ifp->mtu); | |
169 | ||
170 | ei->curr_mtu = ifp->mtu; | |
171 | /* Must reset the interface (simulate down/up) when MTU | |
172 | * changes. */ | |
173 | eigrp_if_reset(ifp); | |
174 | return 0; | |
175 | } | |
176 | ||
177 | eigrp_if_up(ifp->info); | |
ddbf3e60 | 178 | |
138c5a74 DS |
179 | return 0; |
180 | } | |
181 | ||
182 | static int eigrp_ifp_down(struct interface *ifp) | |
183 | { | |
b0b69e59 DS |
184 | if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE)) |
185 | zlog_debug("Zebra: Interface[%s] state change to down.", | |
186 | ifp->name); | |
187 | ||
188 | if (ifp->info) | |
189 | eigrp_if_down(ifp->info); | |
190 | ||
138c5a74 DS |
191 | return 0; |
192 | } | |
193 | ||
194 | static int eigrp_ifp_destroy(struct interface *ifp) | |
195 | { | |
3c3c3252 DS |
196 | if (if_is_up(ifp)) |
197 | zlog_warn("Zebra: got delete of %s, but interface is still up", | |
198 | ifp->name); | |
199 | ||
200 | if (IS_DEBUG_EIGRP(zebra, ZEBRA_INTERFACE)) | |
201 | zlog_debug( | |
202 | "Zebra: interface delete %s index %d flags %llx metric %d mtu %d", | |
203 | ifp->name, ifp->ifindex, (unsigned long long)ifp->flags, | |
204 | ifp->metric, ifp->mtu); | |
205 | ||
206 | if (ifp->info) | |
207 | eigrp_if_free(ifp->info, INTERFACE_DOWN_BY_ZEBRA); | |
208 | ||
138c5a74 DS |
209 | return 0; |
210 | } | |
211 | ||
7f57883e DS |
212 | struct list *eigrp_iflist; |
213 | ||
4d762f26 | 214 | void eigrp_if_init(void) |
7f57883e | 215 | { |
138c5a74 DS |
216 | if_zapi_callbacks(eigrp_ifp_create, eigrp_ifp_up, |
217 | eigrp_ifp_down, eigrp_ifp_destroy); | |
d62a17ae | 218 | /* Initialize Zebra interface data structure. */ |
996c9314 | 219 | // hook_register_prio(if_add, 0, eigrp_if_new); |
ce19a04a | 220 | hook_register_prio(if_del, 0, eigrp_if_delete_hook); |
7f57883e DS |
221 | } |
222 | ||
7f57883e | 223 | |
d62a17ae | 224 | void eigrp_del_if_params(struct eigrp_if_params *eip) |
7f57883e | 225 | { |
d62a17ae | 226 | if (eip->auth_keychain) |
227 | free(eip->auth_keychain); | |
7f57883e DS |
228 | } |
229 | ||
d62a17ae | 230 | int eigrp_if_up(struct eigrp_interface *ei) |
7f57883e | 231 | { |
d62a17ae | 232 | struct eigrp_prefix_entry *pe; |
255ab940 | 233 | struct eigrp_nexthop_entry *ne; |
d62a17ae | 234 | struct eigrp_metrics metric; |
235 | struct eigrp_interface *ei2; | |
236 | struct listnode *node, *nnode; | |
dbfd865b | 237 | struct eigrp *eigrp; |
d62a17ae | 238 | |
239 | if (ei == NULL) | |
240 | return 0; | |
241 | ||
dbfd865b DS |
242 | eigrp = ei->eigrp; |
243 | eigrp_adjust_sndbuflen(eigrp, ei->ifp->mtu); | |
244 | ||
d62a17ae | 245 | eigrp_if_stream_set(ei); |
246 | ||
247 | /* Set multicast memberships appropriately for new state. */ | |
248 | eigrp_if_set_multicast(ei); | |
249 | ||
250 | thread_add_event(master, eigrp_hello_timer, ei, (1), NULL); | |
251 | ||
252 | /*Prepare metrics*/ | |
996c9314 | 253 | metric.bandwidth = eigrp_bandwidth_to_scaled(ei->params.bandwidth); |
b748db67 DS |
254 | metric.delay = eigrp_delay_to_scaled(ei->params.delay); |
255 | metric.load = ei->params.load; | |
256 | metric.reliability = ei->params.reliability; | |
d62a17ae | 257 | metric.mtu[0] = 0xDC; |
258 | metric.mtu[1] = 0x05; | |
259 | metric.mtu[2] = 0x00; | |
260 | metric.hop_count = 0; | |
261 | metric.flags = 0; | |
262 | metric.tag = 0; | |
263 | ||
264 | /*Add connected entry to topology table*/ | |
265 | ||
255ab940 | 266 | ne = eigrp_nexthop_entry_new(); |
348addb4 DS |
267 | ne->ei = ei; |
268 | ne->reported_metric = metric; | |
269 | ne->total_metric = metric; | |
270 | ne->distance = eigrp_calculate_metrics(eigrp, metric); | |
271 | ne->reported_distance = 0; | |
272 | ne->adv_router = eigrp->neighbor_self; | |
255ab940 | 273 | ne->flags = EIGRP_NEXTHOP_ENTRY_SUCCESSOR_FLAG; |
348addb4 | 274 | |
02b45998 | 275 | struct prefix dest_addr; |
d62a17ae | 276 | |
b245781a | 277 | dest_addr = ei->address; |
02b45998 | 278 | apply_mask(&dest_addr); |
d62a17ae | 279 | pe = eigrp_topology_table_lookup_ipv4(eigrp->topology_table, |
476a1469 | 280 | &dest_addr); |
d62a17ae | 281 | |
282 | if (pe == NULL) { | |
283 | pe = eigrp_prefix_entry_new(); | |
284 | pe->serno = eigrp->serno; | |
02b45998 DS |
285 | pe->destination = (struct prefix *)prefix_ipv4_new(); |
286 | prefix_copy(pe->destination, &dest_addr); | |
d62a17ae | 287 | pe->af = AF_INET; |
288 | pe->nt = EIGRP_TOPOLOGY_TYPE_CONNECTED; | |
289 | ||
348addb4 | 290 | ne->prefix = pe; |
cd6c573c | 291 | pe->reported_metric = metric; |
d62a17ae | 292 | pe->state = EIGRP_FSM_STATE_PASSIVE; |
293 | pe->fdistance = eigrp_calculate_metrics(eigrp, metric); | |
294 | pe->req_action |= EIGRP_FSM_NEED_UPDATE; | |
295 | eigrp_prefix_entry_add(eigrp->topology_table, pe); | |
296 | listnode_add(eigrp->topology_changes_internalIPV4, pe); | |
d62a17ae | 297 | |
0da93ecf | 298 | eigrp_nexthop_entry_add(eigrp, pe, ne); |
d62a17ae | 299 | |
348addb4 DS |
300 | for (ALL_LIST_ELEMENTS(eigrp->eiflist, node, nnode, ei2)) { |
301 | eigrp_update_send(ei2); | |
302 | } | |
303 | ||
304 | pe->req_action &= ~EIGRP_FSM_NEED_UPDATE; | |
305 | listnode_delete(eigrp->topology_changes_internalIPV4, pe); | |
306 | } else { | |
307 | struct eigrp_fsm_action_message msg; | |
308 | ||
309 | ne->prefix = pe; | |
0da93ecf | 310 | eigrp_nexthop_entry_add(eigrp, pe, ne); |
348addb4 DS |
311 | |
312 | msg.packet_type = EIGRP_OPC_UPDATE; | |
313 | msg.eigrp = eigrp; | |
314 | msg.data_type = EIGRP_CONNECTED; | |
315 | msg.adv_router = NULL; | |
316 | msg.entry = ne; | |
317 | msg.prefix = pe; | |
318 | ||
319 | eigrp_fsm_event(&msg); | |
320 | } | |
d62a17ae | 321 | |
322 | return 1; | |
7f57883e DS |
323 | } |
324 | ||
d62a17ae | 325 | int eigrp_if_down(struct eigrp_interface *ei) |
7f57883e | 326 | { |
d62a17ae | 327 | struct listnode *node, *nnode; |
328 | struct eigrp_neighbor *nbr; | |
7f57883e | 329 | |
d62a17ae | 330 | if (ei == NULL) |
331 | return 0; | |
7f57883e | 332 | |
d62a17ae | 333 | /* Shutdown packet reception and sending */ |
334 | if (ei->t_hello) | |
335 | THREAD_OFF(ei->t_hello); | |
7f57883e | 336 | |
d62a17ae | 337 | eigrp_if_stream_unset(ei); |
7f57883e | 338 | |
d62a17ae | 339 | /*Set infinite metrics to routes learned by this interface and start |
340 | * query process*/ | |
341 | for (ALL_LIST_ELEMENTS(ei->nbrs, node, nnode, nbr)) { | |
342 | eigrp_nbr_delete(nbr); | |
343 | } | |
7f57883e | 344 | |
d62a17ae | 345 | return 1; |
7f57883e DS |
346 | } |
347 | ||
d62a17ae | 348 | void eigrp_if_stream_set(struct eigrp_interface *ei) |
7f57883e | 349 | { |
d62a17ae | 350 | /* set output fifo queue. */ |
351 | if (ei->obuf == NULL) | |
352 | ei->obuf = eigrp_fifo_new(); | |
7f57883e DS |
353 | } |
354 | ||
d62a17ae | 355 | void eigrp_if_stream_unset(struct eigrp_interface *ei) |
7f57883e | 356 | { |
d62a17ae | 357 | struct eigrp *eigrp = ei->eigrp; |
358 | ||
c45db77d DS |
359 | if (ei->on_write_q) { |
360 | listnode_delete(eigrp->oi_write_q, ei); | |
361 | if (list_isempty(eigrp->oi_write_q)) | |
362 | thread_cancel(eigrp->t_write); | |
363 | ei->on_write_q = 0; | |
d62a17ae | 364 | } |
7f57883e DS |
365 | } |
366 | ||
b748db67 DS |
367 | bool eigrp_if_is_passive(struct eigrp_interface *ei) |
368 | { | |
369 | if (ei->params.passive_interface == EIGRP_IF_ACTIVE) | |
370 | return false; | |
371 | ||
372 | if (ei->eigrp->passive_interface_default == EIGRP_IF_ACTIVE) | |
373 | return false; | |
374 | ||
375 | return true; | |
376 | } | |
377 | ||
d62a17ae | 378 | void eigrp_if_set_multicast(struct eigrp_interface *ei) |
7f57883e | 379 | { |
b748db67 | 380 | if (!eigrp_if_is_passive(ei)) { |
d62a17ae | 381 | /* The interface should belong to the EIGRP-all-routers group. |
382 | */ | |
b748db67 | 383 | if (!ei->member_allrouters |
b245781a | 384 | && (eigrp_if_add_allspfrouters(ei->eigrp, &ei->address, |
d62a17ae | 385 | ei->ifp->ifindex) |
386 | >= 0)) | |
387 | /* Set the flag only if the system call to join | |
388 | * succeeded. */ | |
b748db67 | 389 | ei->member_allrouters = true; |
d62a17ae | 390 | } else { |
391 | /* The interface should NOT belong to the EIGRP-all-routers | |
392 | * group. */ | |
b748db67 | 393 | if (ei->member_allrouters) { |
d62a17ae | 394 | /* Only actually drop if this is the last reference */ |
b245781a | 395 | eigrp_if_drop_allspfrouters(ei->eigrp, &ei->address, |
b748db67 | 396 | ei->ifp->ifindex); |
d62a17ae | 397 | /* Unset the flag regardless of whether the system call |
398 | to leave | |
399 | the group succeeded, since it's much safer to assume | |
400 | that | |
401 | we are not a member. */ | |
b748db67 | 402 | ei->member_allrouters = false; |
d62a17ae | 403 | } |
404 | } | |
7f57883e DS |
405 | } |
406 | ||
d7c0a89a | 407 | uint8_t eigrp_default_iftype(struct interface *ifp) |
7f57883e | 408 | { |
d62a17ae | 409 | if (if_is_pointopoint(ifp)) |
410 | return EIGRP_IFTYPE_POINTOPOINT; | |
411 | else if (if_is_loopback(ifp)) | |
412 | return EIGRP_IFTYPE_LOOPBACK; | |
413 | else | |
414 | return EIGRP_IFTYPE_BROADCAST; | |
7f57883e DS |
415 | } |
416 | ||
996c9314 | 417 | void eigrp_if_free(struct eigrp_interface *ei, int source) |
7f57883e | 418 | { |
476a1469 | 419 | struct prefix dest_addr; |
d62a17ae | 420 | struct eigrp_prefix_entry *pe; |
e9449961 | 421 | struct eigrp *eigrp = ei->eigrp; |
0bf75bd5 | 422 | |
d62a17ae | 423 | if (source == INTERFACE_DOWN_BY_VTY) { |
424 | THREAD_OFF(ei->t_hello); | |
425 | eigrp_hello_send(ei, EIGRP_HELLO_GRACEFUL_SHUTDOWN, NULL); | |
426 | } | |
427 | ||
b245781a | 428 | dest_addr = ei->address; |
476a1469 | 429 | apply_mask(&dest_addr); |
d62a17ae | 430 | pe = eigrp_topology_table_lookup_ipv4(eigrp->topology_table, |
431 | &dest_addr); | |
432 | if (pe) | |
0da93ecf | 433 | eigrp_prefix_entry_delete(eigrp, eigrp->topology_table, pe); |
d62a17ae | 434 | |
435 | eigrp_if_down(ei); | |
436 | ||
d62a17ae | 437 | listnode_delete(ei->eigrp->eiflist, ei); |
7f57883e DS |
438 | } |
439 | ||
440 | /* Simulate down/up on the interface. This is needed, for example, when | |
f9e5c9ca | 441 | the MTU changes. */ |
d62a17ae | 442 | void eigrp_if_reset(struct interface *ifp) |
7f57883e | 443 | { |
b748db67 | 444 | struct eigrp_interface *ei = ifp->info; |
7f57883e | 445 | |
b748db67 DS |
446 | if (!ei) |
447 | return; | |
7f57883e | 448 | |
b748db67 DS |
449 | eigrp_if_down(ei); |
450 | eigrp_if_up(ei); | |
7f57883e DS |
451 | } |
452 | ||
d62a17ae | 453 | struct eigrp_interface *eigrp_if_lookup_by_local_addr(struct eigrp *eigrp, |
454 | struct interface *ifp, | |
455 | struct in_addr address) | |
7f57883e | 456 | { |
d62a17ae | 457 | struct listnode *node; |
458 | struct eigrp_interface *ei; | |
7f57883e | 459 | |
d62a17ae | 460 | for (ALL_LIST_ELEMENTS_RO(eigrp->eiflist, node, ei)) { |
461 | if (ifp && ei->ifp != ifp) | |
462 | continue; | |
7f57883e | 463 | |
b245781a | 464 | if (IPV4_ADDR_SAME(&address, &ei->address.u.prefix4)) |
d62a17ae | 465 | return ei; |
466 | } | |
7f57883e | 467 | |
d62a17ae | 468 | return NULL; |
7f57883e DS |
469 | } |
470 | ||
471 | /** | |
472 | * @fn eigrp_if_lookup_by_name | |
473 | * | |
474 | * @param[in] eigrp EIGRP process | |
475 | * @param[in] if_name Name of the interface | |
476 | * | |
477 | * @return struct eigrp_interface * | |
478 | * | |
479 | * @par | |
480 | * Function is used for lookup interface by name. | |
481 | */ | |
d62a17ae | 482 | struct eigrp_interface *eigrp_if_lookup_by_name(struct eigrp *eigrp, |
483 | const char *if_name) | |
7f57883e | 484 | { |
d62a17ae | 485 | struct eigrp_interface *ei; |
486 | struct listnode *node; | |
487 | ||
488 | /* iterate over all eigrp interfaces */ | |
489 | for (ALL_LIST_ELEMENTS_RO(eigrp->eiflist, node, ei)) { | |
490 | /* compare int name with eigrp interface's name */ | |
491 | if (strcmp(ei->ifp->name, if_name) == 0) { | |
492 | return ei; | |
493 | } | |
494 | } | |
495 | ||
496 | return NULL; | |
7f57883e DS |
497 | } |
498 | ||
d7c0a89a | 499 | uint32_t eigrp_bandwidth_to_scaled(uint32_t bandwidth) |
7f57883e | 500 | { |
d62a17ae | 501 | uint64_t temp_bandwidth = (256ull * 10000000) / bandwidth; |
7f57883e | 502 | |
d62a17ae | 503 | temp_bandwidth = temp_bandwidth < EIGRP_MAX_METRIC ? temp_bandwidth |
504 | : EIGRP_MAX_METRIC; | |
7f57883e | 505 | |
d7c0a89a | 506 | return (uint32_t)temp_bandwidth; |
7f57883e DS |
507 | } |
508 | ||
d7c0a89a | 509 | uint32_t eigrp_scaled_to_bandwidth(uint32_t scaled) |
7f57883e | 510 | { |
d62a17ae | 511 | uint64_t temp_scaled = scaled * (256ull * 10000000); |
7f57883e | 512 | |
d62a17ae | 513 | temp_scaled = |
514 | temp_scaled < EIGRP_MAX_METRIC ? temp_scaled : EIGRP_MAX_METRIC; | |
7f57883e | 515 | |
d7c0a89a | 516 | return (uint32_t)temp_scaled; |
7f57883e DS |
517 | } |
518 | ||
d7c0a89a | 519 | uint32_t eigrp_delay_to_scaled(uint32_t delay) |
7f57883e | 520 | { |
d62a17ae | 521 | return delay * 256; |
7f57883e DS |
522 | } |
523 | ||
d7c0a89a | 524 | uint32_t eigrp_scaled_to_delay(uint32_t scaled) |
7f57883e | 525 | { |
d62a17ae | 526 | return scaled / 256; |
7f57883e | 527 | } |