summaryrefslogtreecommitdiffstats
path: root/bgpd/rfapi/rfapi.h
blob: b2079fb13e26495dc83f6c79e80e5a573a35b28b (plain)
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
/*
 *
 * Copyright 2009-2016, LabN Consulting, L.L.C.
 *
 *
 * 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
 */

#ifndef _QUAGGA_BGP_RFAPI_H
#define _QUAGGA_BGP_RFAPI_H

#ifdef ENABLE_BGP_VNC

#include <stdint.h>
#include <netinet/in.h>
#include "lib/zebra.h"
#include "lib/vty.h"
#include "lib/prefix.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_encap_types.h"

/* probably ought to have a field-specific define in config.h */
#ifndef s6_addr32 /* for solaris/bsd */
#   define	s6_addr32	__u6_addr.__u6_addr32
#endif

#define RFAPI_V4_ADDR 0x04
#define RFAPI_V6_ADDR 0x06
#define RFAPI_SHOW_STR "VNC information\n"

struct rfapi_ip_addr {
	uint8_t addr_family; /* AF_INET | AF_INET6 */
	union {
		struct in_addr v4;  /* in network order */
		struct in6_addr v6; /* in network order */
	} addr;
};

struct rfapi_ip_prefix {
	uint8_t length;
	uint8_t cost; /* bgp local pref = 255 - cost */
	struct rfapi_ip_addr prefix;
};

struct rfapi_nexthop {
	struct prefix addr;
	uint8_t cost;
};

struct rfapi_next_hop_entry {
	struct rfapi_next_hop_entry *next;
	struct rfapi_ip_prefix prefix;
	uint32_t lifetime;
	struct rfapi_ip_addr un_address;
	struct rfapi_ip_addr vn_address;
	struct rfapi_vn_option *vn_options;
	struct rfapi_un_option *un_options;
};

#define RFAPI_REMOVE_RESPONSE_LIFETIME  0
#define RFAPI_INFINITE_LIFETIME         0xFFFFFFFF

struct rfapi_l2address_option {
	struct ethaddr macaddr; /* use 0 to assign label to IP prefix */
	uint32_t label;		/* 20bit label in low bits, no TC, S, or TTL  */
	uint32_t logical_net_id; /* ~= EVPN Ethernet Segment Id,
			    must not be zero for mac regis. */
	uint8_t local_nve_id;
	uint16_t tag_id; /* EVPN Ethernet Tag ID, 0 = none */
};

typedef enum {
	RFAPI_UN_OPTION_TYPE_PROVISIONAL, /* internal use only */
	RFAPI_UN_OPTION_TYPE_TUNNELTYPE,
} rfapi_un_option_type;

struct rfapi_tunneltype_option {
	bgp_encap_types type;
	union {
		struct bgp_encap_type_reserved reserved;
		struct bgp_encap_type_l2tpv3_over_ip l2tpv3_ip;
		struct bgp_encap_type_gre gre;
		struct bgp_encap_type_transmit_tunnel_endpoint
			transmit_tunnel_endpoint;
		struct bgp_encap_type_ipsec_in_tunnel_mode ipsec_tunnel;
		struct bgp_encap_type_ip_in_ip_tunnel_with_ipsec_transport_mode
			ip_ipsec;
		struct bgp_encap_type_mpls_in_ip_tunnel_with_ipsec_transport_mode
			mpls_ipsec;
		struct bgp_encap_type_ip_in_ip ip_ip;
		struct bgp_encap_type_vxlan vxlan;
		struct bgp_encap_type_nvgre nvgre;
		struct bgp_encap_type_mpls mpls;
		struct bgp_encap_type_mpls_in_gre mpls_gre;
		struct bgp_encap_type_vxlan_gpe vxlan_gpe;
		struct bgp_encap_type_mpls_in_udp mpls_udp;
		struct bgp_encap_type_pbb pbb;
	} bgpinfo;
};

struct rfapi_un_option {
	struct rfapi_un_option *next;
	rfapi_un_option_type type;
	union {
		struct rfapi_tunneltype_option tunnel;
	} v;
};

typedef enum {
	RFAPI_VN_OPTION_TYPE_L2ADDR =
		3, /* Layer 2 address, 3 for legacy compatibility */
	RFAPI_VN_OPTION_TYPE_LOCAL_NEXTHOP, /* for static routes */
	RFAPI_VN_OPTION_TYPE_INTERNAL_RD,   /* internal use only */
} rfapi_vn_option_type;

