-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathzebra_evpn_mac.c
2557 lines (2192 loc) · 69 KB
/
zebra_evpn_mac.c
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
/*
* Zebra EVPN for VxLAN code
* Copyright (C) 2016, 2017 Cumulus Networks, Inc.
*
* This file is part of FRR.
*
* FRR 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.
*
* FRR 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 FRR; see the file COPYING. If not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#include <zebra.h>
#include "hash.h"
#include "interface.h"
#include "jhash.h"
#include "memory.h"
#include "prefix.h"
#include "vlan.h"
#include "json.h"
#include "printfrr.h"
#include "zebra/zserv.h"
#include "zebra/debug.h"
#include "zebra/zebra_router.h"
#include "zebra/zebra_errors.h"
#include "zebra/zebra_vrf.h"
#include "zebra/zebra_evpn.h"
#include "zebra/zebra_evpn_mh.h"
#include "zebra/zebra_evpn_mac.h"
#include "zebra/zebra_evpn_neigh.h"
DEFINE_MTYPE_STATIC(ZEBRA, MAC, "EVPN MAC");
/*
* Return number of valid MACs in an EVPN's MAC hash table - all
* remote MACs and non-internal (auto) local MACs count.
*/
uint32_t num_valid_macs(struct zebra_evpn *zevpn)
{
unsigned int i;
uint32_t num_macs = 0;
struct hash *hash;
struct hash_bucket *hb;
struct zebra_mac *mac;
hash = zevpn->mac_table;
if (!hash)
return num_macs;
for (i = 0; i < hash->size; i++) {
for (hb = hash->index[i]; hb; hb = hb->next) {
mac = (struct zebra_mac *)hb->data;
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)
|| CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)
|| !CHECK_FLAG(mac->flags, ZEBRA_MAC_AUTO))
num_macs++;
}
}
return num_macs;
}
uint32_t num_dup_detected_macs(struct zebra_evpn *zevpn)
{
unsigned int i;
uint32_t num_macs = 0;
struct hash *hash;
struct hash_bucket *hb;
struct zebra_mac *mac;
hash = zevpn->mac_table;
if (!hash)
return num_macs;
for (i = 0; i < hash->size; i++) {
for (hb = hash->index[i]; hb; hb = hb->next) {
mac = (struct zebra_mac *)hb->data;
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE))
num_macs++;
}
}
return num_macs;
}
/* Setup mac_list against the access port. This is done when a mac uses
* the ifp as destination for the first time
*/
static void zebra_evpn_mac_ifp_new(struct zebra_if *zif)
{
if (IS_ZEBRA_DEBUG_EVPN_MH_MAC)
zlog_debug("MAC list created for ifp %s (%u)", zif->ifp->name,
zif->ifp->ifindex);
zif->mac_list = list_new();
listset_app_node_mem(zif->mac_list);
}
/* Unlink local mac from a destination access port */
static void zebra_evpn_mac_ifp_unlink(struct zebra_mac *zmac)
{
struct zebra_if *zif;
struct interface *ifp = zmac->ifp;
if (!ifp)
return;
if (IS_ZEBRA_DEBUG_EVPN_MH_MAC)
zlog_debug("VNI %d MAC %pEA unlinked from ifp %s (%u)",
zmac->zevpn->vni,
&zmac->macaddr,
ifp->name, ifp->ifindex);
zif = ifp->info;
list_delete_node(zif->mac_list, &zmac->ifp_listnode);
zmac->ifp = NULL;
}
/* Free up the mac_list if any as a part of the interface del/cleanup */
void zebra_evpn_mac_ifp_del(struct interface *ifp)
{
struct zebra_if *zif = ifp->info;
struct listnode *node;
struct zebra_mac *zmac;
if (zif->mac_list) {
if (IS_ZEBRA_DEBUG_EVPN_MH_MAC)
zlog_debug("MAC list deleted for ifp %s (%u)",
zif->ifp->name, zif->ifp->ifindex);
for (ALL_LIST_ELEMENTS_RO(zif->mac_list, node, zmac)) {
zebra_evpn_mac_ifp_unlink(zmac);
}
list_delete(&zif->mac_list);
}
}
/* Link local mac to destination access port. This is done only if the
* local mac is associated with a zero ESI i.e. single attach or lacp-bypass
* bridge port member
*/
static void zebra_evpn_mac_ifp_link(struct zebra_mac *zmac,
struct interface *ifp)
{
struct zebra_if *zif;
if (!CHECK_FLAG(zmac->flags, ZEBRA_MAC_LOCAL))
return;
/* already linked to the destination */
if (zmac->ifp == ifp)
return;
/* unlink the mac from any old destination */
if (zmac->ifp)
zebra_evpn_mac_ifp_unlink(zmac);
if (!ifp)
return;
zif = ifp->info;
/* the interface mac_list is created on first mac link attempt */
if (!zif->mac_list)
zebra_evpn_mac_ifp_new(zif);
if (IS_ZEBRA_DEBUG_EVPN_MH_MAC)
zlog_debug("VNI %d MAC %pEA linked to ifp %s (%u)",
zmac->zevpn->vni,
&zmac->macaddr,
ifp->name, ifp->ifindex);
zmac->ifp = ifp;
listnode_init(&zmac->ifp_listnode, zmac);
listnode_add(zif->mac_list, &zmac->ifp_listnode);
}
/* If the mac is a local mac clear links to destination access port */
void zebra_evpn_mac_clear_fwd_info(struct zebra_mac *zmac)
{
zebra_evpn_mac_ifp_unlink(zmac);
memset(&zmac->fwd_info, 0, sizeof(zmac->fwd_info));
}
/*
* Install remote MAC into the forwarding plane.
*/
int zebra_evpn_rem_mac_install(struct zebra_evpn *zevpn, struct zebra_mac *mac,
bool was_static)
{
const struct zebra_if *zif, *br_zif;
const struct zebra_l2info_vxlan *vxl;
bool sticky;
enum zebra_dplane_result res;
const struct interface *br_ifp;
vlanid_t vid;
uint32_t nhg_id;
struct in_addr vtep_ip;
zif = zevpn->vxlan_if->info;
if (!zif)
return -1;
br_ifp = zif->brslave_info.br_if;
if (br_ifp == NULL)
return -1;
vxl = &zif->l2info.vxl;
sticky = !!CHECK_FLAG(mac->flags,
(ZEBRA_MAC_STICKY | ZEBRA_MAC_REMOTE_DEF_GW));
/* If nexthop group for the FDB entry is inactive (not programmed in
* the dataplane) the MAC entry cannot be installed
*/
if (mac->es) {
if (!(mac->es->flags & ZEBRA_EVPNES_NHG_ACTIVE))
return -1;
nhg_id = mac->es->nhg_id;
vtep_ip.s_addr = 0;
} else {
nhg_id = 0;
vtep_ip = mac->fwd_info.r_vtep_ip;
}
br_zif = (const struct zebra_if *)(br_ifp->info);
if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif))
vid = vxl->access_vlan;
else
vid = 0;
res = dplane_rem_mac_add(zevpn->vxlan_if, br_ifp, vid, &mac->macaddr,
vtep_ip, sticky, nhg_id, was_static);
if (res != ZEBRA_DPLANE_REQUEST_FAILURE)
return 0;
else
return -1;
}
/*
* Uninstall remote MAC from the forwarding plane.
*/
int zebra_evpn_rem_mac_uninstall(struct zebra_evpn *zevpn,
struct zebra_mac *mac, bool force)
{
const struct zebra_if *zif, *br_zif;
const struct zebra_l2info_vxlan *vxl;
struct in_addr vtep_ip;
const struct interface *ifp, *br_ifp;
vlanid_t vid;
enum zebra_dplane_result res;
/* If the MAC was not installed there is no need to uninstall it */
if (!force && mac->es && !(mac->es->flags & ZEBRA_EVPNES_NHG_ACTIVE))
return -1;
if (!zevpn->vxlan_if) {
if (IS_ZEBRA_DEBUG_VXLAN)
zlog_debug(
"VNI %u hash %p couldn't be uninstalled - no intf",
zevpn->vni, zevpn);
return -1;
}
zif = zevpn->vxlan_if->info;
if (!zif)
return -1;
br_ifp = zif->brslave_info.br_if;
if (br_ifp == NULL)
return -1;
vxl = &zif->l2info.vxl;
br_zif = (const struct zebra_if *)br_ifp->info;
if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif))
vid = vxl->access_vlan;
else
vid = 0;
ifp = zevpn->vxlan_if;
vtep_ip = mac->fwd_info.r_vtep_ip;
res = dplane_rem_mac_del(ifp, br_ifp, vid, &mac->macaddr, vtep_ip);
if (res != ZEBRA_DPLANE_REQUEST_FAILURE)
return 0;
else
return -1;
}
/*
* Decrement neighbor refcount of MAC; uninstall and free it if
* appropriate.
*/
void zebra_evpn_deref_ip2mac(struct zebra_evpn *zevpn, struct zebra_mac *mac)
{
if (!CHECK_FLAG(mac->flags, ZEBRA_MAC_AUTO))
return;
/* If all remote neighbors referencing a remote MAC go away,
* we need to uninstall the MAC.
*/
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)
&& remote_neigh_count(mac) == 0) {
zebra_evpn_rem_mac_uninstall(zevpn, mac, false /*force*/);
zebra_evpn_es_mac_deref_entry(mac);
UNSET_FLAG(mac->flags, ZEBRA_MAC_REMOTE);
}
/* If no references, delete the MAC. */
if (!zebra_evpn_mac_in_use(mac))
zebra_evpn_mac_del(zevpn, mac);
}
static void zebra_evpn_mac_get_access_info(struct zebra_mac *mac,
struct interface **ifpP,
vlanid_t *vid)
{
/* if the mac is associated with an ES we must get the access
* info from the ES
*/
if (mac->es) {
struct zebra_if *zif;
/* get the access port from the es */
*ifpP = mac->es->zif ? mac->es->zif->ifp : NULL;
/* get the vlan from the EVPN */
if (mac->zevpn->vxlan_if) {
zif = mac->zevpn->vxlan_if->info;
*vid = zif->l2info.vxl.access_vlan;
} else {
*vid = 0;
}
} else {
struct zebra_ns *zns;
*vid = mac->fwd_info.local.vid;
zns = zebra_ns_lookup(mac->fwd_info.local.ns_id);
*ifpP = if_lookup_by_index_per_ns(zns,
mac->fwd_info.local.ifindex);
}
}
#define MAC_BUF_SIZE 256
static char *zebra_evpn_zebra_mac_flag_dump(struct zebra_mac *mac, char *buf,
size_t len)
{
if (mac->flags == 0) {
snprintfrr(buf, len, "None ");
return buf;
}
snprintfrr(
buf, len, "%s%s%s%s%s%s%s%s%s%s%s%s",
CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL) ? "LOC " : "",
CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE) ? "REM " : "",
CHECK_FLAG(mac->flags, ZEBRA_MAC_AUTO) ? "AUTO " : "",
CHECK_FLAG(mac->flags, ZEBRA_MAC_STICKY) ? "STICKY " : "",
CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE_RMAC) ? "REM Router "
: "",
CHECK_FLAG(mac->flags, ZEBRA_MAC_DEF_GW) ? "Default GW " : "",
CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE_DEF_GW) ? "REM DEF GW "
: "",
CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE) ? "DUP " : "",
CHECK_FLAG(mac->flags, ZEBRA_MAC_FPM_SENT) ? "FPM " : "",
CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_ACTIVE) ? "LOC Active "
: "",
CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_PROXY) ? "PROXY " : "",
CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL_INACTIVE)
? "LOC Inactive "
: "");
return buf;
}
static void zebra_evpn_dad_mac_auto_recovery_exp(struct thread *t)
{
struct zebra_vrf *zvrf = NULL;
struct zebra_mac *mac = NULL;
struct zebra_evpn *zevpn = NULL;
struct listnode *node = NULL;
struct zebra_neigh *nbr = NULL;
mac = THREAD_ARG(t);
/* since this is asynchronous we need sanity checks*/
zvrf = vrf_info_lookup(mac->zevpn->vrf_id);
if (!zvrf)
return;
zevpn = zebra_evpn_lookup(mac->zevpn->vni);
if (!zevpn)
return;
mac = zebra_evpn_mac_lookup(zevpn, &mac->macaddr);
if (!mac)
return;
if (IS_ZEBRA_DEBUG_VXLAN) {
char mac_buf[MAC_BUF_SIZE];
zlog_debug(
"%s: duplicate addr mac %pEA flags %slearn count %u host count %u auto recovery expired",
__func__, &mac->macaddr,
zebra_evpn_zebra_mac_flag_dump(mac, mac_buf,
sizeof(mac_buf)),
mac->dad_count, listcount(mac->neigh_list));
}
/* Remove all IPs as duplicate associcated with this MAC */
for (ALL_LIST_ELEMENTS_RO(mac->neigh_list, node, nbr)) {
if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE)) {
if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL))
ZEBRA_NEIGH_SET_INACTIVE(nbr);
else if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_REMOTE))
zebra_evpn_rem_neigh_install(
zevpn, nbr, false /*was_static*/);
}
UNSET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE);
nbr->dad_count = 0;
nbr->detect_start_time.tv_sec = 0;
nbr->dad_dup_detect_time = 0;
}
UNSET_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE);
mac->dad_count = 0;
mac->detect_start_time.tv_sec = 0;
mac->detect_start_time.tv_usec = 0;
mac->dad_dup_detect_time = 0;
mac->dad_mac_auto_recovery_timer = NULL;
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) {
/* Inform to BGP */
if (zebra_evpn_mac_send_add_to_client(zevpn->vni, &mac->macaddr,
mac->flags, mac->loc_seq,
mac->es))
return;
/* Process all neighbors associated with this MAC. */
zebra_evpn_process_neigh_on_local_mac_change(zevpn, mac, 0,
0 /*es_change*/);
} else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) {
zebra_evpn_process_neigh_on_remote_mac_add(zevpn, mac);
/* Install the entry. */
zebra_evpn_rem_mac_install(zevpn, mac, false /* was_static */);
}
}
static void zebra_evpn_dup_addr_detect_for_mac(struct zebra_vrf *zvrf,
struct zebra_mac *mac,
struct in_addr vtep_ip,
bool do_dad, bool *is_dup_detect,
bool is_local)
{
struct zebra_neigh *nbr;
struct listnode *node = NULL;
struct timeval elapsed = {0, 0};
bool reset_params = false;
if (!(zebra_evpn_do_dup_addr_detect(zvrf) && do_dad))
return;
/* MAC is detected as duplicate,
* Local MAC event -> hold on advertising to BGP.
* Remote MAC event -> hold on installing it.
*/
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE)) {
if (IS_ZEBRA_DEBUG_VXLAN) {
char mac_buf[MAC_BUF_SIZE];
zlog_debug(
"%s: duplicate addr MAC %pEA flags %sskip update to client, learn count %u recover time %u",
__func__, &mac->macaddr,
zebra_evpn_zebra_mac_flag_dump(mac, mac_buf,
sizeof(mac_buf)),
mac->dad_count, zvrf->dad_freeze_time);
}
/* For duplicate MAC do not update
* client but update neigh due to
* this MAC update.
*/
if (zvrf->dad_freeze)
*is_dup_detect = true;
return;
}
/* Check if detection time (M-secs) expired.
* Reset learn count and detection start time.
*/
monotime_since(&mac->detect_start_time, &elapsed);
reset_params = (elapsed.tv_sec > zvrf->dad_time);
if (is_local && !reset_params) {
/* RFC-7432: A PE/VTEP that detects a MAC mobility
* event via LOCAL learning starts an M-second timer.
*
* NOTE: This is the START of the probe with count is
* 0 during LOCAL learn event.
* (mac->dad_count == 0 || elapsed.tv_sec >= zvrf->dad_time)
*/
reset_params = !mac->dad_count;
}
if (reset_params) {
if (IS_ZEBRA_DEBUG_VXLAN) {
char mac_buf[MAC_BUF_SIZE];
zlog_debug(
"%s: duplicate addr MAC %pEA flags %sdetection time passed, reset learn count %u",
__func__, &mac->macaddr,
zebra_evpn_zebra_mac_flag_dump(mac, mac_buf,
sizeof(mac_buf)),
mac->dad_count);
}
mac->dad_count = 0;
/* Start dup. addr detection (DAD) start time,
* ONLY during LOCAL learn.
*/
if (is_local)
monotime(&mac->detect_start_time);
} else if (!is_local) {
/* For REMOTE MAC, increment detection count
* ONLY while in probe window, once window passed,
* next local learn event should trigger DAD.
*/
mac->dad_count++;
}
/* For LOCAL MAC learn event, once count is reset above via either
* initial/start detection time or passed the probe time, the count
* needs to be incremented.
*/
if (is_local)
mac->dad_count++;
if (mac->dad_count >= zvrf->dad_max_moves) {
flog_warn(EC_ZEBRA_DUP_MAC_DETECTED,
"VNI %u: MAC %pEA detected as duplicate during %s VTEP %pI4",
mac->zevpn->vni, &mac->macaddr,
is_local ? "local update, last" :
"remote update, from", &vtep_ip);
SET_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE);
/* Capture Duplicate detection time */
mac->dad_dup_detect_time = monotime(NULL);
/* Mark all IPs/Neighs as duplicate
* associcated with this MAC
*/
for (ALL_LIST_ELEMENTS_RO(mac->neigh_list, node, nbr)) {
/* Ony Mark IPs which are Local */
if (!CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL))
continue;
SET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE);
nbr->dad_dup_detect_time = monotime(NULL);
flog_warn(EC_ZEBRA_DUP_IP_INHERIT_DETECTED,
"VNI %u: MAC %pEA IP %pIA detected as duplicate during %s update, inherit duplicate from MAC",
mac->zevpn->vni, &mac->macaddr, &nbr->ip,
is_local ? "local" : "remote");
}
/* Start auto recovery timer for this MAC */
THREAD_OFF(mac->dad_mac_auto_recovery_timer);
if (zvrf->dad_freeze && zvrf->dad_freeze_time) {
if (IS_ZEBRA_DEBUG_VXLAN) {
char mac_buf[MAC_BUF_SIZE];
zlog_debug(
"%s: duplicate addr MAC %pEA flags %sauto recovery time %u start",
__func__, &mac->macaddr,
zebra_evpn_zebra_mac_flag_dump(
mac, mac_buf, sizeof(mac_buf)),
zvrf->dad_freeze_time);
}
thread_add_timer(zrouter.master,
zebra_evpn_dad_mac_auto_recovery_exp,
mac, zvrf->dad_freeze_time,
&mac->dad_mac_auto_recovery_timer);
}
/* In case of local update, do not inform to client (BGPd),
* upd_neigh for neigh sequence change.
*/
if (zvrf->dad_freeze)
*is_dup_detect = true;
}
}
/*
* Print a specific MAC entry.
*/
void zebra_evpn_print_mac(struct zebra_mac *mac, void *ctxt, json_object *json)
{
struct vty *vty;
struct zebra_neigh *n = NULL;
struct listnode *node = NULL;
char buf1[ETHER_ADDR_STRLEN];
char buf2[INET6_ADDRSTRLEN];
struct zebra_vrf *zvrf;
struct timeval detect_start_time = {0, 0};
char timebuf[MONOTIME_STRLEN];
char thread_buf[THREAD_TIMER_STRLEN];
time_t uptime;
char up_str[MONOTIME_STRLEN];
zvrf = zebra_vrf_get_evpn();
if (!zvrf)
return;
vty = (struct vty *)ctxt;
prefix_mac2str(&mac->macaddr, buf1, sizeof(buf1));
uptime = monotime(NULL);
uptime -= mac->uptime;
frrtime_to_interval(uptime, up_str, sizeof(up_str));
if (json) {
json_object *json_mac = json_object_new_object();
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) {
struct interface *ifp;
vlanid_t vid;
zebra_evpn_mac_get_access_info(mac, &ifp, &vid);
json_object_string_add(json_mac, "type", "local");
if (ifp) {
json_object_string_add(json_mac, "intf",
ifp->name);
json_object_int_add(json_mac, "ifindex",
ifp->ifindex);
}
if (vid)
json_object_int_add(json_mac, "vlan", vid);
} else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) {
json_object_string_add(json_mac, "type", "remote");
json_object_string_addf(json_mac, "remoteVtep", "%pI4",
&mac->fwd_info.r_vtep_ip);
} else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_AUTO))
json_object_string_add(json_mac, "type", "auto");
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_STICKY))
json_object_boolean_true_add(json_mac, "stickyMac");
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_SVI))
json_object_boolean_true_add(json_mac, "sviMac");
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DEF_GW))
json_object_boolean_true_add(json_mac,
"defaultGateway");
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE_DEF_GW))
json_object_boolean_true_add(json_mac,
"remoteGatewayMac");
json_object_string_add(json_mac, "uptime", up_str);
json_object_int_add(json_mac, "localSequence", mac->loc_seq);
json_object_int_add(json_mac, "remoteSequence", mac->rem_seq);
json_object_int_add(json_mac, "detectionCount", mac->dad_count);
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE))
json_object_boolean_true_add(json_mac, "isDuplicate");
else
json_object_boolean_false_add(json_mac, "isDuplicate");
json_object_int_add(json_mac, "syncNeighCount",
mac->sync_neigh_cnt);
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL_INACTIVE))
json_object_boolean_true_add(json_mac, "localInactive");
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_PROXY))
json_object_boolean_true_add(json_mac, "peerProxy");
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_ACTIVE))
json_object_boolean_true_add(json_mac, "peerActive");
if (mac->hold_timer)
json_object_string_add(
json_mac, "peerActiveHold",
thread_timer_to_hhmmss(thread_buf,
sizeof(thread_buf),
mac->hold_timer));
if (mac->es)
json_object_string_add(json_mac, "esi",
mac->es->esi_str);
/* print all the associated neigh */
if (!listcount(mac->neigh_list))
json_object_string_add(json_mac, "neighbors", "none");
else {
json_object *json_active_nbrs = json_object_new_array();
json_object *json_inactive_nbrs =
json_object_new_array();
json_object *json_nbrs = json_object_new_object();
for (ALL_LIST_ELEMENTS_RO(mac->neigh_list, node, n)) {
if (IS_ZEBRA_NEIGH_ACTIVE(n))
json_object_array_add(
json_active_nbrs,
json_object_new_string(
ipaddr2str(
&n->ip, buf2,
sizeof(buf2))));
else
json_object_array_add(
json_inactive_nbrs,
json_object_new_string(
ipaddr2str(
&n->ip, buf2,
sizeof(buf2))));
}
json_object_object_add(json_nbrs, "active",
json_active_nbrs);
json_object_object_add(json_nbrs, "inactive",
json_inactive_nbrs);
json_object_object_add(json_mac, "neighbors",
json_nbrs);
}
json_object_object_add(json, buf1, json_mac);
} else {
vty_out(vty, "MAC: %s\n", buf1);
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) {
struct interface *ifp;
vlanid_t vid;
zebra_evpn_mac_get_access_info(mac, &ifp, &vid);
if (mac->es)
vty_out(vty, " ESI: %s\n", mac->es->esi_str);
if (ifp)
vty_out(vty, " Intf: %s(%u)", ifp->name,
ifp->ifindex);
else
vty_out(vty, " Intf: -");
vty_out(vty, " VLAN: %u", vid);
} else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) {
if (mac->es)
vty_out(vty, " Remote ES: %s",
mac->es->esi_str);
else
vty_out(vty, " Remote VTEP: %pI4",
&mac->fwd_info.r_vtep_ip);
} else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_AUTO)) {
vty_out(vty, " Auto Mac ");
}
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_STICKY))
vty_out(vty, " Sticky Mac ");
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_SVI))
vty_out(vty, " SVI-Mac ");
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DEF_GW))
vty_out(vty, " Default-gateway Mac ");
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE_DEF_GW))
vty_out(vty, " Remote-gateway Mac ");
vty_out(vty, "\n");
vty_out(vty, " Sync-info: neigh#: %u", mac->sync_neigh_cnt);
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL_INACTIVE))
vty_out(vty, " local-inactive");
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_PROXY))
vty_out(vty, " peer-proxy");
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_ACTIVE))
vty_out(vty, " peer-active");
if (mac->hold_timer)
vty_out(vty, " (ht: %s)",
thread_timer_to_hhmmss(thread_buf,
sizeof(thread_buf),
mac->hold_timer));
vty_out(vty, "\n");
vty_out(vty, " Local Seq: %u Remote Seq: %u\n", mac->loc_seq,
mac->rem_seq);
vty_out(vty, " Uptime: %s\n", up_str);
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE)) {
vty_out(vty, " Duplicate, detected at %s",
time_to_string(mac->dad_dup_detect_time,
timebuf));
} else if (mac->dad_count) {
monotime_since(&mac->detect_start_time,
&detect_start_time);
if (detect_start_time.tv_sec <= zvrf->dad_time) {
time_to_string(mac->detect_start_time.tv_sec,
timebuf);
vty_out(vty,
" Duplicate detection started at %s, detection count %u\n",
timebuf, mac->dad_count);
}
}
/* print all the associated neigh */
vty_out(vty, " Neighbors:\n");
if (!listcount(mac->neigh_list))
vty_out(vty, " No Neighbors\n");
else {
for (ALL_LIST_ELEMENTS_RO(mac->neigh_list, node, n)) {
vty_out(vty, " %s %s\n",
ipaddr2str(&n->ip, buf2, sizeof(buf2)),
(IS_ZEBRA_NEIGH_ACTIVE(n)
? "Active"
: "Inactive"));
}
}
vty_out(vty, "\n");
}
}
static char *zebra_evpn_print_mac_flags(struct zebra_mac *mac, char *flags_buf,
size_t flags_buf_sz)
{
snprintf(flags_buf, flags_buf_sz, "%s%s%s%s",
mac->sync_neigh_cnt ? "N" : "",
(mac->flags & ZEBRA_MAC_ES_PEER_ACTIVE) ? "P" : "",
(mac->flags & ZEBRA_MAC_ES_PEER_PROXY) ? "X" : "",
(mac->flags & ZEBRA_MAC_LOCAL_INACTIVE) ? "I" : "");
return flags_buf;
}
/*
* Print MAC hash entry - called for display of all MACs.
*/
void zebra_evpn_print_mac_hash(struct hash_bucket *bucket, void *ctxt)
{
struct vty *vty;
json_object *json_mac_hdr = NULL, *json_mac = NULL;
struct zebra_mac *mac;
char buf1[ETHER_ADDR_STRLEN];
char addr_buf[PREFIX_STRLEN];
struct mac_walk_ctx *wctx = ctxt;
char flags_buf[6];
vty = wctx->vty;
json_mac_hdr = wctx->json;
mac = (struct zebra_mac *)bucket->data;
prefix_mac2str(&mac->macaddr, buf1, sizeof(buf1));
if (json_mac_hdr)
json_mac = json_object_new_object();
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) {
struct interface *ifp;
vlanid_t vid;
if (wctx->flags & SHOW_REMOTE_MAC_FROM_VTEP)
return;
zebra_evpn_mac_get_access_info(mac, &ifp, &vid);
if (json_mac_hdr == NULL) {
vty_out(vty, "%-17s %-6s %-5s %-30s", buf1, "local",
zebra_evpn_print_mac_flags(mac, flags_buf,
sizeof(flags_buf)),
ifp ? ifp->name : "-");
} else {
json_object_string_add(json_mac, "type", "local");
if (ifp)
json_object_string_add(json_mac, "intf",
ifp->name);
}
if (vid) {
if (json_mac_hdr == NULL)
vty_out(vty, " %-5u", vid);
else
json_object_int_add(json_mac, "vlan", vid);
} else /* No vid? fill out the space */
if (json_mac_hdr == NULL)
vty_out(vty, " %-5s", "");
if (json_mac_hdr == NULL) {
vty_out(vty, " %u/%u", mac->loc_seq, mac->rem_seq);
vty_out(vty, "\n");
} else {
json_object_int_add(json_mac, "localSequence",
mac->loc_seq);
json_object_int_add(json_mac, "remoteSequence",
mac->rem_seq);
json_object_int_add(json_mac, "detectionCount",
mac->dad_count);
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE))
json_object_boolean_true_add(json_mac,
"isDuplicate");
else
json_object_boolean_false_add(json_mac,
"isDuplicate");
json_object_object_add(json_mac_hdr, buf1, json_mac);
}
wctx->count++;
} else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) {
if ((wctx->flags & SHOW_REMOTE_MAC_FROM_VTEP)
&& !IPV4_ADDR_SAME(&mac->fwd_info.r_vtep_ip,
&wctx->r_vtep_ip))
return;
if (json_mac_hdr == NULL) {
if ((wctx->flags & SHOW_REMOTE_MAC_FROM_VTEP)
&& (wctx->count == 0)) {
vty_out(vty, "\nVNI %u\n\n", wctx->zevpn->vni);
vty_out(vty, "%-17s %-6s %-5s%-30s %-5s %s\n",
"MAC", "Type", "Flags",
"Intf/Remote ES/VTEP", "VLAN",
"Seq #'s");
}
if (mac->es == NULL)
inet_ntop(AF_INET, &mac->fwd_info.r_vtep_ip,
addr_buf, sizeof(addr_buf));
vty_out(vty, "%-17s %-6s %-5s %-30s %-5s %u/%u\n", buf1,
"remote",
zebra_evpn_print_mac_flags(mac, flags_buf,
sizeof(flags_buf)),
mac->es ? mac->es->esi_str : addr_buf,
"", mac->loc_seq, mac->rem_seq);
} else {
json_object_string_add(json_mac, "type", "remote");
json_object_string_addf(json_mac, "remoteVtep", "%pI4",
&mac->fwd_info.r_vtep_ip);
json_object_object_add(json_mac_hdr, buf1, json_mac);
json_object_int_add(json_mac, "localSequence",
mac->loc_seq);
json_object_int_add(json_mac, "remoteSequence",
mac->rem_seq);
json_object_int_add(json_mac, "detectionCount",
mac->dad_count);
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE))
json_object_boolean_true_add(json_mac,
"isDuplicate");
else
json_object_boolean_false_add(json_mac,
"isDuplicate");
}
wctx->count++;
}
}
/*
* Print MAC hash entry in detail - called for display of all MACs.
*/
void zebra_evpn_print_mac_hash_detail(struct hash_bucket *bucket, void *ctxt)
{
struct vty *vty;
json_object *json_mac_hdr = NULL;
struct zebra_mac *mac;
struct mac_walk_ctx *wctx = ctxt;
char buf1[ETHER_ADDR_STRLEN];
vty = wctx->vty;
json_mac_hdr = wctx->json;
mac = (struct zebra_mac *)bucket->data;
if (!mac)
return;
wctx->count++;
prefix_mac2str(&mac->macaddr, buf1, sizeof(buf1));
zebra_evpn_print_mac(mac, vty, json_mac_hdr);
}
/*
* Inform BGP about local MACIP.
*/
int zebra_evpn_macip_send_msg_to_client(vni_t vni,
const struct ethaddr *macaddr,
const struct ipaddr *ip, uint8_t flags,
uint32_t seq, int state,
struct zebra_evpn_es *es, uint16_t cmd)
{
int ipa_len;
struct zserv *client = NULL;
struct stream *s = NULL;
esi_t *esi = es ? &es->esi : zero_esi;
client = zserv_find_client(ZEBRA_ROUTE_BGP, 0);