1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
|
/*
* EIGRP Sending and Receiving EIGRP Update Packets.
* Copyright (C) 2013-2016
* Authors:
* Donnie Savage
* Jan Janovic
* Matej Perina
* Peter Orsag
* Peter Paluch
* Frantisek Gazo
* Tomas Hvorkovy
* Martin Kontsek
* Lukas Koribsky
*
* This file is part of GNU Zebra.
*
* GNU Zebra is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* GNU Zebra is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; see the file COPYING; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>
#include "thread.h"
#include "memory.h"
#include "linklist.h"
#include "prefix.h"
#include "if.h"
#include "table.h"
#include "sockunion.h"
#include "stream.h"
#include "log.h"
#include "sockopt.h"
#include "checksum.h"
#include "md5.h"
#include "vty.h"
#include "plist.h"
#include "plist_int.h"
#include "routemap.h"
#include "vty.h"
#include "eigrpd/eigrp_structs.h"
#include "eigrpd/eigrpd.h"
#include "eigrpd/eigrp_interface.h"
#include "eigrpd/eigrp_neighbor.h"
#include "eigrpd/eigrp_packet.h"
#include "eigrpd/eigrp_zebra.h"
#include "eigrpd/eigrp_vty.h"
#include "eigrpd/eigrp_dump.h"
#include "eigrpd/eigrp_macros.h"
#include "eigrpd/eigrp_topology.h"
#include "eigrpd/eigrp_fsm.h"
#include "eigrpd/eigrp_network.h"
#include "eigrpd/eigrp_memory.h"
/**
* @fn remove_received_prefix_gr
*
* @param[in] nbr_prefixes List of neighbor prefixes
* @param[in] recv_prefix Prefix which needs to be removed from
* list
*
* @return void
*
* @par
* Function is used for removing received prefix
* from list of neighbor prefixes
*/
static void remove_received_prefix_gr(struct list *nbr_prefixes,
struct eigrp_prefix_entry *recv_prefix)
{
struct listnode *node1, *node11;
struct eigrp_prefix_entry *prefix = NULL;
/* iterate over all prefixes in list */
for (ALL_LIST_ELEMENTS(nbr_prefixes, node1, node11, prefix)) {
/* remove prefix from list if found */
if (prefix == recv_prefix) {
listnode_delete(nbr_prefixes, prefix);
}
}
}
/**
* @fn eigrp_update_receive_GR_ask
*
* @param[in] eigrp EIGRP process
* @param[in] nbr Neighbor update of who we
* received
* @param[in] nbr_prefixes Prefixes which weren't advertised
*
* @return void
*
* @par
* Function is used for notifying FSM about prefixes which
* weren't advertised by neighbor:
* We will send message to FSM with prefix delay set to infinity.
*/
static void eigrp_update_receive_GR_ask(struct eigrp *eigrp,
struct eigrp_neighbor *nbr,
struct list *nbr_prefixes)
{
struct listnode *node1;
struct eigrp_prefix_entry *prefix;
struct TLV_IPv4_Internal_type *tlv_max;
/* iterate over all prefixes which weren't advertised by neighbor */
for (ALL_LIST_ELEMENTS_RO(nbr_prefixes, node1, prefix)) {
zlog_debug("GR receive: Neighbor not advertised %s/%d",
inet_ntoa(prefix->destination_ipv4->prefix),
prefix->destination_ipv4->prefixlen);
/* create internal IPv4 TLV with infinite delay */
tlv_max = eigrp_IPv4_InternalTLV_new();
tlv_max->type = EIGRP_TLV_IPv4_INT;
tlv_max->length = 28U;
tlv_max->metric = prefix->reported_metric;
/* set delay to MAX */
tlv_max->metric.delay = EIGRP_MAX_METRIC;
tlv_max->destination = prefix->destination_ipv4->prefix;
tlv_max->prefix_length = prefix->destination_ipv4->prefixlen;
/* prepare message for FSM */
struct eigrp_fsm_action_message *fsm_msg;
fsm_msg = XCALLOC(MTYPE_EIGRP_FSM_MSG,
sizeof(struct eigrp_fsm_action_message));
struct eigrp_neighbor_entry *entry =
eigrp_prefix_entry_lookup(prefix->entries, nbr);
fsm_msg->packet_type = EIGRP_OPC_UPDATE;
fsm_msg->eigrp = eigrp;
fsm_msg->data_type = EIGRP_TLV_IPv4_INT;
fsm_msg->adv_router = nbr;
fsm_msg->data.ipv4_int_type = tlv_max;
fsm_msg->entry = entry;
fsm_msg->prefix = prefix;
/* send message to FSM */
int event = eigrp_get_fsm_event(fsm_msg);
eigrp_fsm_event(fsm_msg, event);
/* free memory used by TLV */
eigrp_IPv4_InternalTLV_free(tlv_max);
}
}
/*
* EIGRP UPDATE read function
*/
void eigrp_update_receive(struct eigrp *eigrp, struct ip *iph,
struct eigrp_header *eigrph, struct stream *s,
struct eigrp_interface *ei, int size)
{
struct eigrp_neighbor *nbr;
struct TLV_IPv4_Internal_type *tlv;
struct eigrp_prefix_entry *pe;
struct eigrp_neighbor_entry *ne;
u_int32_t flags;
u_int16_t type;
u_char same;
struct access_list *alist;
struct prefix_list *plist;
struct eigrp *e;
u_char graceful_restart;
u_char graceful_restart_final;
struct list *nbr_prefixes = NULL;
/* increment statistics. */
ei->update_in++;
/* get neighbor struct */
nbr = eigrp_nbr_get(ei, eigrph, iph);
/* neighbor must be valid, eigrp_nbr_get creates if none existed */
assert(nbr);
flags = ntohl(eigrph->flags);
if (flags & EIGRP_CR_FLAG) {
return;
}
same = 0;
graceful_restart = 0;
graceful_restart_final = 0;
if ((nbr->recv_sequence_number) == (ntohl(eigrph->sequence)))
same = 1;
nbr->recv_sequence_number = ntohl(eigrph->sequence);
if (IS_DEBUG_EIGRP_PACKET(0, RECV))
zlog_debug(
"Processing Update size[%u] int(%s) nbr(%s) seq [%u] flags [%0x]",
size,
ifindex2ifname(nbr->ei->ifp->ifindex, VRF_DEFAULT),
inet_ntoa(nbr->src), nbr->recv_sequence_number, flags);
if ((flags == (EIGRP_INIT_FLAG + EIGRP_RS_FLAG + EIGRP_EOT_FLAG))
&& (!same)) {
/* Graceful restart Update received with all routes */
zlog_info("Neighbor %s (%s) is resync: peer graceful-restart",
inet_ntoa(nbr->src),
ifindex2ifname(nbr->ei->ifp->ifindex, VRF_DEFAULT));
/* get all prefixes from neighbor from topology table */
nbr_prefixes = eigrp_neighbor_prefixes_lookup(eigrp, nbr);
graceful_restart = 1;
graceful_restart_final = 1;
} else if ((flags == (EIGRP_INIT_FLAG + EIGRP_RS_FLAG)) && (!same)) {
/* Graceful restart Update received, routes also in next packet
*/
zlog_info("Neighbor %s (%s) is resync: peer graceful-restart",
inet_ntoa(nbr->src),
ifindex2ifname(nbr->ei->ifp->ifindex, VRF_DEFAULT));
/* get all prefixes from neighbor from topology table */
nbr_prefixes = eigrp_neighbor_prefixes_lookup(eigrp, nbr);
/* save prefixes to neighbor for later use */
nbr->nbr_gr_prefixes = nbr_prefixes;
graceful_restart = 1;
graceful_restart_final = 0;
} else if ((flags == (EIGRP_EOT_FLAG)) && (!same)) {
/* If there was INIT+RS Update packet before,
* consider this as GR EOT */
if (nbr->nbr_gr_prefixes != NULL) {
/* this is final packet of GR */
nbr_prefixes = nbr->nbr_gr_prefixes;
nbr->nbr_gr_prefixes = NULL;
graceful_restart = 1;
graceful_restart_final = 1;
}
} else if ((flags == (0)) && (!same)) {
/* If there was INIT+RS Update packet before,
* consider this as GR not final packet */
if (nbr->nbr_gr_prefixes != NULL) {
/* this is GR not final route packet */
nbr_prefixes = nbr->nbr_gr_prefixes;
graceful_restart = 1;
graceful_restart_final = 0;
}
} else if ((flags & EIGRP_INIT_FLAG)
&& (!same)) { /* When in pending state, send INIT update only
if it wasn't
already sent before (only if init_sequence
is 0) */
if ((nbr->state == EIGRP_NEIGHBOR_PENDING)
&& (nbr->init_sequence_number == 0))
eigrp_update_send_init(nbr);
if (nbr->state == EIGRP_NEIGHBOR_UP) {
eigrp_nbr_state_set(nbr, EIGRP_NEIGHBOR_DOWN);
eigrp_topology_neighbor_down(nbr->ei->eigrp, nbr);
nbr->recv_sequence_number = ntohl(eigrph->sequence);
zlog_info("Neighbor %s (%s) is down: peer restarted",
inet_ntoa(nbr->src),
ifindex2ifname(nbr->ei->ifp->ifindex,
VRF_DEFAULT));
eigrp_nbr_state_set(nbr, EIGRP_NEIGHBOR_PENDING);
zlog_info("Neighbor %s (%s) is pending: new adjacency",
inet_ntoa(nbr->src),
ifindex2ifname(nbr->ei->ifp->ifindex,
VRF_DEFAULT));
eigrp_update_send_init(nbr);
}
}
/*If there is topology information*/
while (s->endp > s->getp) {
type = stream_getw(s);
if (type == EIGRP_TLV_IPv4_INT) {
struct prefix_ipv4 dest_addr;
stream_set_getp(s, s->getp - sizeof(u_int16_t));
tlv = eigrp_read_ipv4_tlv(s);
/*searching if destination exists */
dest_addr.family = AF_INET;
dest_addr.prefix = tlv->destination;
dest_addr.prefixlen = tlv->prefix_length;
struct eigrp_prefix_entry *dest =
eigrp_topology_table_lookup_ipv4(
eigrp->topology_table, &dest_addr);
/*if exists it comes to DUAL*/
if (dest != NULL) {
/* remove received prefix from neighbor prefix
* list if in GR */
if (graceful_restart)
remove_received_prefix_gr(nbr_prefixes,
dest);
struct eigrp_fsm_action_message *msg;
msg = XCALLOC(MTYPE_EIGRP_FSM_MSG,
sizeof(struct
eigrp_fsm_action_message));
struct eigrp_neighbor_entry *entry =
eigrp_prefix_entry_lookup(dest->entries,
nbr);
msg->packet_type = EIGRP_OPC_UPDATE;
msg->eigrp = eigrp;
msg->data_type = EIGRP_TLV_IPv4_INT;
msg->adv_router = nbr;
msg->data.ipv4_int_type = tlv;
msg->entry = entry;
msg->prefix = dest;
int event = eigrp_get_fsm_event(msg);
eigrp_fsm_event(msg, event);
} else {
/*Here comes topology information save*/
pe = eigrp_prefix_entry_new();
pe->serno = eigrp->serno;
pe->destination_ipv4 = prefix_ipv4_new();
prefix_copy(
(struct prefix *)pe->destination_ipv4,
(struct prefix *)&dest_addr);
pe->af = AF_INET;
pe->state = EIGRP_FSM_STATE_PASSIVE;
pe->nt = EIGRP_TOPOLOGY_TYPE_REMOTE;
ne = eigrp_neighbor_entry_new();
ne->ei = ei;
ne->adv_router = nbr;
ne->reported_metric = tlv->metric;
ne->reported_distance = eigrp_calculate_metrics(
eigrp, tlv->metric);
/*
* Filtering
*/
e = eigrp_lookup();
/*
* Check if there is any access-list on
* interface (IN direction)
* and set distance to max
*/
alist = ei->list[EIGRP_FILTER_IN];
/* Check if access-list fits */
if (alist
&& access_list_apply(
alist,
(struct prefix *)&dest_addr)
== FILTER_DENY) {
/* If yes, set reported metric to Max */
ne->reported_metric.delay =
EIGRP_MAX_METRIC;
} else {
ne->distance =
eigrp_calculate_total_metrics(
eigrp, ne);
}
plist = e->prefix[EIGRP_FILTER_IN];
/* Check if prefix-list fits */
if (plist
&& prefix_list_apply(
plist,
(struct prefix *)&dest_addr)
== PREFIX_DENY) {
/* If yes, set reported metric to Max */
ne->reported_metric.delay =
EIGRP_MAX_METRIC;
}
/*Get access-list from current interface */
alist = ei->list[EIGRP_FILTER_IN];
/* Check if access-list fits */
if (alist
&& access_list_apply(
alist,
(struct prefix *)&dest_addr)
== FILTER_DENY) {
/* If yes, set reported metric to Max */
ne->reported_metric.delay =
EIGRP_MAX_METRIC;
}
plist = ei->prefix[EIGRP_FILTER_IN];
/* Check if prefix-list fits */
if (plist
&& prefix_list_apply(
plist,
(struct prefix *)&dest_addr)
== PREFIX_DENY) {
/* If yes, set reported metric to Max */
ne->reported_metric.delay =
EIGRP_MAX_METRIC;
}
/*
* End of filtering
*/
ne->distance = eigrp_calculate_total_metrics(
eigrp, ne);
pe->fdistance = pe->distance = pe->rdistance =
ne->distance;
ne->prefix = pe;
ne->flags = EIGRP_NEIGHBOR_ENTRY_SUCCESSOR_FLAG;
eigrp_prefix_entry_add(eigrp->topology_table,
pe);
eigrp_neighbor_entry_add(pe, ne);
pe->distance = pe->fdistance = pe->rdistance =
ne->distance;
pe->reported_metric = ne->total_metric;
eigrp_topology_update_node_flags(pe);
pe->req_action |= EIGRP_FSM_NEED_UPDATE;
listnode_add(
eigrp->topology_changes_internalIPV4,
pe);
}
eigrp_IPv4_InternalTLV_free(tlv);
}
}
/* ask about prefixes not present in GR update,
* if this is final GR packet */
if (graceful_restart_final) {
eigrp_update_receive_GR_ask(eigrp, nbr, nbr_prefixes);
}
/*
* We don't need to send separate Ack for INIT Update. INIT will be
* acked in EOT Update.
*/
if ((nbr->state == EIGRP_NEIGHBOR_UP) && !(flags == EIGRP_INIT_FLAG)) {
eigrp_hello_send_ack(nbr);
}
eigrp_query_send_all(eigrp);
eigrp_update_send_all(eigrp, ei);
}
/*send EIGRP Update packet*/
void eigrp_update_send_init(struct eigrp_neighbor *nbr)
{
struct eigrp_packet *ep;
u_int16_t length = EIGRP_HEADER_LEN;
ep = eigrp_packet_new(nbr->ei->ifp->mtu);
/* Prepare EIGRP INIT UPDATE header */
if (IS_DEBUG_EIGRP_PACKET(0, RECV))
zlog_debug("Enqueuing Update Init Seq [%u] Ack [%u]",
nbr->ei->eigrp->sequence_number,
nbr->recv_sequence_number);
eigrp_packet_header_init(
EIGRP_OPC_UPDATE, nbr->ei, ep->s, EIGRP_INIT_FLAG,
nbr->ei->eigrp->sequence_number, nbr->recv_sequence_number);
// encode Authentication TLV, if needed
if ((IF_DEF_PARAMS(nbr->ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5)
&& (IF_DEF_PARAMS(nbr->ei->ifp)->auth_keychain != NULL)) {
length += eigrp_add_authTLV_MD5_to_stream(ep->s, nbr->ei);
eigrp_make_md5_digest(nbr->ei, ep->s,
EIGRP_AUTH_UPDATE_INIT_FLAG);
}
/* EIGRP Checksum */
eigrp_packet_checksum(nbr->ei, ep->s, length);
ep->length = length;
ep->dst.s_addr = nbr->src.s_addr;
/*This ack number we await from neighbor*/
nbr->init_sequence_number = nbr->ei->eigrp->sequence_number;
ep->sequence_number = nbr->ei->eigrp->sequence_number;
if (IS_DEBUG_EIGRP_PACKET(0, RECV))
zlog_debug("Enqueuing Update Init Len [%u] Seq [%u] Dest [%s]",
ep->length, ep->sequence_number, inet_ntoa(ep->dst));
/*Put packet to retransmission queue*/
eigrp_fifo_push_head(nbr->retrans_queue, ep);
if (nbr->retrans_queue->count == 1) {
eigrp_send_packet_reliably(nbr);
}
}
static void eigrp_update_place_on_nbr_queue(struct eigrp_neighbor *nbr,
struct eigrp_packet *ep,
u_int32_t seq_no,
int length)
{
if((IF_DEF_PARAMS (nbr->ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5) &&
(IF_DEF_PARAMS (nbr->ei->ifp)->auth_keychain != NULL)) {
eigrp_make_md5_digest(nbr->ei,ep->s, EIGRP_AUTH_UPDATE_FLAG);
}
/* EIGRP Checksum */
eigrp_packet_checksum(nbr->ei, ep->s, length);
ep->length = length;
ep->dst.s_addr = nbr->src.s_addr;
/*This ack number we await from neighbor*/
ep->sequence_number = seq_no;
if (IS_DEBUG_EIGRP_PACKET(0, RECV))
zlog_debug("Enqueuing Update Init Len [%u] Seq [%u] Dest [%s]",
ep->length, ep->sequence_number, inet_ntoa(ep->dst));
/*Put packet to retransmission queue*/
eigrp_fifo_push_head(nbr->retrans_queue, ep);
}
void eigrp_update_send_EOT(struct eigrp_neighbor *nbr)
{
struct eigrp_packet *ep;
u_int16_t length = EIGRP_HEADER_LEN;
struct eigrp_neighbor_entry *te;
struct eigrp_prefix_entry *pe;
struct listnode *node, *node2, *nnode, *nnode2;
struct access_list *alist;
struct prefix_list *plist;
struct access_list *alist_i;
struct prefix_list *plist_i;
struct eigrp *e;
struct prefix_ipv4 *dest_addr;
u_int32_t seq_no = nbr->ei->eigrp->sequence_number;
ep = eigrp_packet_new(nbr->ei->ifp->mtu);
/* Prepare EIGRP EOT UPDATE header */
eigrp_packet_header_init(EIGRP_OPC_UPDATE, nbr->ei, ep->s, EIGRP_EOT_FLAG,
seq_no,
nbr->recv_sequence_number);
// encode Authentication TLV, if needed
if((IF_DEF_PARAMS (nbr->ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5) &&
(IF_DEF_PARAMS (nbr->ei->ifp)->auth_keychain != NULL)) {
length += eigrp_add_authTLV_MD5_to_stream(ep->s,nbr->ei);
}
for (ALL_LIST_ELEMENTS(nbr->ei->eigrp->topology_table, node, nnode, pe)) {
for (ALL_LIST_ELEMENTS(pe->entries, node2, nnode2, te)) {
if ((te->ei == nbr->ei)
&& (te->prefix->nt == EIGRP_TOPOLOGY_TYPE_REMOTE))
continue;
if ((length + 0x001D) > (u_int16_t)nbr->ei->ifp->mtu) {
eigrp_update_place_on_nbr_queue (nbr, ep, seq_no, length);
eigrp_send_packet_reliably(nbr);
seq_no++;
length = EIGRP_HEADER_LEN;
ep = eigrp_packet_new(nbr->ei->ifp->mtu);
eigrp_packet_header_init(EIGRP_OPC_UPDATE, nbr->ei, ep->s, EIGRP_EOT_FLAG,
seq_no, nbr->recv_sequence_number);
if((IF_DEF_PARAMS (nbr->ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5) &&
(IF_DEF_PARAMS (nbr->ei->ifp)->auth_keychain != NULL))
{
length += eigrp_add_authTLV_MD5_to_stream(ep->s,nbr->ei);
}
}
/* Get destination address from prefix */
dest_addr = pe->destination_ipv4;
/*
* Filtering
*/
//TODO: Work in progress
/* get list from eigrp process */
e = eigrp_lookup();
/* Get access-lists and prefix-lists from process and interface */
alist = e->list[EIGRP_FILTER_OUT];
plist = e->prefix[EIGRP_FILTER_OUT];
alist_i = nbr->ei->list[EIGRP_FILTER_OUT];
plist_i = nbr->ei->prefix[EIGRP_FILTER_OUT];
/* Check if any list fits */
if ((alist
&& access_list_apply (alist,
(struct prefix *) dest_addr) == FILTER_DENY)||
(plist && prefix_list_apply (plist,
(struct prefix *) dest_addr) == PREFIX_DENY)||
(alist_i && access_list_apply (alist_i,
(struct prefix *) dest_addr) == FILTER_DENY)||
(plist_i && prefix_list_apply (plist_i,
(struct prefix *) dest_addr) == PREFIX_DENY)) {
//pe->reported_metric.delay = EIGRP_MAX_METRIC;
continue;
} else {
length += eigrp_add_internalTLV_to_stream(ep->s, pe);
}
}
}
eigrp_update_place_on_nbr_queue (nbr, ep, seq_no, length);
eigrp_send_packet_reliably(nbr);
}
void eigrp_update_send(struct eigrp_interface *ei)
{
struct eigrp_packet *ep;
struct listnode *node, *nnode;
struct eigrp_neighbor *nbr;
struct eigrp_prefix_entry *pe;
u_char has_tlv;
struct access_list *alist;
struct prefix_list *plist;
struct access_list *alist_i;
struct prefix_list *plist_i;
struct eigrp *e;
struct prefix_ipv4 *dest_addr;
bool packet_sent = false;
u_int16_t length = EIGRP_HEADER_LEN;
ep = eigrp_packet_new(ei->ifp->mtu);
/* Prepare EIGRP INIT UPDATE header */
eigrp_packet_header_init(EIGRP_OPC_UPDATE, ei, ep->s, 0,
ei->eigrp->sequence_number, 0);
// encode Authentication TLV, if needed
if ((IF_DEF_PARAMS(ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5)
&& (IF_DEF_PARAMS(ei->ifp)->auth_keychain != NULL)) {
length += eigrp_add_authTLV_MD5_to_stream(ep->s, ei);
}
has_tlv = 0;
for (ALL_LIST_ELEMENTS(ei->eigrp->topology_changes_internalIPV4, node,
nnode, pe)) {
if (pe->req_action & EIGRP_FSM_NEED_UPDATE) {
/* Get destination address from prefix */
dest_addr = pe->destination_ipv4;
/*
* Filtering
*/
// TODO: Work in progress
/* get list from eigrp process */
e = eigrp_lookup();
/* Get access-lists and prefix-lists from process and
* interface */
alist = e->list[EIGRP_FILTER_OUT];
plist = e->prefix[EIGRP_FILTER_OUT];
alist_i = ei->list[EIGRP_FILTER_OUT];
plist_i = ei->prefix[EIGRP_FILTER_OUT];
/* Check if any list fits */
if ((alist
&& access_list_apply(alist,
(struct prefix *)dest_addr)
== FILTER_DENY)
|| (plist
&& prefix_list_apply(plist,
(struct prefix *)dest_addr)
== PREFIX_DENY)
|| (alist_i
&& access_list_apply(alist_i,
(struct prefix *)dest_addr)
== FILTER_DENY)
|| (plist_i
&& prefix_list_apply(plist_i,
(struct prefix *)dest_addr)
== PREFIX_DENY)) {
zlog_info("PROC OUT: Skipping");
// pe->reported_metric.delay = EIGRP_MAX_METRIC;
zlog_info("PROC OUT Prefix: %s",
inet_ntoa(dest_addr->prefix));
continue;
} else {
zlog_info("PROC OUT: NENastavujem metriku ");
length += eigrp_add_internalTLV_to_stream(ep->s,
pe);
has_tlv = 1;
}
/*
* End of filtering
*/
/* NULL the pointer */
dest_addr = NULL;
}
}
if (!has_tlv) {
eigrp_packet_free(ep);
return;
}
if ((IF_DEF_PARAMS(ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5)
&& (IF_DEF_PARAMS(ei->ifp)->auth_keychain != NULL)) {
eigrp_make_md5_digest(ei, ep->s, EIGRP_AUTH_UPDATE_FLAG);
}
/* EIGRP Checksum */
eigrp_packet_checksum(ei, ep->s, length);
ep->length = length;
ep->dst.s_addr = htonl(EIGRP_MULTICAST_ADDRESS);
/*This ack number we await from neighbor*/
ep->sequence_number = ei->eigrp->sequence_number;
if (IS_DEBUG_EIGRP_PACKET(0, RECV))
zlog_debug("Enqueuing Update length[%u] Seq [%u]", length,
ep->sequence_number);
for (ALL_LIST_ELEMENTS(ei->nbrs, node, nnode, nbr)) {
if (nbr->state == EIGRP_NEIGHBOR_UP) {
packet_sent = true;
/*Put packet to retransmission queue*/
eigrp_fifo_push_head(nbr->retrans_queue, ep);
if (nbr->retrans_queue->count == 1) {
eigrp_send_packet_reliably(nbr);
}
}
}
if (!packet_sent)
eigrp_packet_free(ep);
}
void eigrp_update_send_all(struct eigrp *eigrp,
struct eigrp_interface *exception)
{
struct eigrp_interface *iface;
struct listnode *node, *node2, *nnode2;
struct eigrp_prefix_entry *pe;
for (ALL_LIST_ELEMENTS_RO(eigrp->eiflist, node, iface)) {
if (iface != exception) {
eigrp_update_send(iface);
}
}
for (ALL_LIST_ELEMENTS(eigrp->topology_changes_internalIPV4, node2,
nnode2, pe)) {
if (pe->req_action & EIGRP_FSM_NEED_UPDATE) {
pe->req_action &= ~EIGRP_FSM_NEED_UPDATE;
listnode_delete(eigrp->topology_changes_internalIPV4,
pe);
zlog_debug("UPDATE COUNT: %d",
eigrp->topology_changes_internalIPV4->count);
}
}
}
/**
* @fn eigrp_update_send_GR_part
*
* @param[in] nbr contains neighbor who would receive Graceful
* restart
*
* @return void
*
* @par
* Function used for sending Graceful restart Update packet
* and if there are multiple chunks, send only one of them.
* It is called from thread. Do not call it directly.
*
* Uses nbr_gr_packet_type from neighbor.
*/
static void eigrp_update_send_GR_part(struct eigrp_neighbor *nbr)
{
struct eigrp_packet *ep;
u_int16_t length = EIGRP_HEADER_LEN;
struct listnode *node, *nnode;
struct eigrp_prefix_entry *pe;
struct prefix_ipv4 *dest_addr;
struct eigrp *e;
struct access_list *alist, *alist_i;
struct prefix_list *plist, *plist_i;
struct list *prefixes;
u_int32_t flags;
unsigned int send_prefixes;
struct TLV_IPv4_Internal_type *tlv_max;
/* get prefixes to send to neighbor */
prefixes = nbr->nbr_gr_prefixes_send;
send_prefixes = 0;
length = EIGRP_HEADER_LEN;
/* if there already were last packet chunk, we won't continue */
if (nbr->nbr_gr_packet_type == EIGRP_PACKET_PART_LAST)
return;
/* if this is first packet chunk, we need to decide,
* if there will be one or more chunks */
if (nbr->nbr_gr_packet_type == EIGRP_PACKET_PART_FIRST) {
if (prefixes->count <= EIGRP_TLV_MAX_IPv4) {
/* there will be only one chunk */
flags = EIGRP_INIT_FLAG + EIGRP_RS_FLAG
+ EIGRP_EOT_FLAG;
nbr->nbr_gr_packet_type = EIGRP_PACKET_PART_LAST;
} else {
/* there will be more chunks */
flags = EIGRP_INIT_FLAG + EIGRP_RS_FLAG;
nbr->nbr_gr_packet_type = EIGRP_PACKET_PART_NA;
}
} else {
/* this is not first chunk, and we need to decide,
* if there will be more chunks */
if (prefixes->count <= EIGRP_TLV_MAX_IPv4) {
/* this is last chunk */
flags = EIGRP_EOT_FLAG;
nbr->nbr_gr_packet_type = EIGRP_PACKET_PART_LAST;
} else {
/* there will be more chunks */
flags = 0;
nbr->nbr_gr_packet_type = EIGRP_PACKET_PART_NA;
}
}
ep = eigrp_packet_new(nbr->ei->ifp->mtu);
/* Prepare EIGRP Graceful restart UPDATE header */
eigrp_packet_header_init(EIGRP_OPC_UPDATE, nbr->ei, ep->s, flags,
nbr->ei->eigrp->sequence_number,
nbr->recv_sequence_number);
// encode Authentication TLV, if needed
if ((IF_DEF_PARAMS(nbr->ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5)
&& (IF_DEF_PARAMS(nbr->ei->ifp)->auth_keychain != NULL)) {
length += eigrp_add_authTLV_MD5_to_stream(ep->s, nbr->ei);
}
for (ALL_LIST_ELEMENTS(nbr->ei->eigrp->topology_table, node, nnode,
pe)) {
/*
* Filtering
*/
dest_addr = pe->destination_ipv4;
/* get list from eigrp process */
e = eigrp_lookup();
/* Get access-lists and prefix-lists from process and interface
*/
alist = e->list[EIGRP_FILTER_OUT];
plist = e->prefix[EIGRP_FILTER_OUT];
alist_i = nbr->ei->list[EIGRP_FILTER_OUT];
plist_i = nbr->ei->prefix[EIGRP_FILTER_OUT];
/* Check if any list fits */
if ((alist
&& access_list_apply(alist, (struct prefix *)dest_addr)
== FILTER_DENY)
|| (plist
&& prefix_list_apply(plist, (struct prefix *)dest_addr)
== PREFIX_DENY)
|| (alist_i
&& access_list_apply(alist_i,
(struct prefix *)dest_addr)
== FILTER_DENY)
|| (plist_i
&& prefix_list_apply(plist_i,
(struct prefix *)dest_addr)
== PREFIX_DENY)) {
/* do not send filtered route */
zlog_info("Filtered prefix %s won't be sent out.",
inet_ntoa(dest_addr->prefix));
} else {
/* sending route which wasn't filtered */
length += eigrp_add_internalTLV_to_stream(ep->s, pe);
send_prefixes++;
}
alist = e->list[EIGRP_FILTER_IN];
plist = e->prefix[EIGRP_FILTER_IN];
alist_i = nbr->ei->list[EIGRP_FILTER_IN];
plist_i = nbr->ei->prefix[EIGRP_FILTER_IN];
/* Check if any list fits */
if ((alist
&& access_list_apply(alist, (struct prefix *)dest_addr)
== FILTER_DENY)
|| (plist
&& prefix_list_apply(plist, (struct prefix *)dest_addr)
== PREFIX_DENY)
|| (alist_i
&& access_list_apply(alist_i,
(struct prefix *)dest_addr)
== FILTER_DENY)
|| (plist_i
&& prefix_list_apply(plist_i,
(struct prefix *)dest_addr)
== PREFIX_DENY)) {
/* do not send filtered route */
zlog_info("Filtered prefix %s will be removed.",
inet_ntoa(dest_addr->prefix));
tlv_max = eigrp_IPv4_InternalTLV_new();
tlv_max->type = EIGRP_TLV_IPv4_INT;
tlv_max->length = 28U;
tlv_max->metric = pe->reported_metric;
/* set delay to MAX */
tlv_max->metric.delay = EIGRP_MAX_METRIC;
tlv_max->destination = pe->destination_ipv4->prefix;
tlv_max->prefix_length =
pe->destination_ipv4->prefixlen;
/* prepare message for FSM */
struct eigrp_fsm_action_message *fsm_msg;
fsm_msg = XCALLOC(
MTYPE_EIGRP_FSM_MSG,
sizeof(struct eigrp_fsm_action_message));
struct eigrp_neighbor_entry *entry =
eigrp_prefix_entry_lookup(pe->entries, nbr);
fsm_msg->packet_type = EIGRP_OPC_UPDATE;
fsm_msg->eigrp = e;
fsm_msg->data_type = EIGRP_TLV_IPv4_INT;
fsm_msg->adv_router = nbr;
fsm_msg->data.ipv4_int_type = tlv_max;
fsm_msg->entry = entry;
fsm_msg->prefix = pe;
/* send message to FSM */
int event = eigrp_get_fsm_event(fsm_msg);
eigrp_fsm_event(fsm_msg, event);
/* free memory used by TLV */
eigrp_IPv4_InternalTLV_free(tlv_max);
}
/*
* End of filtering
*/
/* NULL the pointer */
dest_addr = NULL;
/* delete processed prefix from list */
listnode_delete(prefixes, pe);
/* if there are enough prefixes, send packet */
if (send_prefixes >= EIGRP_TLV_MAX_IPv4)
break;
}
/* compute Auth digest */
if ((IF_DEF_PARAMS(nbr->ei->ifp)->auth_type == EIGRP_AUTH_TYPE_MD5)
&& (IF_DEF_PARAMS(nbr->ei->ifp)->auth_keychain != NULL)) {
eigrp_make_md5_digest(nbr->ei, ep->s, EIGRP_AUTH_UPDATE_FLAG);
}
/* EIGRP Checksum */
eigrp_packet_checksum(nbr->ei, ep->s, length);
ep->length = length;
ep->dst.s_addr = nbr->src.s_addr;
/*This ack number we await from neighbor*/
ep->sequence_number = nbr->ei->eigrp->sequence_number;
if (IS_DEBUG_EIGRP_PACKET(0, RECV))
zlog_debug("Enqueuing Update Init Len [%u] Seq [%u] Dest [%s]",
ep->length, ep->sequence_number, inet_ntoa(ep->dst));
/*Put packet to retransmission queue*/
eigrp_fifo_push_head(nbr->retrans_queue, ep);
if (nbr->retrans_queue->count == 1) {
eigrp_send_packet_reliably(nbr);
}
}
/**
* @fn eigrp_update_send_GR_thread
*
* @param[in] thread contains neighbor who would receive
* Graceful restart
*
* @return int always 0
*
* @par
* Function used for sending Graceful restart Update packet
* in thread, it is prepared for multiple chunks of packet.
*
* Uses nbr_gr_packet_type and t_nbr_send_gr from neighbor.
*/
int eigrp_update_send_GR_thread(struct thread *thread)
{
struct eigrp_neighbor *nbr;
/* get argument from thread */
nbr = THREAD_ARG(thread);
/* remove this thread pointer */
nbr->t_nbr_send_gr = NULL;
/* if there is packet waiting in queue,
* schedule this thread again with small delay */
if (nbr->retrans_queue->count > 0) {
nbr->t_nbr_send_gr = NULL;
thread_add_timer_msec(master, eigrp_update_send_GR_thread, nbr,
10, &nbr->t_nbr_send_gr);
return 0;
}
/* send GR EIGRP packet chunk */
eigrp_update_send_GR_part(nbr);
/* if it wasn't last chunk, schedule this thread again */
if (nbr->nbr_gr_packet_type != EIGRP_PACKET_PART_LAST) {
thread_execute(master, eigrp_update_send_GR_thread, nbr, 0);
nbr->t_nbr_send_gr = NULL;
}
return 0;
}
/**
* @fn eigrp_update_send_GR
*
* @param[in] nbr Neighbor who would receive Graceful
* restart
* @param[in] gr_type Who executed Graceful restart
* @param[in] vty Virtual terminal for log output
*
* @return void
*
* @par
* Function used for sending Graceful restart Update packet:
* Creates Update packet with INIT, RS, EOT flags and include
* all route except those filtered
*/
void eigrp_update_send_GR(struct eigrp_neighbor *nbr, enum GR_type gr_type,
struct vty *vty)
{
struct eigrp_prefix_entry *pe2;
struct listnode *node2, *nnode2;
struct list *prefixes;
if (gr_type == EIGRP_GR_FILTER) {
/* function was called after applying filtration */
zlog_info(
"Neighbor %s (%s) is resync: route configuration changed",
inet_ntoa(nbr->src),
ifindex2ifname(nbr->ei->ifp->ifindex, VRF_DEFAULT));
} else if (gr_type == EIGRP_GR_MANUAL) {
/* Graceful restart was called manually */
zlog_info("Neighbor %s (%s) is resync: manually cleared",
inet_ntoa(nbr->src),
ifindex2ifname(nbr->ei->ifp->ifindex, VRF_DEFAULT));
if (vty != NULL) {
vty_time_print(vty, 0);
vty_out(vty,
"Neighbor %s (%s) is resync: manually cleared\n",
inet_ntoa(nbr->src),
ifindex2ifname(nbr->ei->ifp->ifindex,
VRF_DEFAULT));
}
}
prefixes = list_new();
/* add all prefixes from topology table to list */
for (ALL_LIST_ELEMENTS(nbr->ei->eigrp->topology_table, node2, nnode2,
pe2)) {
listnode_add(prefixes, pe2);
}
/* save prefixes to neighbor */
nbr->nbr_gr_prefixes_send = prefixes;
/* indicate, that this is first GR Update packet chunk */
nbr->nbr_gr_packet_type = EIGRP_PACKET_PART_FIRST;
/* execute packet sending in thread */
thread_execute(master, eigrp_update_send_GR_thread, nbr, 0);
nbr->t_nbr_send_gr = NULL;
}
/**
* @fn eigrp_update_send_interface_GR
*
* @param[in] ei Interface to neighbors of which the GR
* is sent
* @param[in] gr_type Who executed Graceful restart
* @param[in] vty Virtual terminal for log output
*
* @return void
*
* @par
* Function used for sending Graceful restart Update packet
* to all neighbors on specified interface.
*/
void eigrp_update_send_interface_GR(struct eigrp_interface *ei,
enum GR_type gr_type, struct vty *vty)
{
struct listnode *node;
struct eigrp_neighbor *nbr;
/* iterate over all neighbors on eigrp interface */
for (ALL_LIST_ELEMENTS_RO(ei->nbrs, node, nbr)) {
/* send GR to neighbor */
eigrp_update_send_GR(nbr, gr_type, vty);
}
}
/**
* @fn eigrp_update_send_process_GR
*
* @param[in] eigrp EIGRP process
* @param[in] gr_type Who executed Graceful restart
* @param[in] vty Virtual terminal for log output
*
* @return void
*
* @par
* Function used for sending Graceful restart Update packet
* to all neighbors in eigrp process.
*/
void eigrp_update_send_process_GR(struct eigrp *eigrp, enum GR_type gr_type,
struct vty *vty)
{
struct listnode *node;
struct eigrp_interface *ei;
/* iterate over all eigrp interfaces */
for (ALL_LIST_ELEMENTS_RO(eigrp->eiflist, node, ei)) {
/* send GR to all neighbors on interface */
eigrp_update_send_interface_GR(ei, gr_type, vty);
}
}
|