forked from FRRouting/frr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzebra_dplane.c
3849 lines (3062 loc) · 88.7 KB
/
zebra_dplane.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 dataplane layer.
* Copyright (c) 2018 Volta Networks, Inc.
*
* This program 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 of the License, or
* (at your option) any later version.
*
* This program 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
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "lib/libfrr.h"
#include "lib/debug.h"
#include "lib/frratomic.h"
#include "lib/frr_pthread.h"
#include "lib/memory.h"
#include "lib/queue.h"
#include "lib/zebra.h"
#include "zebra/zebra_router.h"
#include "zebra/zebra_memory.h"
#include "zebra/zebra_router.h"
#include "zebra/zebra_dplane.h"
#include "zebra/rt.h"
#include "zebra/debug.h"
/* Memory type for context blocks */
DEFINE_MTYPE_STATIC(ZEBRA, DP_CTX, "Zebra DPlane Ctx")
DEFINE_MTYPE_STATIC(ZEBRA, DP_PROV, "Zebra DPlane Provider")
#ifndef AOK
# define AOK 0
#endif
/* Enable test dataplane provider */
/*#define DPLANE_TEST_PROVIDER 1 */
/* Default value for max queued incoming updates */
const uint32_t DPLANE_DEFAULT_MAX_QUEUED = 200;
/* Default value for new work per cycle */
const uint32_t DPLANE_DEFAULT_NEW_WORK = 100;
/* Validation check macro for context blocks */
/* #define DPLANE_DEBUG 1 */
#ifdef DPLANE_DEBUG
# define DPLANE_CTX_VALID(p) \
assert((p) != NULL)
#else
# define DPLANE_CTX_VALID(p)
#endif /* DPLANE_DEBUG */
/*
* Nexthop information captured for nexthop/nexthop group updates
*/
struct dplane_nexthop_info {
uint32_t id;
afi_t afi;
vrf_id_t vrf_id;
int type;
struct nexthop_group ng;
struct nh_grp nh_grp[MULTIPATH_NUM];
uint8_t nh_grp_count;
};
/*
* Route information captured for route updates.
*/
struct dplane_route_info {
/* Dest and (optional) source prefixes */
struct prefix zd_dest;
struct prefix zd_src;
afi_t zd_afi;
safi_t zd_safi;
int zd_type;
int zd_old_type;
route_tag_t zd_tag;
route_tag_t zd_old_tag;
uint32_t zd_metric;
uint32_t zd_old_metric;
uint16_t zd_instance;
uint16_t zd_old_instance;
uint8_t zd_distance;
uint8_t zd_old_distance;
uint32_t zd_mtu;
uint32_t zd_nexthop_mtu;
/* Nexthop hash entry info */
struct dplane_nexthop_info nhe;
/* Nexthops */
struct nexthop_group zd_ng;
/* "Previous" nexthops, used only in route updates without netlink */
struct nexthop_group zd_old_ng;
/* TODO -- use fixed array of nexthops, to avoid mallocs? */
};
/*
* Pseudowire info for the dataplane
*/
struct dplane_pw_info {
int type;
int af;
int status;
uint32_t flags;
union g_addr dest;
mpls_label_t local_label;
mpls_label_t remote_label;
/* Nexthops */
struct nexthop_group nhg;
union pw_protocol_fields fields;
};
/*
* Interface/prefix info for the dataplane
*/
struct dplane_intf_info {
uint32_t metric;
uint32_t flags;
#define DPLANE_INTF_CONNECTED (1 << 0) /* Connected peer, p2p */
#define DPLANE_INTF_SECONDARY (1 << 1)
#define DPLANE_INTF_BROADCAST (1 << 2)
#define DPLANE_INTF_HAS_DEST DPLANE_INTF_CONNECTED
#define DPLANE_INTF_HAS_LABEL (1 << 4)
/* Interface address/prefix */
struct prefix prefix;
/* Dest address, for p2p, or broadcast prefix */
struct prefix dest_prefix;
char *label;
char label_buf[32];
};
/*
* EVPN MAC address info for the dataplane.
*/
struct dplane_mac_info {
vlanid_t vid;
ifindex_t br_ifindex;
struct ethaddr mac;
struct in_addr vtep_ip;
bool is_sticky;
};
/*
* EVPN neighbor info for the dataplane
*/
struct dplane_neigh_info {
struct ipaddr ip_addr;
struct ethaddr mac;
uint32_t flags;
uint16_t state;
};
/*
* The context block used to exchange info about route updates across
* the boundary between the zebra main context (and pthread) and the
* dataplane layer (and pthread).
*/
struct zebra_dplane_ctx {
/* Operation code */
enum dplane_op_e zd_op;
/* Status on return */
enum zebra_dplane_result zd_status;
/* Dplane provider id */
uint32_t zd_provider;
/* Flags - used by providers, e.g. */
int zd_flags;
bool zd_is_update;
uint32_t zd_seq;
uint32_t zd_old_seq;
/* Some updates may be generated by notifications: allow the
* plugin to notice and ignore results from its own notifications.
*/
uint32_t zd_notif_provider;
/* TODO -- internal/sub-operation status? */
enum zebra_dplane_result zd_remote_status;
enum zebra_dplane_result zd_kernel_status;
vrf_id_t zd_vrf_id;
uint32_t zd_table_id;
char zd_ifname[INTERFACE_NAMSIZ];
ifindex_t zd_ifindex;
/* Support info for different kinds of updates */
union {
struct dplane_route_info rinfo;
zebra_lsp_t lsp;
struct dplane_pw_info pw;
struct dplane_intf_info intf;
struct dplane_mac_info macinfo;
struct dplane_neigh_info neigh;
} u;
/* Namespace info, used especially for netlink kernel communication */
struct zebra_dplane_info zd_ns_info;
/* Embedded list linkage */
TAILQ_ENTRY(zebra_dplane_ctx) zd_q_entries;
};
/* Flag that can be set by a pre-kernel provider as a signal that an update
* should bypass the kernel.
*/
#define DPLANE_CTX_FLAG_NO_KERNEL 0x01
/*
* Registration block for one dataplane provider.
*/
struct zebra_dplane_provider {
/* Name */
char dp_name[DPLANE_PROVIDER_NAMELEN + 1];
/* Priority, for ordering among providers */
uint8_t dp_priority;
/* Id value */
uint32_t dp_id;
/* Mutex */
pthread_mutex_t dp_mutex;
/* Plugin-provided extra data */
void *dp_data;
/* Flags */
int dp_flags;
int (*dp_start)(struct zebra_dplane_provider *prov);
int (*dp_fp)(struct zebra_dplane_provider *prov);
int (*dp_fini)(struct zebra_dplane_provider *prov, bool early_p);
_Atomic uint32_t dp_in_counter;
_Atomic uint32_t dp_in_queued;
_Atomic uint32_t dp_in_max;
_Atomic uint32_t dp_out_counter;
_Atomic uint32_t dp_out_queued;
_Atomic uint32_t dp_out_max;
_Atomic uint32_t dp_error_counter;
/* Queue of contexts inbound to the provider */
struct dplane_ctx_q dp_ctx_in_q;
/* Queue of completed contexts outbound from the provider back
* towards the dataplane module.
*/
struct dplane_ctx_q dp_ctx_out_q;
/* Embedded list linkage for provider objects */
TAILQ_ENTRY(zebra_dplane_provider) dp_prov_link;
};
/*
* Globals
*/
static struct zebra_dplane_globals {
/* Mutex to control access to dataplane components */
pthread_mutex_t dg_mutex;
/* Results callback registered by zebra 'core' */
int (*dg_results_cb)(struct dplane_ctx_q *ctxlist);
/* Sentinel for beginning of shutdown */
volatile bool dg_is_shutdown;
/* Sentinel for end of shutdown */
volatile bool dg_run;
/* Update context queue inbound to the dataplane */
TAILQ_HEAD(zdg_ctx_q, zebra_dplane_ctx) dg_update_ctx_q;
/* Ordered list of providers */
TAILQ_HEAD(zdg_prov_q, zebra_dplane_provider) dg_providers_q;
/* Counter used to assign internal ids to providers */
uint32_t dg_provider_id;
/* Limit number of pending, unprocessed updates */
_Atomic uint32_t dg_max_queued_updates;
/* Control whether system route notifications should be produced. */
bool dg_sys_route_notifs;
/* Limit number of new updates dequeued at once, to pace an
* incoming burst.
*/
uint32_t dg_updates_per_cycle;
_Atomic uint32_t dg_routes_in;
_Atomic uint32_t dg_routes_queued;
_Atomic uint32_t dg_routes_queued_max;
_Atomic uint32_t dg_route_errors;
_Atomic uint32_t dg_other_errors;
_Atomic uint32_t dg_nexthops_in;
_Atomic uint32_t dg_nexthop_errors;
_Atomic uint32_t dg_lsps_in;
_Atomic uint32_t dg_lsp_errors;
_Atomic uint32_t dg_pws_in;
_Atomic uint32_t dg_pw_errors;
_Atomic uint32_t dg_intf_addrs_in;
_Atomic uint32_t dg_intf_addr_errors;
_Atomic uint32_t dg_macs_in;
_Atomic uint32_t dg_mac_errors;
_Atomic uint32_t dg_neighs_in;
_Atomic uint32_t dg_neigh_errors;
_Atomic uint32_t dg_update_yields;
/* Dataplane pthread */
struct frr_pthread *dg_pthread;
/* Event-delivery context 'master' for the dplane */
struct thread_master *dg_master;
/* Event/'thread' pointer for queued updates */
struct thread *dg_t_update;
/* Event pointer for pending shutdown check loop */
struct thread *dg_t_shutdown_check;
} zdplane_info;
/*
* Lock and unlock for interactions with the zebra 'core' pthread
*/
#define DPLANE_LOCK() pthread_mutex_lock(&zdplane_info.dg_mutex)
#define DPLANE_UNLOCK() pthread_mutex_unlock(&zdplane_info.dg_mutex)
/*
* Lock and unlock for individual providers
*/
#define DPLANE_PROV_LOCK(p) pthread_mutex_lock(&((p)->dp_mutex))
#define DPLANE_PROV_UNLOCK(p) pthread_mutex_unlock(&((p)->dp_mutex))
/* Prototypes */
static int dplane_thread_loop(struct thread *event);
static void dplane_info_from_zns(struct zebra_dplane_info *ns_info,
struct zebra_ns *zns);
static enum zebra_dplane_result lsp_update_internal(zebra_lsp_t *lsp,
enum dplane_op_e op);
static enum zebra_dplane_result pw_update_internal(struct zebra_pw *pw,
enum dplane_op_e op);
static enum zebra_dplane_result intf_addr_update_internal(
const struct interface *ifp, const struct connected *ifc,
enum dplane_op_e op);
static enum zebra_dplane_result mac_update_internal(
enum dplane_op_e op, const struct interface *ifp,
const struct interface *br_ifp,
vlanid_t vid, const struct ethaddr *mac,
struct in_addr vtep_ip, bool sticky);
static enum zebra_dplane_result neigh_update_internal(
enum dplane_op_e op,
const struct interface *ifp,
const struct ethaddr *mac,
const struct ipaddr *ip,
uint32_t flags, uint16_t state);
/*
* Public APIs
*/
/* Obtain thread_master for dataplane thread */
struct thread_master *dplane_get_thread_master(void)
{
return zdplane_info.dg_master;
}
/*
* Allocate a dataplane update context
*/
struct zebra_dplane_ctx *dplane_ctx_alloc(void)
{
struct zebra_dplane_ctx *p;
/* TODO -- just alloc'ing memory, but would like to maintain
* a pool
*/
p = XCALLOC(MTYPE_DP_CTX, sizeof(struct zebra_dplane_ctx));
return p;
}
/* Enable system route notifications */
void dplane_enable_sys_route_notifs(void)
{
zdplane_info.dg_sys_route_notifs = true;
}
/*
* Free a dataplane results context.
*/
static void dplane_ctx_free(struct zebra_dplane_ctx **pctx)
{
if (pctx == NULL)
return;
DPLANE_CTX_VALID(*pctx);
/* TODO -- just freeing memory, but would like to maintain
* a pool
*/
/* Some internal allocations may need to be freed, depending on
* the type of info captured in the ctx.
*/
switch ((*pctx)->zd_op) {
case DPLANE_OP_ROUTE_INSTALL:
case DPLANE_OP_ROUTE_UPDATE:
case DPLANE_OP_ROUTE_DELETE:
case DPLANE_OP_SYS_ROUTE_ADD:
case DPLANE_OP_SYS_ROUTE_DELETE:
case DPLANE_OP_ROUTE_NOTIFY:
/* Free allocated nexthops */
if ((*pctx)->u.rinfo.zd_ng.nexthop) {
/* This deals with recursive nexthops too */
nexthops_free((*pctx)->u.rinfo.zd_ng.nexthop);
(*pctx)->u.rinfo.zd_ng.nexthop = NULL;
}
if ((*pctx)->u.rinfo.zd_old_ng.nexthop) {
/* This deals with recursive nexthops too */
nexthops_free((*pctx)->u.rinfo.zd_old_ng.nexthop);
(*pctx)->u.rinfo.zd_old_ng.nexthop = NULL;
}
break;
case DPLANE_OP_NH_INSTALL:
case DPLANE_OP_NH_UPDATE:
case DPLANE_OP_NH_DELETE: {
if ((*pctx)->u.rinfo.nhe.ng.nexthop) {
/* This deals with recursive nexthops too */
nexthops_free((*pctx)->u.rinfo.nhe.ng.nexthop);
(*pctx)->u.rinfo.nhe.ng.nexthop = NULL;
}
break;
}
case DPLANE_OP_LSP_INSTALL:
case DPLANE_OP_LSP_UPDATE:
case DPLANE_OP_LSP_DELETE:
case DPLANE_OP_LSP_NOTIFY:
{
zebra_nhlfe_t *nhlfe, *next;
/* Free allocated NHLFEs */
for (nhlfe = (*pctx)->u.lsp.nhlfe_list; nhlfe; nhlfe = next) {
next = nhlfe->next;
zebra_mpls_nhlfe_del(nhlfe);
}
/* Clear pointers in lsp struct, in case we're cacheing
* free context structs.
*/
(*pctx)->u.lsp.nhlfe_list = NULL;
(*pctx)->u.lsp.best_nhlfe = NULL;
break;
}
case DPLANE_OP_PW_INSTALL:
case DPLANE_OP_PW_UNINSTALL:
/* Free allocated nexthops */
if ((*pctx)->u.pw.nhg.nexthop) {
/* This deals with recursive nexthops too */
nexthops_free((*pctx)->u.pw.nhg.nexthop);
(*pctx)->u.pw.nhg.nexthop = NULL;
}
break;
case DPLANE_OP_ADDR_INSTALL:
case DPLANE_OP_ADDR_UNINSTALL:
/* Maybe free label string, if allocated */
if ((*pctx)->u.intf.label != NULL &&
(*pctx)->u.intf.label != (*pctx)->u.intf.label_buf) {
free((*pctx)->u.intf.label);
(*pctx)->u.intf.label = NULL;
}
break;
case DPLANE_OP_MAC_INSTALL:
case DPLANE_OP_MAC_DELETE:
case DPLANE_OP_NEIGH_INSTALL:
case DPLANE_OP_NEIGH_UPDATE:
case DPLANE_OP_NEIGH_DELETE:
case DPLANE_OP_VTEP_ADD:
case DPLANE_OP_VTEP_DELETE:
case DPLANE_OP_NONE:
break;
}
XFREE(MTYPE_DP_CTX, *pctx);
*pctx = NULL;
}
/*
* Return a context block to the dplane module after processing
*/
void dplane_ctx_fini(struct zebra_dplane_ctx **pctx)
{
/* TODO -- maintain pool; for now, just free */
dplane_ctx_free(pctx);
}
/* Enqueue a context block */
void dplane_ctx_enqueue_tail(struct dplane_ctx_q *q,
const struct zebra_dplane_ctx *ctx)
{
TAILQ_INSERT_TAIL(q, (struct zebra_dplane_ctx *)ctx, zd_q_entries);
}
/* Append a list of context blocks to another list */
void dplane_ctx_list_append(struct dplane_ctx_q *to_list,
struct dplane_ctx_q *from_list)
{
if (TAILQ_FIRST(from_list)) {
TAILQ_CONCAT(to_list, from_list, zd_q_entries);
/* And clear 'from' list */
TAILQ_INIT(from_list);
}
}
/* Dequeue a context block from the head of a list */
struct zebra_dplane_ctx *dplane_ctx_dequeue(struct dplane_ctx_q *q)
{
struct zebra_dplane_ctx *ctx = TAILQ_FIRST(q);
if (ctx)
TAILQ_REMOVE(q, ctx, zd_q_entries);
return ctx;
}
/*
* Accessors for information from the context object
*/
enum zebra_dplane_result dplane_ctx_get_status(
const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->zd_status;
}
void dplane_ctx_set_status(struct zebra_dplane_ctx *ctx,
enum zebra_dplane_result status)
{
DPLANE_CTX_VALID(ctx);
ctx->zd_status = status;
}
/* Retrieve last/current provider id */
uint32_t dplane_ctx_get_provider(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->zd_provider;
}
/* Providers run before the kernel can control whether a kernel
* update should be done.
*/
void dplane_ctx_set_skip_kernel(struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
SET_FLAG(ctx->zd_flags, DPLANE_CTX_FLAG_NO_KERNEL);
}
bool dplane_ctx_is_skip_kernel(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return CHECK_FLAG(ctx->zd_flags, DPLANE_CTX_FLAG_NO_KERNEL);
}
void dplane_ctx_set_op(struct zebra_dplane_ctx *ctx, enum dplane_op_e op)
{
DPLANE_CTX_VALID(ctx);
ctx->zd_op = op;
}
enum dplane_op_e dplane_ctx_get_op(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->zd_op;
}
const char *dplane_op2str(enum dplane_op_e op)
{
const char *ret = "UNKNOWN";
switch (op) {
case DPLANE_OP_NONE:
ret = "NONE";
break;
/* Route update */
case DPLANE_OP_ROUTE_INSTALL:
ret = "ROUTE_INSTALL";
break;
case DPLANE_OP_ROUTE_UPDATE:
ret = "ROUTE_UPDATE";
break;
case DPLANE_OP_ROUTE_DELETE:
ret = "ROUTE_DELETE";
break;
case DPLANE_OP_ROUTE_NOTIFY:
ret = "ROUTE_NOTIFY";
break;
/* Nexthop update */
case DPLANE_OP_NH_INSTALL:
ret = "NH_INSTALL";
break;
case DPLANE_OP_NH_UPDATE:
ret = "NH_UPDATE";
break;
case DPLANE_OP_NH_DELETE:
ret = "NH_DELETE";
break;
case DPLANE_OP_LSP_INSTALL:
ret = "LSP_INSTALL";
break;
case DPLANE_OP_LSP_UPDATE:
ret = "LSP_UPDATE";
break;
case DPLANE_OP_LSP_DELETE:
ret = "LSP_DELETE";
break;
case DPLANE_OP_LSP_NOTIFY:
ret = "LSP_NOTIFY";
break;
case DPLANE_OP_PW_INSTALL:
ret = "PW_INSTALL";
break;
case DPLANE_OP_PW_UNINSTALL:
ret = "PW_UNINSTALL";
break;
case DPLANE_OP_SYS_ROUTE_ADD:
ret = "SYS_ROUTE_ADD";
break;
case DPLANE_OP_SYS_ROUTE_DELETE:
ret = "SYS_ROUTE_DEL";
break;
case DPLANE_OP_ADDR_INSTALL:
ret = "ADDR_INSTALL";
break;
case DPLANE_OP_ADDR_UNINSTALL:
ret = "ADDR_UNINSTALL";
break;
case DPLANE_OP_MAC_INSTALL:
ret = "MAC_INSTALL";
break;
case DPLANE_OP_MAC_DELETE:
ret = "MAC_DELETE";
break;
case DPLANE_OP_NEIGH_INSTALL:
ret = "NEIGH_INSTALL";
break;
case DPLANE_OP_NEIGH_UPDATE:
ret = "NEIGH_UPDATE";
break;
case DPLANE_OP_NEIGH_DELETE:
ret = "NEIGH_DELETE";
break;
case DPLANE_OP_VTEP_ADD:
ret = "VTEP_ADD";
break;
case DPLANE_OP_VTEP_DELETE:
ret = "VTEP_DELETE";
break;
}
return ret;
}
const char *dplane_res2str(enum zebra_dplane_result res)
{
const char *ret = "<Unknown>";
switch (res) {
case ZEBRA_DPLANE_REQUEST_FAILURE:
ret = "FAILURE";
break;
case ZEBRA_DPLANE_REQUEST_QUEUED:
ret = "QUEUED";
break;
case ZEBRA_DPLANE_REQUEST_SUCCESS:
ret = "SUCCESS";
break;
}
return ret;
}
void dplane_ctx_set_dest(struct zebra_dplane_ctx *ctx,
const struct prefix *dest)
{
DPLANE_CTX_VALID(ctx);
prefix_copy(&(ctx->u.rinfo.zd_dest), dest);
}
const struct prefix *dplane_ctx_get_dest(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return &(ctx->u.rinfo.zd_dest);
}
void dplane_ctx_set_src(struct zebra_dplane_ctx *ctx, const struct prefix *src)
{
DPLANE_CTX_VALID(ctx);
if (src)
prefix_copy(&(ctx->u.rinfo.zd_src), src);
else
memset(&(ctx->u.rinfo.zd_src), 0, sizeof(struct prefix));
}
/* Source prefix is a little special - return NULL for "no src prefix" */
const struct prefix *dplane_ctx_get_src(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
if (ctx->u.rinfo.zd_src.prefixlen == 0 &&
IN6_IS_ADDR_UNSPECIFIED(&(ctx->u.rinfo.zd_src.u.prefix6))) {
return NULL;
} else {
return &(ctx->u.rinfo.zd_src);
}
}
bool dplane_ctx_is_update(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->zd_is_update;
}
uint32_t dplane_ctx_get_seq(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->zd_seq;
}
uint32_t dplane_ctx_get_old_seq(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->zd_old_seq;
}
void dplane_ctx_set_vrf(struct zebra_dplane_ctx *ctx, vrf_id_t vrf)
{
DPLANE_CTX_VALID(ctx);
ctx->zd_vrf_id = vrf;
}
vrf_id_t dplane_ctx_get_vrf(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->zd_vrf_id;
}
bool dplane_ctx_is_from_notif(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return (ctx->zd_notif_provider != 0);
}
uint32_t dplane_ctx_get_notif_provider(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->zd_notif_provider;
}
void dplane_ctx_set_notif_provider(struct zebra_dplane_ctx *ctx,
uint32_t id)
{
DPLANE_CTX_VALID(ctx);
ctx->zd_notif_provider = id;
}
const char *dplane_ctx_get_ifname(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->zd_ifname;
}
ifindex_t dplane_ctx_get_ifindex(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->zd_ifindex;
}
void dplane_ctx_set_type(struct zebra_dplane_ctx *ctx, int type)
{
DPLANE_CTX_VALID(ctx);
ctx->u.rinfo.zd_type = type;
}
int dplane_ctx_get_type(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->u.rinfo.zd_type;
}
int dplane_ctx_get_old_type(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->u.rinfo.zd_old_type;
}
void dplane_ctx_set_afi(struct zebra_dplane_ctx *ctx, afi_t afi)
{
DPLANE_CTX_VALID(ctx);
ctx->u.rinfo.zd_afi = afi;
}
afi_t dplane_ctx_get_afi(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->u.rinfo.zd_afi;
}
void dplane_ctx_set_safi(struct zebra_dplane_ctx *ctx, safi_t safi)
{
DPLANE_CTX_VALID(ctx);
ctx->u.rinfo.zd_safi = safi;
}
safi_t dplane_ctx_get_safi(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->u.rinfo.zd_safi;
}
void dplane_ctx_set_table(struct zebra_dplane_ctx *ctx, uint32_t table)
{
DPLANE_CTX_VALID(ctx);
ctx->zd_table_id = table;
}
uint32_t dplane_ctx_get_table(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->zd_table_id;
}
route_tag_t dplane_ctx_get_tag(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->u.rinfo.zd_tag;
}
void dplane_ctx_set_tag(struct zebra_dplane_ctx *ctx, route_tag_t tag)
{
DPLANE_CTX_VALID(ctx);
ctx->u.rinfo.zd_tag = tag;
}
route_tag_t dplane_ctx_get_old_tag(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->u.rinfo.zd_old_tag;
}
uint16_t dplane_ctx_get_instance(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->u.rinfo.zd_instance;
}
void dplane_ctx_set_instance(struct zebra_dplane_ctx *ctx, uint16_t instance)
{
DPLANE_CTX_VALID(ctx);
ctx->u.rinfo.zd_instance = instance;
}
uint16_t dplane_ctx_get_old_instance(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->u.rinfo.zd_old_instance;
}
uint32_t dplane_ctx_get_metric(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->u.rinfo.zd_metric;
}
uint32_t dplane_ctx_get_old_metric(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->u.rinfo.zd_old_metric;
}
uint32_t dplane_ctx_get_mtu(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);
return ctx->u.rinfo.zd_mtu;
}
uint32_t dplane_ctx_get_nh_mtu(const struct zebra_dplane_ctx *ctx)
{
DPLANE_CTX_VALID(ctx);