struct rfapi_vn_option {
	struct rfapi_vn_option *next;

	rfapi_vn_option_type type;

	union {
		struct rfapi_l2address_option l2addr;

		/*
		 * If this option is present, the next hop is local to the
		 * client NVE (i.e., not via a tunnel).
		 */
		struct rfapi_nexthop local_nexthop;

		/*
		 * For rfapi internal use only
		 */
		struct prefix_rd internal_rd;
	} v;
};

struct rfapi_l2address_option_match {
	struct rfapi_l2address_option o;
	uint32_t flags;

#define RFAPI_L2O_MACADDR		0x00000001
#define RFAPI_L2O_LABEL			0x00000002
#define RFAPI_L2O_LNI			0x00000004
#define RFAPI_L2O_LHI			0x00000008
};

#define VNC_CONFIG_STR "VNC/RFP related configuration\n"

typedef void *rfapi_handle;

/***********************************************************************
 *			RFP Callbacks
 ***********************************************************************/
/*------------------------------------------
 * rfapi_response_cb_t (callback typedef)
 *
 * Callbacks of this type are used to provide asynchronous
 * route updates from RFAPI to the RFP client.
 *
 * response_cb
 *	called to notify the rfp client that a next hop list
 *	that has previously been provided in response to an
 *	rfapi_query call has been updated. Deleted routes are indicated
 *	with lifetime==RFAPI_REMOVE_RESPONSE_LIFETIME.
 *
 *	By default, the routes an NVE receives via this callback include
 *	its own routes (that it has registered). However, these may be
 *	filtered out if the global BGP_VNC_CONFIG_FILTER_SELF_FROM_RSP
 *	flag is set.
 *
 * local_cb
 *	called to notify the rfp client that a local route
 *	has been added or deleted. Deleted routes are indicated
 *	with lifetime==RFAPI_REMOVE_RESPONSE_LIFETIME.
 *
 * input:
 *	next_hops	a list of possible next hops.
 *			This is a linked list allocated within the
 *			rfapi. The response_cb callback function is responsible
 *			for freeing this memory via rfapi_free_next_hop_list()
 *			in order to avoid memory leaks.
 *
 *	userdata	value (cookie) originally specified in call to
 *			rfapi_open()
 *
 *------------------------------------------*/
typedef void(rfapi_response_cb_t)(struct rfapi_next_hop_entry *next_hops,
				  void *userdata);

/*------------------------------------------
 * rfapi_nve_close_cb_t (callback typedef)
 *
 * Callbacks of this type are used to provide asynchronous
 * notification that an rfapi_handle was invalidated
 *
 * input:
 *	pHandle		Firmerly valid rfapi_handle returned to
 *			client via rfapi_open().
 *
 *	reason		EIDRM	handle administratively closed (clear nve ...)
 *			ESTALE	handle invalidated by configuration change
 *
 *------------------------------------------*/
typedef void(rfapi_nve_close_cb_t)(rfapi_handle pHandle, int reason);

/*------------------------------------------
 * rfp_cfg_write_cb_t (callback typedef)
 *
 * This callback is used to generate output for any config parameters
 * that may supported by RFP  via RFP defined vty commands at the bgp
 * level.  See loglevel as an example.
 *
 * input:
 *    vty           -- quagga vty context
 *    rfp_start_val -- value returned by rfp_start
 *
 * output:
 *    to vty, rfp related configuration
 *
 * return value:
 *    lines written
--------------------------------------------*/
typedef int(rfp_cfg_write_cb_t)(struct vty *vty, void *rfp_start_val);

/*------------------------------------------
 * rfp_cfg_group_write_cb_t (callback typedef)
 *
 * This callback is used to generate output for any config parameters
 * that may supported by RFP via RFP defined vty commands at the
 * L2 or NVE level.  See loglevel as an example.
 *
 * input:
 *    vty              quagga vty context
 *    rfp_start_val    value returned by rfp_start
 *    type             group type
 *    name             group name
 *    rfp_cfg_group    Pointer to configuration structure
 *
 * output:
 *    to vty, rfp related configuration
 *
 * return value:
 *    lines written
--------------------------------------------*/
typedef enum {
	RFAPI_RFP_CFG_GROUP_DEFAULT,
	RFAPI_RFP_CFG_GROUP_NVE,
	RFAPI_RFP_CFG_GROUP_L2
} rfapi_rfp_cfg_group_type;

