-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
zebra_dplane.c
7730 lines (6169 loc) · 186 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
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Zebra dataplane layer.
* Copyright (c) 2018 Volta Networks, Inc.
* Portions:
* Copyright (c) 2021 The MITRE Corporation.
*/
#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/zebra.h"
#include "zebra/netconf_netlink.h"
#include "zebra/zebra_router.h"
#include "zebra/zebra_dplane.h"
#include "zebra/zebra_vxlan_private.h"
#include "zebra/zebra_mpls.h"
#include "zebra/rt.h"
#include "zebra/debug.h"
#include "zebra/zebra_pbr.h"
#include "zebra/zebra_neigh.h"
#include "zebra/zebra_tc.h"
#include "printfrr.h"
/* Memory types */
DEFINE_MTYPE_STATIC(ZEBRA, DP_CTX, "Zebra DPlane Ctx");
DEFINE_MTYPE_STATIC(ZEBRA, DP_INTF, "Zebra DPlane Intf");
DEFINE_MTYPE_STATIC(ZEBRA, DP_PROV, "Zebra DPlane Provider");
DEFINE_MTYPE_STATIC(ZEBRA, DP_NETFILTER, "Zebra Netfilter Internal Object");
DEFINE_MTYPE_STATIC(ZEBRA, DP_NS, "DPlane NSes");
DEFINE_MTYPE(ZEBRA, VLAN_CHANGE_ARR, "Vlan Change Array");
#ifndef AOK
# define AOK 0
#endif
/*
* Dataplane API version. This must be updated when any incompatible changes
* are made. The minor version (at least) should be updated when new APIs
* are introduced.
*/
static uint32_t zdplane_version = MAKE_FRRVERSION(2, 0, 0);
/* Control for collection of extra interface info with route updates; a plugin
* can enable the extra info via a dplane api.
*/
static bool dplane_collect_extra_intf_info;
/* 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;
uint32_t old_id;
afi_t afi;
vrf_id_t vrf_id;
int type;
struct nexthop_group ng;
struct nh_grp nh_grp[MULTIPATH_NUM];
uint16_t nh_grp_count;
};
/*
* Optional extra info about interfaces used in route updates' nexthops.
*/
struct dplane_intf_extra {
vrf_id_t vrf_id;
uint32_t ifindex;
uint32_t flags;
uint32_t status;
struct dplane_intf_extra_list_item dlink;
};
/*
* 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;
uint32_t zd_flags;
/* Nexthop hash entry info */
struct dplane_nexthop_info nhe;
/* Nexthops */
uint32_t zd_nhg_id;
struct nexthop_group zd_ng;
/* Backup nexthops (if present) */
struct nexthop_group backup_ng;
/* "Previous" nexthops, used only in route updates without netlink */
struct nexthop_group zd_old_ng;
struct nexthop_group old_backup_ng;
/* Optional list of extra interface info */
struct dplane_intf_extra_list_head intf_extra_list;
};
/*
* Pseudowire info for the dataplane
*/
struct dplane_pw_info {
int type;
int af;
int status;
uint32_t flags;
uint32_t nhg_id;
union g_addr dest;
mpls_label_t local_label;
mpls_label_t remote_label;
/* Nexthops that are valid and installed */
struct nexthop_group fib_nhg;
/* Primary and backup nexthop sets, copied from the resolving route. */
struct nexthop_group primary_nhg;
struct nexthop_group backup_nhg;
union pw_protocol_fields fields;
};
/*
* Bridge port info for the dataplane
*/
struct dplane_br_port_info {
uint32_t sph_filter_cnt;
struct in_addr sph_filters[ES_VTEP_MAX_CNT];
/* DPLANE_BR_PORT_XXX - see zebra_dplane.h*/
uint32_t flags;
uint32_t backup_nhg_id;
};
/*
* Interface/prefix info for the dataplane
*/
struct dplane_intf_info {
enum zebra_iftype zif_type;
ifindex_t bond_ifindex;
ifindex_t link_ifindex;
int32_t mtu;
vrf_id_t vrf_id;
enum zebra_slave_iftype zif_slave_type;
ifindex_t master_ifindex;
ifindex_t bridge_ifindex;
ns_id_t link_nsid;
enum zebra_slave_iftype zslave_type;
uint8_t bypass;
enum zebra_link_type zltype;
bool startup;
uint8_t family;
struct zebra_vxlan_vni_array *vniarray;
bool no_bvinfo_avail;
bool no_afspec_avail;
struct zebra_dplane_bridge_vlan_info bvinfo;
struct zebra_dplane_bridge_vlan_info_array *bvarray;
char desc[128];
int32_t hw_addr_len;
uint8_t hw_addr[INTERFACE_HWADDR_MAX];
uint32_t table_id;
struct zebra_l2info_bridge binfo;
struct zebra_l2info_vlan vinfo;
struct zebra_l2info_vxlan vxinfo;
struct zebra_l2info_gre grinfo;
uint32_t rc_bitfield;
uint32_t txqlen;
uint32_t metric;
uint32_t flags;
bool protodown;
bool protodown_set;
bool pd_reason_val;
#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)
#define DPLANE_INTF_NOPREFIXROUTE (1 << 5)
/* 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;
vni_t vni;
struct in_addr vtep_ip;
bool is_sticky;
uint32_t nhg_id;
uint32_t update_flags;
};
/*
* Neighbor info for the dataplane
*/
struct dplane_neigh_info {
struct ipaddr ip_addr;
union {
struct ethaddr mac;
struct ipaddr ip_addr;
} link;
vni_t vni;
uint32_t flags;
uint16_t state;
uint32_t update_flags;
};
/*
* Neighbor Table
*/
struct dplane_neigh_table {
uint8_t family;
uint32_t app_probes;
uint32_t ucast_probes;
uint32_t mcast_probes;
};
/*
* Policy based routing rule info for the dataplane
*/
struct dplane_ctx_rule {
struct pbr_rule prule;
struct ethaddr smac;
struct ethaddr dmac;
int out_ifindex;
intptr_t dp_flow_ptr;
};
struct dplane_rule_info {
/*
* Originating zclient sock fd, so we can know who to send
* back to.
*/
int sock;
int unique;
int seq;
struct dplane_ctx_rule new;
struct dplane_ctx_rule old;
};
struct dplane_gre_ctx {
uint32_t link_ifindex;
unsigned int mtu;
struct zebra_l2info_gre info;
};
/*
* Network interface configuration info - aligned with netlink's NETCONF
* info. The flags values are public, in the dplane.h file...
*/
struct dplane_netconf_info {
enum dplane_netconf_status_e mpls_val;
enum dplane_netconf_status_e mcast_val;
enum dplane_netconf_status_e linkdown_val;
};
struct dplane_tc_qdisc_info {
enum tc_qdisc_kind kind;
const char *kind_str;
};
struct dplane_tc_class_info {
uint32_t handle;
enum tc_qdisc_kind kind;
const char *kind_str;
uint64_t rate;
uint64_t ceil;
};
struct dplane_tc_filter_info {
uint32_t handle;
uint16_t priority;
enum tc_filter_kind kind;
const char *kind_str;
uint32_t filter_bm;
uint16_t eth_proto;
uint8_t ip_proto;
struct prefix src_ip;
struct prefix dst_ip;
uint16_t src_port_min;
uint16_t src_port_max;
uint16_t dst_port_min;
uint16_t dst_port_max;
uint8_t dsfield;
uint8_t dsfield_mask;
uint32_t classid;
};
/*
* SRv6 encapsulation params context for the dataplane
*/
struct dplane_srv6_encap_ctx {
struct in6_addr srcaddr;
};
/*
* VLAN info for the dataplane
*/
struct dplane_vlan_info {
ifindex_t ifindex;
struct zebra_vxlan_vlan_array *vlan_array;
};
/*
* 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[IFNAMSIZ];
ifindex_t zd_ifindex;
/* Support info for different kinds of updates */
union {
struct dplane_route_info rinfo;
struct zebra_lsp lsp;
struct dplane_pw_info pw;
struct dplane_br_port_info br_port;
struct dplane_intf_info intf;
struct dplane_vlan_info vlan_info;
struct dplane_mac_info macinfo;
struct dplane_neigh_info neigh;
struct dplane_rule_info rule;
struct dplane_tc_qdisc_info tc_qdisc;
struct dplane_tc_class_info tc_class;
struct dplane_tc_filter_info tc_filter;
struct zebra_pbr_iptable iptable;
struct zebra_pbr_ipset ipset;
struct {
struct zebra_pbr_ipset_entry entry;
struct zebra_pbr_ipset_info info;
} ipset_entry;
struct dplane_neigh_table neightable;
struct dplane_gre_ctx gre;
struct dplane_netconf_info netconf;
enum zebra_dplane_startup_notifications spot;
struct dplane_srv6_encap_ctx srv6_encap;
} u;
/* Namespace info, used especially for netlink kernel communication */
struct zebra_dplane_info zd_ns_info;
/* Embedded list linkage */
struct dplane_ctx_list_item zd_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
/* List types declared now that the structs involved are defined. */
DECLARE_DLIST(dplane_ctx_list, struct zebra_dplane_ctx, zd_entries);
DECLARE_DLIST(dplane_intf_extra_list, struct dplane_intf_extra, dlink);
/* List for dplane plugins/providers */
PREDECL_DLIST(dplane_prov_list);
/*
* 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_max;
_Atomic uint32_t dp_out_counter;
_Atomic uint32_t dp_out_max;
_Atomic uint32_t dp_error_counter;
/* Queue of contexts inbound to the provider */
struct dplane_ctx_list_head dp_ctx_in_list;
/* Queue of completed contexts outbound from the provider back
* towards the dataplane module.
*/
struct dplane_ctx_list_head dp_ctx_out_list;
/* Embedded list linkage for provider objects */
struct dplane_prov_list_item dp_link;
};
/* Declare list of providers/plugins */
DECLARE_DLIST(dplane_prov_list, struct zebra_dplane_provider, dp_link);
/* Declare types for list of zns info objects */
PREDECL_DLIST(zns_info_list);
struct dplane_zns_info {
struct zebra_dplane_info info;
/* Request data from the OS */
struct event *t_request;
/* Read event */
struct event *t_read;
/* List linkage */
struct zns_info_list_item 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_list_head *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 */
struct dplane_ctx_list_head dg_update_list;
/* Ordered list of providers */
struct dplane_prov_list_head dg_providers;
/* List of info about each zns */
struct zns_info_list_head dg_zns_list;
/* 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_br_port_in;
_Atomic uint32_t dg_br_port_errors;
_Atomic uint32_t dg_intf_addrs_in;
_Atomic uint32_t dg_intf_addr_errors;
_Atomic uint32_t dg_intf_changes;
_Atomic uint32_t dg_intf_changes_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_rules_in;
_Atomic uint32_t dg_rule_errors;
_Atomic uint32_t dg_update_yields;
_Atomic uint32_t dg_iptable_in;
_Atomic uint32_t dg_iptable_errors;
_Atomic uint32_t dg_ipset_in;
_Atomic uint32_t dg_ipset_errors;
_Atomic uint32_t dg_ipset_entry_in;
_Atomic uint32_t dg_ipset_entry_errors;
_Atomic uint32_t dg_neightable_in;
_Atomic uint32_t dg_neightable_errors;
_Atomic uint32_t dg_gre_set_in;
_Atomic uint32_t dg_gre_set_errors;
_Atomic uint32_t dg_intfs_in;
_Atomic uint32_t dg_intf_errors;
_Atomic uint32_t dg_tcs_in;
_Atomic uint32_t dg_tcs_errors;
_Atomic uint32_t dg_srv6_encap_srcaddr_set_in;
_Atomic uint32_t dg_srv6_encap_srcaddr_set_errors;
/* Dataplane pthread */
struct frr_pthread *dg_pthread;
/* Event-delivery context 'master' for the dplane */
struct event_loop *dg_master;
/* Event/'thread' pointer for queued updates */
struct event *dg_t_update;
/* Event pointer for pending shutdown check loop */
struct event *dg_t_shutdown_check;
} zdplane_info;
/* Instantiate zns list type */
DECLARE_DLIST(zns_info_list, struct dplane_zns_info, link);
/*
* 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 void dplane_thread_loop(struct event *event);
static enum zebra_dplane_result lsp_update_internal(struct zebra_lsp *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_common(enum dplane_op_e op, const struct interface *ifp,
const struct interface *br_ifp, vlanid_t vid,
const struct ethaddr *mac, vni_t vni, struct in_addr vtep_ip,
bool sticky, uint32_t nhg_id, uint32_t update_flags);
static enum zebra_dplane_result
neigh_update_internal(enum dplane_op_e op, const struct interface *ifp,
const void *link, int link_family,
const struct ipaddr *ip, vni_t vni, uint32_t flags,
uint16_t state, uint32_t update_flags, int protocol);
/*
* Public APIs
*/
/* Access the dplane API version */
uint32_t zebra_dplane_get_version(void)
{
return zdplane_version;
}
/* Obtain thread_master for dataplane thread */
struct event_loop *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;
}
/*
* Clean up dependent/internal allocations inside a context object
*/
static void dplane_ctx_free_internal(struct zebra_dplane_ctx *ctx)
{
struct dplane_intf_extra *if_extra;
/*
* Some internal allocations may need to be freed, depending on
* the type of info captured in the ctx.
*/
switch (ctx->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 (ctx->u.rinfo.zd_ng.nexthop) {
/* This deals with recursive nexthops too */
nexthops_free(ctx->u.rinfo.zd_ng.nexthop);
ctx->u.rinfo.zd_ng.nexthop = NULL;
}
/* Free backup info also (if present) */
if (ctx->u.rinfo.backup_ng.nexthop) {
/* This deals with recursive nexthops too */
nexthops_free(ctx->u.rinfo.backup_ng.nexthop);
ctx->u.rinfo.backup_ng.nexthop = NULL;
}
if (ctx->u.rinfo.zd_old_ng.nexthop) {
/* This deals with recursive nexthops too */
nexthops_free(ctx->u.rinfo.zd_old_ng.nexthop);
ctx->u.rinfo.zd_old_ng.nexthop = NULL;
}
if (ctx->u.rinfo.old_backup_ng.nexthop) {
/* This deals with recursive nexthops too */
nexthops_free(ctx->u.rinfo.old_backup_ng.nexthop);
ctx->u.rinfo.old_backup_ng.nexthop = NULL;
}
/* Optional extra interface info */
while ((if_extra = dplane_intf_extra_list_pop(
&ctx->u.rinfo.intf_extra_list)))
XFREE(MTYPE_DP_INTF, if_extra);
break;
case DPLANE_OP_NH_INSTALL:
case DPLANE_OP_NH_UPDATE:
case DPLANE_OP_NH_DELETE: {
if (ctx->u.rinfo.nhe.ng.nexthop) {
/* This deals with recursive nexthops too */
nexthops_free(ctx->u.rinfo.nhe.ng.nexthop);
ctx->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:
{
struct zebra_nhlfe *nhlfe;
/* Unlink and free allocated NHLFEs */
frr_each_safe(nhlfe_list, &ctx->u.lsp.nhlfe_list, nhlfe) {
nhlfe_list_del(&ctx->u.lsp.nhlfe_list, nhlfe);
zebra_mpls_nhlfe_free(nhlfe);
}
/* Unlink and free allocated backup NHLFEs, if present */
frr_each_safe(nhlfe_list,
&(ctx->u.lsp.backup_nhlfe_list), nhlfe) {
nhlfe_list_del(&ctx->u.lsp.backup_nhlfe_list,
nhlfe);
zebra_mpls_nhlfe_free(nhlfe);
}
/* Clear pointers in lsp struct, in case we're caching
* free context structs.
*/
nhlfe_list_init(&ctx->u.lsp.nhlfe_list);
ctx->u.lsp.best_nhlfe = NULL;
nhlfe_list_init(&ctx->u.lsp.backup_nhlfe_list);
break;
}
case DPLANE_OP_PW_INSTALL:
case DPLANE_OP_PW_UNINSTALL:
/* Free allocated nexthops */
if (ctx->u.pw.fib_nhg.nexthop) {
/* This deals with recursive nexthops too */
nexthops_free(ctx->u.pw.fib_nhg.nexthop);
ctx->u.pw.fib_nhg.nexthop = NULL;
}
if (ctx->u.pw.primary_nhg.nexthop) {
nexthops_free(ctx->u.pw.primary_nhg.nexthop);
ctx->u.pw.primary_nhg.nexthop = NULL;
}
if (ctx->u.pw.backup_nhg.nexthop) {
nexthops_free(ctx->u.pw.backup_nhg.nexthop);
ctx->u.pw.backup_nhg.nexthop = NULL;
}
break;
case DPLANE_OP_ADDR_INSTALL:
case DPLANE_OP_ADDR_UNINSTALL:
case DPLANE_OP_INTF_ADDR_ADD:
case DPLANE_OP_INTF_ADDR_DEL:
/* Maybe free label string, if allocated */
if (ctx->u.intf.label != NULL &&
ctx->u.intf.label != ctx->u.intf.label_buf) {
XFREE(MTYPE_DP_CTX, ctx->u.intf.label);
ctx->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_RULE_ADD:
case DPLANE_OP_RULE_DELETE:
case DPLANE_OP_RULE_UPDATE:
case DPLANE_OP_NEIGH_DISCOVER:
case DPLANE_OP_BR_PORT_UPDATE:
case DPLANE_OP_NEIGH_IP_INSTALL:
case DPLANE_OP_NEIGH_IP_DELETE:
case DPLANE_OP_NONE:
case DPLANE_OP_IPSET_ADD:
case DPLANE_OP_IPSET_DELETE:
break;
case DPLANE_OP_INTF_INSTALL:
case DPLANE_OP_INTF_UPDATE:
if (ctx->u.intf.vniarray)
XFREE(MTYPE_TMP, ctx->u.intf.vniarray);
if (ctx->u.intf.bvarray)
XFREE(MTYPE_TMP, ctx->u.intf.bvarray);
break;
case DPLANE_OP_INTF_DELETE:
case DPLANE_OP_TC_QDISC_INSTALL:
case DPLANE_OP_TC_QDISC_UNINSTALL:
case DPLANE_OP_TC_CLASS_ADD:
case DPLANE_OP_TC_CLASS_DELETE:
case DPLANE_OP_TC_CLASS_UPDATE:
case DPLANE_OP_TC_FILTER_ADD:
case DPLANE_OP_TC_FILTER_DELETE:
case DPLANE_OP_TC_FILTER_UPDATE:
break;
case DPLANE_OP_IPSET_ENTRY_ADD:
case DPLANE_OP_IPSET_ENTRY_DELETE:
break;
case DPLANE_OP_NEIGH_TABLE_UPDATE:
break;
case DPLANE_OP_IPTABLE_ADD:
case DPLANE_OP_IPTABLE_DELETE:
if (ctx->u.iptable.interface_name_list)
list_delete(&ctx->u.iptable.interface_name_list);
break;
case DPLANE_OP_GRE_SET:
case DPLANE_OP_INTF_NETCONFIG:
case DPLANE_OP_STARTUP_STAGE:
case DPLANE_OP_SRV6_ENCAP_SRCADDR_SET:
break;
case DPLANE_OP_VLAN_INSTALL:
if (ctx->u.vlan_info.vlan_array)
XFREE(MTYPE_VLAN_CHANGE_ARR,
ctx->u.vlan_info.vlan_array);
break;
}
}
/*
* 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.
*/
dplane_ctx_free_internal(*pctx);
XFREE(MTYPE_DP_CTX, *pctx);
}
/*
* Reset an allocated context object for re-use. All internal allocations are
* freed and the context is memset.
*/
void dplane_ctx_reset(struct zebra_dplane_ctx *ctx)
{
dplane_ctx_free_internal(ctx);
memset(ctx, 0, sizeof(*ctx));
}
/*
* 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);
}
/* Init a list of contexts */
void dplane_ctx_q_init(struct dplane_ctx_list_head *q)
{
dplane_ctx_list_init(q);
}
/* Enqueue a context block */
void dplane_ctx_enqueue_tail(struct dplane_ctx_list_head *list,
const struct zebra_dplane_ctx *ctx)
{
dplane_ctx_list_add_tail(list, (struct zebra_dplane_ctx *)ctx);
}
/* Append a list of context blocks to another list */
void dplane_ctx_list_append(struct dplane_ctx_list_head *to_list,
struct dplane_ctx_list_head *from_list)
{
struct zebra_dplane_ctx *ctx;
while ((ctx = dplane_ctx_list_pop(from_list)) != NULL)
dplane_ctx_list_add_tail(to_list, ctx);
}
struct zebra_dplane_ctx *dplane_ctx_get_head(struct dplane_ctx_list_head *q)
{
struct zebra_dplane_ctx *ctx = dplane_ctx_list_first(q);
return ctx;
}
/* Dequeue a context block from the head of a list */
struct zebra_dplane_ctx *dplane_ctx_dequeue(struct dplane_ctx_list_head *q)
{
struct zebra_dplane_ctx *ctx = dplane_ctx_list_pop(q);
return ctx;
}
uint32_t dplane_ctx_queue_count(struct dplane_ctx_list_head *q)
{
return dplane_ctx_list_count(q);
}
/*
* 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;
}