]> git.proxmox.com Git - mirror_frr.git/blob - eigrpd/eigrp_hello.c
Merge pull request #5175 from opensourcerouting/debug-nb-yang
[mirror_frr.git] / eigrpd / eigrp_hello.c
1 /*
2 * EIGRP Sending and Receiving EIGRP Hello Packets.
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 *
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
30 */
31
32 #include <zebra.h>
33
34 #include "thread.h"
35 #include "memory.h"
36 #include "linklist.h"
37 #include "prefix.h"
38 #include "if.h"
39 #include "table.h"
40 #include "sockunion.h"
41 #include "stream.h"
42 #include "log.h"
43 #include "sockopt.h"
44 #include "checksum.h"
45 #include "vty.h"
46 #include "md5.h"
47
48 #include "eigrpd/eigrp_structs.h"
49 #include "eigrpd/eigrpd.h"
50 #include "eigrpd/eigrp_interface.h"
51 #include "eigrpd/eigrp_neighbor.h"
52 #include "eigrpd/eigrp_packet.h"
53 #include "eigrpd/eigrp_zebra.h"
54 #include "eigrpd/eigrp_vty.h"
55 #include "eigrpd/eigrp_dump.h"
56 #include "eigrpd/eigrp_macros.h"
57 #include "eigrpd/eigrp_errors.h"
58
59 /* Packet Type String. */
60 static const struct message eigrp_general_tlv_type_str[] = {
61 {EIGRP_TLV_PARAMETER, "PARAMETER"},
62 {EIGRP_TLV_AUTH, "AUTH"},
63 {EIGRP_TLV_SEQ, "SEQ"},
64 {EIGRP_TLV_SW_VERSION, "SW_VERSION"},
65 {EIGRP_TLV_NEXT_MCAST_SEQ, "NEXT_MCAST_SEQ"},
66 {EIGRP_TLV_PEER_TERMINATION, "PEER_TERMINATION"},
67 {EIGRP_TLV_PEER_MTRLIST, "PEER_MTRLIST"},
68 {EIGRP_TLV_PEER_TIDLIST, "PEER_TIDLIST"},
69 {0}};
70
71
72 /*
73 * @fn eigrp_hello_timer
74 *
75 * @param[in] thread current execution thread timer is associated with
76 *
77 * @return int always returns 0
78 *
79 * @par
80 * Called once per "hello" time interval, default 5 seconds
81 * Sends hello packet via multicast for all interfaces eigrp
82 * is configured for
83 */
84 int eigrp_hello_timer(struct thread *thread)
85 {
86 struct eigrp_interface *ei;
87
88 ei = THREAD_ARG(thread);
89 ei->t_hello = NULL;
90
91 if (IS_DEBUG_EIGRP(0, TIMERS))
92 zlog_debug("Start Hello Timer (%s) Expire [%u]", IF_NAME(ei),
93 ei->params.v_hello);
94
95 /* Sending hello packet. */
96 eigrp_hello_send(ei, EIGRP_HELLO_NORMAL, NULL);
97
98 /* Hello timer set. */
99 ei->t_hello = NULL;
100 thread_add_timer(master, eigrp_hello_timer, ei, ei->params.v_hello,
101 &ei->t_hello);
102
103 return 0;
104 }
105
106 /**
107 * @fn eigrp_hello_parameter_decode
108 *
109 * @param[in] nbr neighbor the ACK should be sent to
110 * @param[in] param pointer packet TLV is stored to
111 *
112 * @return uint16_t number of bytes added to packet stream
113 *
114 * @par
115 * Encode Parameter TLV, used to convey metric weights and the hold time.
116 *
117 * @usage
118 * Note the addition of K6 for the new extended metrics, and does not apply to
119 * older TLV packet formats.
120 */
121 static struct eigrp_neighbor *
122 eigrp_hello_parameter_decode(struct eigrp_neighbor *nbr,
123 struct eigrp_tlv_hdr_type *tlv)
124 {
125 struct eigrp *eigrp = nbr->ei->eigrp;
126 struct TLV_Parameter_Type *param = (struct TLV_Parameter_Type *)tlv;
127
128 /* copy over the values passed in by the neighbor */
129 nbr->K1 = param->K1;
130 nbr->K2 = param->K2;
131 nbr->K3 = param->K3;
132 nbr->K4 = param->K4;
133 nbr->K5 = param->K5;
134 nbr->K6 = param->K6;
135 nbr->v_holddown = ntohs(param->hold_time);
136
137 /*
138 * Check K1-K5 have the correct values to be able to become neighbors
139 * K6 does not have to match
140 */
141 if ((eigrp->k_values[0] == nbr->K1) && (eigrp->k_values[1] == nbr->K2)
142 && (eigrp->k_values[2] == nbr->K3)
143 && (eigrp->k_values[3] == nbr->K4)
144 && (eigrp->k_values[4] == nbr->K5)) {
145
146 if (eigrp_nbr_state_get(nbr) == EIGRP_NEIGHBOR_DOWN) {
147 zlog_info("Neighbor %s (%s) is pending: new adjacency",
148 inet_ntoa(nbr->src),
149 ifindex2ifname(nbr->ei->ifp->ifindex,
150 eigrp->vrf_id));
151
152 /* Expedited hello sent */
153 eigrp_hello_send(nbr->ei, EIGRP_HELLO_NORMAL, NULL);
154
155 // if(ntohl(nbr->ei->address->u.prefix4.s_addr) >
156 // ntohl(nbr->src.s_addr))
157 eigrp_update_send_init(nbr);
158
159 eigrp_nbr_state_set(nbr, EIGRP_NEIGHBOR_PENDING);
160 }
161 } else {
162 if (eigrp_nbr_state_get(nbr) != EIGRP_NEIGHBOR_DOWN) {
163 if ((param->K1 & param->K2 & param->K3 & param->K4
164 & param->K5)
165 == 255) {
166 zlog_info(
167 "Neighbor %s (%s) is down: Interface PEER-TERMINATION received",
168 inet_ntoa(nbr->src),
169 ifindex2ifname(nbr->ei->ifp->ifindex,
170 eigrp->vrf_id));
171 eigrp_nbr_delete(nbr);
172 return NULL;
173 } else {
174 zlog_info(
175 "Neighbor %s (%s) going down: Kvalue mismatch",
176 inet_ntoa(nbr->src),
177 ifindex2ifname(nbr->ei->ifp->ifindex,
178 eigrp->vrf_id));
179 eigrp_nbr_state_set(nbr, EIGRP_NEIGHBOR_DOWN);
180 }
181 }
182 }
183
184 return nbr;
185 }
186
187 static uint8_t
188 eigrp_hello_authentication_decode(struct stream *s,
189 struct eigrp_tlv_hdr_type *tlv_header,
190 struct eigrp_neighbor *nbr)
191 {
192 struct TLV_MD5_Authentication_Type *md5;
193
194 md5 = (struct TLV_MD5_Authentication_Type *)tlv_header;
195
196 if (md5->auth_type == EIGRP_AUTH_TYPE_MD5)
197 return eigrp_check_md5_digest(s, md5, nbr,
198 EIGRP_AUTH_BASIC_HELLO_FLAG);
199 else if (md5->auth_type == EIGRP_AUTH_TYPE_SHA256)
200 return eigrp_check_sha256_digest(
201 s, (struct TLV_SHA256_Authentication_Type *)tlv_header,
202 nbr, EIGRP_AUTH_BASIC_HELLO_FLAG);
203
204 return 0;
205 }
206
207 /**
208 * @fn eigrp_sw_version_decode
209 *
210 * @param[in] nbr neighbor the ACK shoudl be sent to
211 * @param[in] param pointer to TLV software version information
212 *
213 * @return void
214 *
215 * @par
216 * Read the software version in the specified location.
217 * This consists of two bytes of OS version, and two bytes of EIGRP
218 * revision number.
219 */
220 static void eigrp_sw_version_decode(struct eigrp_neighbor *nbr,
221 struct eigrp_tlv_hdr_type *tlv)
222 {
223 struct TLV_Software_Type *version = (struct TLV_Software_Type *)tlv;
224
225 nbr->os_rel_major = version->vender_major;
226 nbr->os_rel_minor = version->vender_minor;
227 nbr->tlv_rel_major = version->eigrp_major;
228 nbr->tlv_rel_minor = version->eigrp_minor;
229 return;
230 }
231
232 /**
233 * @fn eigrp_peer_termination_decode
234 *
235 * @param[in] nbr neighbor the ACK shoudl be sent to
236 * @param[in] tlv pointer to TLV software version information
237 *
238 * @return void
239 *
240 * @par
241 * Read the address in the TLV and match to out address. If
242 * a match is found, move the sending neighbor to the down state. If
243 * out address is not in the TLV, then ignore the peer termination
244 */
245 static void eigrp_peer_termination_decode(struct eigrp_neighbor *nbr,
246 struct eigrp_tlv_hdr_type *tlv)
247 {
248 struct eigrp *eigrp = nbr->ei->eigrp;
249 struct TLV_Peer_Termination_type *param =
250 (struct TLV_Peer_Termination_type *)tlv;
251
252 uint32_t my_ip = nbr->ei->address.u.prefix4.s_addr;
253 uint32_t received_ip = param->neighbor_ip;
254
255 if (my_ip == received_ip) {
256 zlog_info("Neighbor %s (%s) is down: Peer Termination received",
257 inet_ntoa(nbr->src),
258 ifindex2ifname(nbr->ei->ifp->ifindex, eigrp->vrf_id));
259 /* set neighbor to DOWN */
260 nbr->state = EIGRP_NEIGHBOR_DOWN;
261 /* delete neighbor */
262 eigrp_nbr_delete(nbr);
263 }
264 }
265
266 /**
267 * @fn eigrp_peer_termination_encode
268 *
269 * @param[in,out] s packet stream TLV is stored to
270 * @param[in] nbr_addr pointer to neighbor address for Peer
271 * Termination TLV
272 *
273 * @return uint16_t number of bytes added to packet stream
274 *
275 * @par
276 * Function used to encode Peer Termination TLV to Hello packet.
277 */
278 static uint16_t eigrp_peer_termination_encode(struct stream *s,
279 struct in_addr *nbr_addr)
280 {
281 uint16_t length = EIGRP_TLV_PEER_TERMINATION_LEN;
282
283 /* fill in type and length */
284 stream_putw(s, EIGRP_TLV_PEER_TERMINATION);
285 stream_putw(s, length);
286
287 /* fill in unknown field 0x04 */
288 stream_putc(s, 0x04);
289
290 /* finally neighbor IP address */
291 stream_put_ipv4(s, nbr_addr->s_addr);
292
293 return (length);
294 }
295
296 /*
297 * @fn eigrp_hello_receive
298 *
299 * @param[in] eigrp eigrp routing process
300 * @param[in] iph pointer to ip header
301 * @param[in] eigrph pointer to eigrp header
302 * @param[in] s input ip stream
303 * @param[in] ei eigrp interface packet arrived on
304 * @param[in] size size of eigrp packet
305 *
306 * @return void
307 *
308 * @par
309 * This is the main worker function for processing hello packets. It
310 * will validate the peer associated with the src ip address of the ip
311 * header, and then decode each of the general TLVs which the packet
312 * may contain.
313 *
314 * @usage
315 * Not all TLVs are current decoder. This is a work in progress..
316 */
317 void eigrp_hello_receive(struct eigrp *eigrp, struct ip *iph,
318 struct eigrp_header *eigrph, struct stream *s,
319 struct eigrp_interface *ei, int size)
320 {
321 struct eigrp_tlv_hdr_type *tlv_header;
322 struct eigrp_neighbor *nbr;
323 uint16_t type;
324 uint16_t length;
325
326 /* get neighbor struct */
327 nbr = eigrp_nbr_get(ei, eigrph, iph);
328
329 /* neighbor must be valid, eigrp_nbr_get creates if none existed */
330 assert(nbr);
331
332 if (IS_DEBUG_EIGRP_PACKET(eigrph->opcode - 1, RECV))
333 zlog_debug("Processing Hello size[%u] int(%s) nbr(%s)", size,
334 ifindex2ifname(nbr->ei->ifp->ifindex, eigrp->vrf_id),
335 inet_ntoa(nbr->src));
336
337 size -= EIGRP_HEADER_LEN;
338 if (size < 0)
339 return;
340
341 tlv_header = (struct eigrp_tlv_hdr_type *)eigrph->tlv;
342
343 do {
344 type = ntohs(tlv_header->type);
345 length = ntohs(tlv_header->length);
346
347 if ((length > 0) && (length <= size)) {
348 if (IS_DEBUG_EIGRP_PACKET(0, RECV))
349 zlog_debug(
350 " General TLV(%s)",
351 lookup_msg(eigrp_general_tlv_type_str,
352 type, NULL));
353
354 // determine what General TLV is being processed
355 switch (type) {
356 case EIGRP_TLV_PARAMETER:
357 nbr = eigrp_hello_parameter_decode(nbr,
358 tlv_header);
359 if (!nbr)
360 return;
361 break;
362 case EIGRP_TLV_AUTH: {
363 if (eigrp_hello_authentication_decode(
364 s, tlv_header, nbr)
365 == 0)
366 return;
367 else
368 break;
369 break;
370 }
371 case EIGRP_TLV_SEQ:
372 break;
373 case EIGRP_TLV_SW_VERSION:
374 eigrp_sw_version_decode(nbr, tlv_header);
375 break;
376 case EIGRP_TLV_NEXT_MCAST_SEQ:
377 break;
378 case EIGRP_TLV_PEER_TERMINATION:
379 eigrp_peer_termination_decode(nbr, tlv_header);
380 return;
381 break;
382 case EIGRP_TLV_PEER_MTRLIST:
383 case EIGRP_TLV_PEER_TIDLIST:
384 break;
385 default:
386 break;
387 }
388 }
389
390 tlv_header = (struct eigrp_tlv_hdr_type *)(((char *)tlv_header)
391 + length);
392 size -= length;
393
394 } while (size > 0);
395
396
397 /*If received packet is hello with Parameter TLV*/
398 if (ntohl(eigrph->ack) == 0) {
399 /* increment statistics. */
400 ei->hello_in++;
401 if (nbr)
402 eigrp_nbr_state_update(nbr);
403 }
404
405 if (IS_DEBUG_EIGRP_PACKET(0, RECV))
406 zlog_debug("Hello Packet received from %s",
407 inet_ntoa(nbr->src));
408 }
409
410 uint32_t FRR_MAJOR;
411 uint32_t FRR_MINOR;
412
413 void eigrp_sw_version_initialize(void)
414 {
415 char ver_string[] = VERSION;
416 char *dash = strstr(ver_string, "-");
417 int ret;
418
419 if (dash)
420 dash[0] = '\0';
421
422 ret = sscanf(ver_string, "%" SCNu32 ".%" SCNu32, &FRR_MAJOR,
423 &FRR_MINOR);
424 if (ret != 2)
425 flog_err(EC_EIGRP_PACKET,
426 "Did not Properly parse %s, please fix VERSION string",
427 VERSION);
428 }
429
430 /**
431 * @fn eigrp_sw_version_encode
432 *
433 * @param[in,out] s packet stream TLV is stored to
434 *
435 * @return uint16_t number of bytes added to packet stream
436 *
437 * @par
438 * Store the software version in the specified location.
439 * This consists of two bytes of OS version, and two bytes of EIGRP
440 * revision number.
441 */
442 static uint16_t eigrp_sw_version_encode(struct stream *s)
443 {
444 uint16_t length = EIGRP_TLV_SW_VERSION_LEN;
445
446 // setup the tlv fields
447 stream_putw(s, EIGRP_TLV_SW_VERSION);
448 stream_putw(s, length);
449
450 stream_putc(s, FRR_MAJOR); //!< major os version
451 stream_putc(s, FRR_MINOR); //!< minor os version
452
453 /* and the core eigrp version */
454 stream_putc(s, EIGRP_MAJOR_VERSION);
455 stream_putc(s, EIGRP_MINOR_VERSION);
456
457 return (length);
458 }
459
460 /**
461 * @fn eigrp_tidlist_encode
462 *
463 * @param[in,out] s packet stream TLV is stored to
464 *
465 * @return void
466 *
467 * @par
468 * If doing mutli-topology, then store the supported TID list.
469 * This is currently a place holder function
470 */
471 static uint16_t eigrp_tidlist_encode(struct stream *s)
472 {
473 // uint16_t length = EIGRP_TLV_SW_VERSION_LEN;
474 return 0;
475 }
476
477 /**
478 * @fn eigrp_sequence_encode
479 *
480 * @param[in,out] s packet stream TLV is stored to
481 *
482 * @return uint16_t number of bytes added to packet stream
483 *
484 * @par
485 * Part of conditional receive process
486 *
487 */
488 static uint16_t eigrp_sequence_encode(struct eigrp *eigrp, struct stream *s)
489 {
490 uint16_t length = EIGRP_TLV_SEQ_BASE_LEN;
491 struct eigrp_interface *ei;
492 struct listnode *node, *node2, *nnode2;
493 struct eigrp_neighbor *nbr;
494 size_t backup_end, size_end;
495 int found;
496
497 // add in the parameters TLV
498 backup_end = stream_get_endp(s);
499 stream_putw(s, EIGRP_TLV_SEQ);
500 size_end = s->endp;
501 stream_putw(s, 0x0000);
502 stream_putc(s, IPV4_MAX_BYTELEN);
503
504 found = 0;
505 for (ALL_LIST_ELEMENTS_RO(eigrp->eiflist, node, ei)) {
506 for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) {
507 if (nbr->multicast_queue->count > 0) {
508 length += (uint16_t)stream_put_ipv4(
509 s, nbr->src.s_addr);
510 found = 1;
511 }
512 }
513 }
514
515 if (found == 0) {
516 stream_set_endp(s, backup_end);
517 return 0;
518 }
519
520 backup_end = stream_get_endp(s);
521 stream_set_endp(s, size_end);
522 stream_putw(s, length);
523 stream_set_endp(s, backup_end);
524
525 return length;
526 }
527
528 /**
529 * @fn eigrp_sequence_encode
530 *
531 * @param[in,out] s packet stream TLV is stored to
532 *
533 * @return uint16_t number of bytes added to packet stream
534 *
535 * @par
536 * Part of conditional receive process
537 *
538 */
539 static uint16_t eigrp_next_sequence_encode(struct eigrp *eigrp,
540 struct stream *s)
541 {
542 uint16_t length = EIGRP_NEXT_SEQUENCE_TLV_SIZE;
543
544 // add in the parameters TLV
545 stream_putw(s, EIGRP_TLV_NEXT_MCAST_SEQ);
546 stream_putw(s, EIGRP_NEXT_SEQUENCE_TLV_SIZE);
547 stream_putl(s, eigrp->sequence_number + 1);
548
549 return length;
550 }
551
552 /**
553 * @fn eigrp_hello_parameter_encode
554 *
555 * @param[in] ei pointer to interface hello packet came in on
556 * @param[in,out] s packet stream TLV is stored to
557 *
558 * @return uint16_t number of bytes added to packet stream
559 *
560 * @par
561 * Encode Parameter TLV, used to convey metric weights and the hold time.
562 *
563 * @usage
564 * Note the addition of K6 for the new extended metrics, and does not apply to
565 * older TLV packet formats.
566 */
567 static uint16_t eigrp_hello_parameter_encode(struct eigrp_interface *ei,
568 struct stream *s, uint8_t flags)
569 {
570 // add in the parameters TLV
571 stream_putw(s, EIGRP_TLV_PARAMETER);
572 stream_putw(s, EIGRP_TLV_PARAMETER_LEN);
573
574 // if graceful shutdown is needed to be announced, send all 255 in K
575 // values
576 if (flags & EIGRP_HELLO_GRACEFUL_SHUTDOWN) {
577 stream_putc(s, 0xff); /* K1 */
578 stream_putc(s, 0xff); /* K2 */
579 stream_putc(s, 0xff); /* K3 */
580 stream_putc(s, 0xff); /* K4 */
581 stream_putc(s, 0xff); /* K5 */
582 stream_putc(s, 0xff); /* K6 */
583 } else // set k values
584 {
585 stream_putc(s, ei->eigrp->k_values[0]); /* K1 */
586 stream_putc(s, ei->eigrp->k_values[1]); /* K2 */
587 stream_putc(s, ei->eigrp->k_values[2]); /* K3 */
588 stream_putc(s, ei->eigrp->k_values[3]); /* K4 */
589 stream_putc(s, ei->eigrp->k_values[4]); /* K5 */
590 stream_putc(s, ei->eigrp->k_values[5]); /* K6 */
591 }
592
593 // and set hold time value..
594 stream_putw(s, ei->params.v_wait);
595
596 return EIGRP_TLV_PARAMETER_LEN;
597 }
598
599 /**
600 * @fn eigrp_hello_encode
601 *
602 * @param[in] ei pointer to interface hello packet came in on
603 * @param[in] s packet stream TLV is stored to
604 * @param[in] ack if non-zero, neigbors sequence packet to ack
605 * @param[in] flags type of hello packet
606 * @param[in] nbr_addr pointer to neighbor address for Peer
607 * Termination TLV
608 *
609 * @return eigrp_packet pointer initialize hello packet
610 *
611 * @par
612 * Allocate an EIGRP hello packet, and add in the the approperate TLVs
613 *
614 */
615 static struct eigrp_packet *eigrp_hello_encode(struct eigrp_interface *ei,
616 in_addr_t addr, uint32_t ack,
617 uint8_t flags,
618 struct in_addr *nbr_addr)
619 {
620 struct eigrp_packet *ep;
621 uint16_t length = EIGRP_HEADER_LEN;
622
623 // allocate a new packet to be sent
624 ep = eigrp_packet_new(EIGRP_PACKET_MTU(ei->ifp->mtu), NULL);
625
626 if (ep) {
627 // encode common header feilds
628 eigrp_packet_header_init(EIGRP_OPC_HELLO, ei->eigrp, ep->s, 0,
629 0, ack);
630
631 // encode Authentication TLV
632 if ((ei->params.auth_type == EIGRP_AUTH_TYPE_MD5)
633 && (ei->params.auth_keychain != NULL)) {
634 length += eigrp_add_authTLV_MD5_to_stream(ep->s, ei);
635 } else if ((ei->params.auth_type == EIGRP_AUTH_TYPE_SHA256)
636 && (ei->params.auth_keychain != NULL)) {
637 length += eigrp_add_authTLV_SHA256_to_stream(ep->s, ei);
638 }
639
640 /* encode appropriate parameters to Hello packet */
641 if (flags & EIGRP_HELLO_GRACEFUL_SHUTDOWN)
642 length += eigrp_hello_parameter_encode(
643 ei, ep->s, EIGRP_HELLO_GRACEFUL_SHUTDOWN);
644 else
645 length += eigrp_hello_parameter_encode(
646 ei, ep->s, EIGRP_HELLO_NORMAL);
647
648 // figure out the version of code we're running
649 length += eigrp_sw_version_encode(ep->s);
650
651 if (flags & EIGRP_HELLO_ADD_SEQUENCE) {
652 length += eigrp_sequence_encode(ei->eigrp, ep->s);
653 length += eigrp_next_sequence_encode(ei->eigrp, ep->s);
654 }
655
656 // add in the TID list if doing multi-topology
657 length += eigrp_tidlist_encode(ep->s);
658
659 /* encode Peer Termination TLV if needed */
660 if (flags & EIGRP_HELLO_GRACEFUL_SHUTDOWN_NBR)
661 length +=
662 eigrp_peer_termination_encode(ep->s, nbr_addr);
663
664 // Set packet length
665 ep->length = length;
666
667 // set soruce address for the hello packet
668 ep->dst.s_addr = addr;
669
670 if ((ei->params.auth_type == EIGRP_AUTH_TYPE_MD5)
671 && (ei->params.auth_keychain != NULL)) {
672 eigrp_make_md5_digest(ei, ep->s,
673 EIGRP_AUTH_BASIC_HELLO_FLAG);
674 } else if ((ei->params.auth_type == EIGRP_AUTH_TYPE_SHA256)
675 && (ei->params.auth_keychain != NULL)) {
676 eigrp_make_sha256_digest(ei, ep->s,
677 EIGRP_AUTH_BASIC_HELLO_FLAG);
678 }
679
680 // EIGRP Checksum
681 eigrp_packet_checksum(ei, ep->s, length);
682 }
683
684 return (ep);
685 }
686
687 /**
688 * @fn eigrp_hello_send
689 *
690 * @param[in] nbr neighbor the ACK should be sent to
691 *
692 * @return void
693 *
694 * @par
695 * Send (unicast) a hello packet with the destination address
696 * associated with the neighbor. The eigrp header ACK feild will be
697 * updated to the neighbor's sequence number to acknolodge any
698 * outstanding packets
699 */
700 void eigrp_hello_send_ack(struct eigrp_neighbor *nbr)
701 {
702 struct eigrp_packet *ep;
703
704 /* if packet succesfully created, add it to the interface queue */
705 ep = eigrp_hello_encode(nbr->ei, nbr->src.s_addr,
706 nbr->recv_sequence_number, EIGRP_HELLO_NORMAL,
707 NULL);
708
709 if (ep) {
710 if (IS_DEBUG_EIGRP_PACKET(0, SEND))
711 zlog_debug("Queueing [Hello] Ack Seq [%u] nbr [%s]",
712 nbr->recv_sequence_number,
713 inet_ntoa(nbr->src));
714
715 /* Add packet to the top of the interface output queue*/
716 eigrp_fifo_push(nbr->ei->obuf, ep);
717
718 /* Hook thread to write packet. */
719 if (nbr->ei->on_write_q == 0) {
720 listnode_add(nbr->ei->eigrp->oi_write_q, nbr->ei);
721 nbr->ei->on_write_q = 1;
722 }
723 thread_add_write(master, eigrp_write, nbr->ei->eigrp,
724 nbr->ei->eigrp->fd, &nbr->ei->eigrp->t_write);
725 }
726 }
727
728 /**
729 * @fn eigrp_hello_send
730 *
731 * @param[in] ei pointer to interface hello should be sent
732 * @param[in] flags type of hello packet
733 * @param[in] nbr_addr pointer to neighbor address for Peer
734 * Termination TLV
735 *
736 * @return void
737 *
738 * @par
739 * Build and enqueue a generic (multicast) periodic hello packet for
740 * sending. If no packets are currently queues, the packet will be
741 * sent immadiatly
742 */
743 void eigrp_hello_send(struct eigrp_interface *ei, uint8_t flags,
744 struct in_addr *nbr_addr)
745 {
746 struct eigrp_packet *ep = NULL;
747
748 /* If this is passive interface, do not send EIGRP Hello.
749 if ((EIGRP_IF_PASSIVE_STATUS (ei) == EIGRP_IF_PASSIVE) ||
750 (ei->type != EIGRP_IFTYPE_NBMA))
751 return;
752 */
753
754 if (IS_DEBUG_EIGRP_PACKET(0, SEND))
755 zlog_debug("Queueing [Hello] Interface(%s)", IF_NAME(ei));
756
757 /* if packet was succesfully created, then add it to the interface queue
758 */
759 ep = eigrp_hello_encode(ei, htonl(EIGRP_MULTICAST_ADDRESS), 0, flags,
760 nbr_addr);
761
762 if (ep) {
763 // Add packet to the top of the interface output queue
764 eigrp_fifo_push(ei->obuf, ep);
765
766 /* Hook thread to write packet. */
767 if (ei->on_write_q == 0) {
768 listnode_add(ei->eigrp->oi_write_q, ei);
769 ei->on_write_q = 1;
770 }
771
772 if (ei->eigrp->t_write == NULL) {
773 if (flags & EIGRP_HELLO_GRACEFUL_SHUTDOWN) {
774 thread_execute(master, eigrp_write, ei->eigrp,
775 ei->eigrp->fd);
776 } else {
777 thread_add_write(master, eigrp_write, ei->eigrp,
778 ei->eigrp->fd,
779 &ei->eigrp->t_write);
780 }
781 }
782 }
783 }