typedef int(rfp_cfg_group_write_cb_t)(struct vty *vty, void *rfp_start_val,
				      rfapi_rfp_cfg_group_type type,
				      const char *name, void *rfp_cfg_group);

/***********************************************************************
 * Configuration related defines and structures
 ***********************************************************************/

struct rfapi_rfp_cb_methods {
	rfp_cfg_write_cb_t *cfg_cb;		/* show top level config */
	rfp_cfg_group_write_cb_t *cfg_group_cb; /* show group level config */
	rfapi_response_cb_t *response_cb;       /* unsolicited responses */
	rfapi_response_cb_t *local_cb;		/* local route add/delete */
	rfapi_nve_close_cb_t *close_cb;		/* handle closed */
};

/*
 * If a route with infinite lifetime is withdrawn, this is
 * how long (in seconds) to wait before expiring it (because
 * RFAPI_LIFETIME_MULTIPLIER_PCT * infinity is too long to wait)
 */
#define RFAPI_LIFETIME_INFINITE_WITHDRAW_DELAY (60*120)

/*
 * the factor that should be applied to a prefix's <lifetime> value
 * before using it to expire a withdrawn prefix, expressed as a percent.
 * Thus, a value of 100 means to use the exact value of <lifetime>,
 * a value of 200 means to use twice the value of <lifetime>, etc.
 */
#define RFAPI_RFP_CFG_DEFAULT_HOLDDOWN_FACTOR	150

/*
 * This is used by rfapi to determine if RFP is using/supports
 * a partial (i.e., cache) or full table download approach for
 * mapping information.  When  full table download approach is
 * used all information is passed to RFP after an initial
 * rfapi_query.  When partial table download is used, only
 * information matching a query is passed.
 */
typedef enum {
	RFAPI_RFP_DOWNLOAD_PARTIAL = 0,
	RFAPI_RFP_DOWNLOAD_FULL
} rfapi_rfp_download_type;

#define RFAPI_RFP_CFG_DEFAULT_FTD_ADVERTISEMENT_INTERVAL 1

struct rfapi_rfp_cfg {
	/* partial or full table download */
	rfapi_rfp_download_type download_type; /* default=partial */
	/*
	 * When full-table-download is enabled, this is the minimum
	 * number of seconds between times a non-queried prefix will
	 * be updated to a particular NVE.
	 * default: RFAPI_RFP_CFG_DEFAULT_FTD_ADVERTISEMENT_INTERVAL
	 */
	uint32_t ftd_advertisement_interval;
	/*
	 * percentage of registration lifetime to continue to use information
	 * post soft-state refresh timeout
	 default: RFAPI_RFP_CFG_DEFAULT_HOLDDOWN_FACTOR
	 */
	uint32_t holddown_factor;
	/* Control generation of updated RFP responses */
	uint8_t use_updated_response; /* default=0/no */
	/* when use_updated_response, also generate remove responses */
	uint8_t use_removes; /* default=0/no */
};

/***********************************************************************
 * Process related functions -- MUST be provided by the RFAPI user <<===
 ***********************************************************************/

/*------------------------------------------
 * rfp_start
 *
 * This function will start the RFP code
 *
 * input:
 *    master    quagga thread_master to tie into bgpd threads
 *
 * output:
 *    cfgp      Pointer to rfapi_rfp_cfg (null = use defaults),
 *              copied by caller, updated via rfp_set_configuration
 *    cbmp      Pointer to rfapi_rfp_cb_methods, may be null
 *              copied by caller, updated via rfapi_rfp_set_cb_methods
 * return value:
 *    rfp_start_val rfp returned value passed on rfp_stop and other rfapi calls
--------------------------------------------*/
extern void *rfp_start(struct thread_master *master,
		       struct rfapi_rfp_cfg **cfgp,
		       struct rfapi_rfp_cb_methods **cbmp);

/*------------------------------------------
 * rfp_stop
 *
 * This function is called on shutdown to trigger RFP cleanup
 *
 * input:
 *    rfp_start_val
 *
 * output:
 *    none
 *
 * return value:
--------------------------------------------*/
extern void rfp_stop(void *rfp_start_val);

/***********************************************************************
 *		 RFP processing behavior configuration
 ***********************************************************************/

/*------------------------------------------
 * rfapi_rfp_set_configuration
 *
 * This is used to change rfapi's processing behavior based on
 * RFP requirements.
 *
 * input:
 *    rfp_start_val     value returned by rfp_start
 *    rfapi_rfp_cfg     Pointer to configuration structure
 *
 * output:
 *    none
 *
 * return value:
 *	0		Success
 *	ENXIO		Unabled to locate configured BGP/VNC
--------------------------------------------*/
extern int rfapi_rfp_set_configuration(void *rfp_start_val,
				       struct rfapi_rfp_cfg *rfp_cfg);

/*------------------------------------------
 * rfapi_rfp_set_cb_methods
 *
 * Change registered callback functions for asynchronous notifications
 * from RFAPI to the RFP client.
 *
 * input:
 *    rfp_start_val     value by rfp_start
 *    methods		Pointer to struct rfapi_rfp_cb_methods containing
 *			pointers to callback methods as described above
 *
 * return value:
 *	0		Success
 *	ENXIO		BGP or VNC not configured
 *------------------------------------------*/
extern int rfapi_rfp_set_cb_methods(void *rfp_start_val,
				    struct rfapi_rfp_cb_methods *methods);

/***********************************************************************
 *		 RFP group specific configuration
 ***********************************************************************/

/*------------------------------------------
 * rfapi_rfp_init_group_config_ptr_vty
 *
 * This is used to init or return a previously init'ed group specific
 * configuration pointer. Group is identified by vty context.
 * NOTE: size is ignored when a previously init'ed value is returned.
 * RFAPI frees rfp_cfg_group when group is deleted during reconfig,
 * bgp restart or shutdown.
 *
 * input:
 *    rfp_start_val     value returned by rfp_start
 *    type              group type
 *    vty               quagga vty context
 *    size              number of bytes to allocation
 *
 * output:
 *    none
 *
 * return value:
 *    rfp_cfg_group     NULL or Pointer to configuration structure
--------------------------------------------*/
extern void *rfapi_rfp_init_group_config_ptr_vty(void *rfp_start_val,
						 rfapi_rfp_cfg_group_type type,
						 struct vty *vty,
						 uint32_t size);

/*------------------------------------------
 * rfapi_rfp_get_group_config_ptr_vty
 *
 * This is used to get group specific configuration pointer.
 * Group is identified by type and vty context.
 * RFAPI frees rfp_cfg_group when group is deleted during reconfig,
 * bgp restart or shutdown.
 *
 * input:
 *    rfp_start_val     value returned by rfp_start
 *    type              group type
 *    vty               quagga vty context
 *
 * output:
 *    none
 *
 * return value:
 *    rfp_cfg_group     Pointer to configuration structure
--------------------------------------------*/
extern void *rfapi_rfp_get_group_config_ptr_vty(void *rfp_start_val,
						rfapi_rfp_cfg_group_type type,
						struct vty *vty);

/*------------------------------------------
 * rfp_group_config_search_cb_t (callback typedef)
 *
 * This callback is used to called from within a
 * rfapi_rfp_get_group_config_ptr to check if the rfp_cfg_group
 * matches the search criteria
 *
 * input:
 *    criteria          RFAPI caller provided serach criteria
 *    rfp_cfg_group     Pointer to configuration structure | NULL
 *
 * output:
 *
 * return value:
 *      0               Match/Success
 *	ENOENT		No matching
--------------------------------------------*/
typedef int(rfp_group_config_search_cb_t)(void *criteria, void *rfp_cfg_group);

/*------------------------------------------
 * rfapi_rfp_get_group_config_ptr_name
 *
 * This is used to get group specific configuration pointer.
 * Group is identified by type and name context.
 * RFAPI frees rfp_cfg_group when group is deleted during reconfig,
 * bgp restart or shutdown.
 *
 * input:
 *    rfp_start_val     value returned by rfp_start
 *    type              group type
 *    name              group name
 *    criteria          RFAPI caller provided serach criteria
 *    search_cb         optional rfp_group_config_search_cb_t
 *
 * output:
 *    none
 *
 * return value:
 *    rfp_cfg_group     Pointer to configuration structure
--------------------------------------------*/
extern void *rfapi_rfp_get_group_config_ptr_name(
	void *rfp_start_val, rfapi_rfp_cfg_group_type type, const char *name,
	void *criteria, rfp_group_config_search_cb_t *search_cb);

/*------------------------------------------
 * rfapi_rfp_get_l2_group_config_ptr_lni
 *
 * This is used to get group specific configuration pointer.
 * Group is identified by type and logical network identifier.
 * RFAPI frees rfp_cfg_group when group is deleted during reconfig,
 * bgp restart or shutdown.
 *
 * input:
 *    rfp_start_val     value returned by rfp_start
 *    logical_net_id    group logical network identifier
 *    criteria          RFAPI caller provided serach criteria
 *    search_cb         optional rfp_group_config_search_cb_t
 *
 * output:
 *    none
 *
 * return value:
 *    rfp_cfg_group     Pointer to configuration structure
--------------------------------------------*/
extern void *
rfapi_rfp_get_l2_group_config_ptr_lni(void *rfp_start_val,
				      uint32_t logical_net_id, void *criteria,
				      rfp_group_config_search_cb_t *search_cb);

/***********************************************************************
 *			NVE Sessions
 ***********************************************************************/

/*------------------------------------------
 * rfapi_open
 *
 * This function initializes a NVE record and associates it with
 * the specified VN and underlay network addresses
 *
 * input:
 *      rfp_start_val   value returned by rfp_start
 *	vn		NVE virtual network address
 *
 *	un		NVE underlay network address
 *
 *	default_options	Default options to use on registrations.
 *			For now only tunnel type is supported.
 *			May be overridden per-prefix in rfapi_register().
 *			Caller owns (rfapi_open() does not free)
 *
 *	response_cb	Pointer to next hop list update callback function or
 *			NULL when no callbacks are desired.
 *
 *	userdata	Passed to subsequent response_cb invocations.
 *
 * output:
 *	response_lifetime The length of time that responses sent to this
 *			NVE are valid.
 *
 *	pHandle		pointer to location to store rfapi handle. The
 *			handle must be passed on subsequent rfapi_ calls.
 *
 *
 * return value:
 *	0		Success
 *	EEXIST		NVE with this {vn,un} already open
 *	ENOENT		No matching nve group config
 *	ENOMSG		Matched nve group config was incomplete
 *	ENXIO		BGP or VNC not configured
 *	EAFNOSUPPORT	Matched nve group specifies auto-assignment of RD,
 *			but underlay network address is not IPv4
 *	EDEADLK		Called from within a callback procedure
 *------------------------------------------*/
extern int rfapi_open(void *rfp_start_val, struct rfapi_ip_addr *vn,
		      struct rfapi_ip_addr *un,
		      struct rfapi_un_option *default_options,
		      uint32_t *response_lifetime, void *userdata,
		      rfapi_handle *pHandle);


/*------------------------------------------
 * rfapi_close
 *
 * Shut down NVE session and release associated data. Calling
 * from within a rfapi callback procedure is permitted (the close
 * will be completed asynchronously after the callback finishes).
 *
 * input:
 *    rfd: rfapi descriptor returned by rfapi_open
 *
 * output:
 *
 * return value:
 *	0		Success
 *	EBADF		invalid handle
 *	ENXIO		BGP or VNC not configured
 *------------------------------------------*/
extern int rfapi_close(rfapi_handle rfd);

/*------------------------------------------
 * rfapi_check
 *
 * Test rfapi descriptor
 *
 * input:
 *    rfd: rfapi descriptor returned by rfapi_open
 *
 * output:
 *
 * return value:
 *	0		Success: handle is valid and usable
 *	EINVAL		null argument
 *	ESTALE		formerly valid handle invalidated by config, needs close
 *	EBADF		invalid handle
 *	ENXIO		BGP or VNC not configured
 *	EAFNOSUPPORT	Internal addressing error
 *------------------------------------------*/
extern int rfapi_check(rfapi_handle rfd);

/***********************************************************************
 *			NVE Routes
 ***********************************************************************/

/*------------------------------------------
 * rfapi_query
 *
 * This function queries the RIB for a
 * particular route.  Note that this call may result in subsequent
 * callbacks to response_cb.  Response callbacks can be cancelled
 * by calling rfapi_query_done.  A duplicate query using the same target
 * will result in only one callback per change in next_hops. (i.e.,
 * cancel/replace the prior query results.)
 *
 * input:
 *    rfd:	rfapi descriptor returned by rfapi_open
 *    target:	the destination address
 *    l2o	ptr to L2 Options struct, NULL if not present in query
 *
 * output:
 *	ppNextHopEntry	pointer to a location to store a pointer
 *			to the returned list of nexthops. It is the
 *			caller's responsibility to free this list
 *			via rfapi_free_next_hop_list().
 *
 *
 * return value:
 *	0		Success
 *	EBADF		invalid handle
 *	ENOENT		no valid route
 *	ENXIO		BGP or VNC not configured
 *	ESTALE		descriptor is no longer usable; should be closed
 *	EDEADLK		Called from within a callback procedure
--------------------------------------------*/
extern int rfapi_query(rfapi_handle rfd, struct rfapi_ip_addr *target,
		       struct rfapi_l2address_option *l2o,
		       struct rfapi_next_hop_entry **ppNextHopEntry);

/*------------------------------------------
 * rfapi_query_done
 *
 * Notifies the rfapi that the user is no longer interested
 * in the specified target.
 *
 * input:
 *    rfd:	rfapi descriptor returned by rfapi_open
 *    target:	the destination address
 *
 * output:
 *
 * return value:
 *	0		Success
 *	EBADF		invalid handle
 *	ENOENT		no match found for target
 *	ENXIO		BGP or VNC not configured
 *	ESTALE		descriptor is no longer usable; should be closed
 *	EDEADLK		Called from within a callback procedure
--------------------------------------------*/
extern int rfapi_query_done(rfapi_handle rfd, struct rfapi_ip_addr *target);

/*------------------------------------------
 * rfapi_query_done_all
 *
 * Notifies the rfapi that the user is no longer interested
 * in any target.
 *
 * input:
 *    rfd:	rfapi descriptor returned by rfapi_open
 *
 * output:
 *    count:	number of queries cleared
 *
 * return value:
 *	0		Success
 *	EBADF		invalid handle
 *	ENXIO		BGP or VNC not configured
 *	ESTALE		descriptor is no longer usable; should be closed
 *	EDEADLK		Called from within a callback procedure
--------------------------------------------*/
extern int rfapi_query_done_all(rfapi_handle rfd, int *count);

/*------------------------------------------
 * rfapi_register
 *
 * Requests that reachability to the indicated prefix via this NVE
 * be advertised by BGP. If <unregister> is non-zero, then the previously-
 * advertised prefix should be withdrawn.
 *
 * (This function should NOT be called if the rfapi_open() function
 * returns NULL)
 *
 * input:
 *    rfd:		rfapi descriptor returned by rfapi_open
 *    prefix:           A prefix to be registered or deregistered
 *    lifetime		Prefix lifetime in seconds, host byte order
 *    options_un	underlay netowrk options, may include tunnel-type
 *			Caller owns (rfapi_register() does not free).
 *    options_vn	virtual network options, may include layer 2 address
 *			option and local-nexthop option
 *			Caller owns (rfapi_register() does not free).
 *
 *    action:       	RFAPI_REGISTER_ADD	add the route
 *                      RFAPI_REGISTER_WITHDRAW	withdraw route
 *			RFAPI_REGISTER_KILL	withdraw without holddown
 *
 * return value:
 *	0		Success
 *	EBADF		invalid handle
 *	ENXIO		BGP or VNC not configured
 *	ESTALE		descriptor is no longer usable; should be closed
 *	EDEADLK		Called from within a callback procedure
 --------------------------------------------*/

typedef enum {
	RFAPI_REGISTER_ADD,
	RFAPI_REGISTER_WITHDRAW,
	RFAPI_REGISTER_KILL
} rfapi_register_action;

extern int rfapi_register(rfapi_handle rfd, struct rfapi_ip_prefix *prefix,
			  uint32_t lifetime, struct rfapi_un_option *options_un,
			  struct rfapi_vn_option *options_vn,
			  rfapi_register_action action);

/***********************************************************************
 *			Helper / Utility functions
 ***********************************************************************/

/*------------------------------------------
 * rfapi_get_vn_addr
 *
 * Get the virtual network address used by an NVE based on it's RFD
 *
 * input:
 *    rfd: rfapi descriptor returned by rfapi_open or rfapi_create_generic
 *
 * output:
 *
 * return value:
 *	vn		NVE virtual network address
 *------------------------------------------*/
extern struct rfapi_ip_addr *rfapi_get_vn_addr(void *);

/*------------------------------------------
 * rfapi_get_un_addr
 *
 * Get the underlay network address used by an NVE based on it's RFD
 *
 * input:
 *    rfd: rfapi descriptor returned by rfapi_open or rfapi_create_generic
 *
 * output:
 *
 * return value:
 *	un		NVE underlay network address
 *------------------------------------------*/
extern struct rfapi_ip_addr *rfapi_get_un_addr(void *);

/*------------------------------------------
 * rfapi_error_str
 *
 * Returns a string describing the rfapi error code.
 *
 * input:
 *
 *	code		Error code returned by rfapi function
 *
 * returns:
 *
 *	const char *	String
 *------------------------------------------*/
extern const char *rfapi_error_str(int code);

/*------------------------------------------
 * rfapi_get_rfp_start_val
 *
 * Returns value passed to rfapi on rfp_start
 *
 * input:
 *	void *		bgp structure
 *
 * returns:
 *	void *
 *------------------------------------------*/
extern void *rfapi_get_rfp_start_val(void *bgpv);

/*------------------------------------------
 * rfapi_compare_rfds
 *
 * Compare two generic rfapi descriptors.
 *
 * input:
 *    rfd1: rfapi descriptor returned by rfapi_open or rfapi_create_generic
 *    rfd2: rfapi descriptor returned by rfapi_open or rfapi_create_generic
 *
 * output:
 *
 * return value:
 *	0		Mismatch
 *	1		Match
 *------------------------------------------*/
extern int rfapi_compare_rfds(void *rfd1, void *rfd2);

/*------------------------------------------
 * rfapi_free_next_hop_list
 *
 * Frees a next_hop_list returned by a rfapi_query invocation
 *
 * input:
 *    list:   a pointer to a response list (as a
 *            struct rfapi_next_hop_entry) to free.
 *
 * output:
 *
 * return value: None
 --------------------------------------------*/
extern void rfapi_free_next_hop_list(struct rfapi_next_hop_entry *list);

/*------------------------------------------
 * rfapi_get_response_lifetime_default
 *
 * Returns the default lifetime for a response.
 *    rfp_start_val     value returned by rfp_start or
 *                      NULL (=use default instance)
 *
 * input:
 *    None
 *
 * output:
 *
 * return value: The bgp instance default lifetime for a response.
 --------------------------------------------*/
extern int rfapi_get_response_lifetime_default(void *rfp_start_val);

/*------------------------------------------
 * rfapi_is_vnc_configured
 *
 * Returns if VNC is configured
 *
 * input:
 *    rfp_start_val     value returned by rfp_start or
 *                      NULL (=use default instance)
 *
 * output:
 *
 * return value: If VNC is configured for the bgpd instance
 *	0		Success
 *	ENXIO		VNC not configured
 --------------------------------------------*/
extern int rfapi_is_vnc_configured(void *rfp_start_val);

/*------------------------------------------
 * rfapi_bgp_lookup_by_rfp
 *
 * Find bgp instance pointer based on value returned by rfp_start
 *
 * input:
 *      rfp_start_val     value returned by rfp_startor
 *                        NULL (=get default instance)
 *
 * output:
 *	none
 *
 * return value:
 *	bgp             bgp instance pointer
 *      NULL = not found
 *
 --------------------------------------------*/
extern struct bgp *rfapi_bgp_lookup_by_rfp(void *rfp_start_val);

/*------------------------------------------
 * rfapi_get_rfp_start_val_by_bgp
 *
 * Find bgp instance pointer based on value returned by rfp_start
 *
 * input:
 *	bgp             bgp instance pointer
 *
 * output:
 *	none
 *
 * return value:
 *	rfp_start_val
 *      NULL = not found
 *
 --------------------------------------------*/
extern void *rfapi_get_rfp_start_val_by_bgp(struct bgp *bgp);

#endif /* ENABLE_BGP_VNC */

#endif /* _QUAGGA_BGP_RFAPI_H */