summaryrefslogtreecommitdiff
path: root/lib/tunnel_encaps.h
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2018-09-28 01:03:42 +0200
committerMikael Magnusson <mikma@users.sourceforge.net>2021-11-06 00:07:40 +0100
commit4d2bf9c7aa9525ee682311679e85cdbd3fb2e51e (patch)
tree0122ff8f3ae163f3f3060dc58e9297013c85fa6d /lib/tunnel_encaps.h
parentc8eff2ae3eb1c6090b4cc85cb5d19699c45d9f26 (diff)
TunnelEncaps: Initial commit
Filter: TLV Filter: support multiple TLVs Filter: clean unused build_tunnel_encap and calc_tunnel_encap Filter: replace te_format_tlvlist using format visitor Filter: add af to ep subtlv Filter: define tlvlist_calc_tunnel_encap_new and tlvlist_decode_tunnel_encap Filter: use tlvlist_calc_tunnel_encap_new Filter: add visit_tlv_end and visit_subtlv_end Filter: use visitor in EA_SET Filter: use vistor in EA_SET Filter: add tlvlist_same fixes configure free peer Generalize tunnel encapsulation Add struct tunnel_encap Improve format function Add tunnel type names Add cloud security tunnel type Update tunnel types Add addess family Replace log with DBG Add format callback Add wireguard peer key to tunnel encap format Move wireguard formatting from tunnel_encaps library Change from eattr to adata in decode and format Support multiple TLVs Use visitor pattern Use visitor in wireguard Remove decode_tunnel_encap Replace te_format_tlvlist using format visitor Remove unused structs Use AFI_IPV4+6 Add visit_tlv_end and visit_subtlv_end Remove debug Fix format encap + ep Register encap name Filter: Simplify TLV Remove some reserved keywords: TUNNEL_ENCAP, TUNNEL_ENDPOINT, UDP_DEST_PORT, and COLOR Support unknown sub-TLV. Filter: Clean up Clean up unused functions and structs. Filter: replace asn with reserved in ep. Filter: Remove unused T_TLV Filter: Clean up commented code Filter: Remove unused empty set Filter: Refactor encoder Filter: Refactor tlvlist Filter: Implement unknown cmp Filter: Simplify encoding Filter: Add EA_GET Filter: Fix indent
Diffstat (limited to 'lib/tunnel_encaps.h')
-rw-r--r--lib/tunnel_encaps.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/tunnel_encaps.h b/lib/tunnel_encaps.h
new file mode 100644
index 00000000..fc7bbda6
--- /dev/null
+++ b/lib/tunnel_encaps.h
@@ -0,0 +1,63 @@
+#ifndef _BIRD_TUNNEL_ENCAPS_
+#define _BIRD_TUNNEL_ENCAPS_
+
+#include "nest/attrs.h"
+#include "nest/route.h"
+
+#define BA_TUNNEL_ENCAP 0x17
+
+#define BGP_TUNNEL_ENCAP_A_SUB_TLV_ENCAP 1
+#define BGP_TUNNEL_ENCAP_A_SUB_TLV_COLOR 4
+#define BGP_TUNNEL_ENCAP_A_SUB_TLV_TUNNEL_EP 6
+#define BGP_TUNNEL_ENCAP_A_SUB_TLV_UDP_DEST_PORT 8
+
+#define FLAG_BGP_TUNNEL_ENCAP_A_SUB_TLV_ENCAP (1<<BGP_TUNNEL_ENCAP_A_SUB_TLV_ENCAP)
+#define FLAG_BGP_TUNNEL_ENCAP_A_SUB_TLV_COLOR (1<<BGP_TUNNEL_ENCAP_A_SUB_TLV_COLOR)
+#define FLAG_BGP_TUNNEL_ENCAP_A_SUB_TLV_TUNNEL_EP (1<<BGP_TUNNEL_ENCAP_A_SUB_TLV_TUNNEL_EP)
+#define FLAG_BGP_TUNNEL_ENCAP_A_SUB_TLV_UDP_DEST_PORT (1<<BGP_TUNNEL_ENCAP_A_SUB_TLV_UDP_DEST_PORT)
+
+struct te_context {
+ void *opaque;
+ const byte *sub_tlvs_pos;
+ uint sub_tlvs_len;
+};
+
+struct te_visitor {
+ int (*visit_tlv)(int type, struct te_context *ctx);
+ int (*visit_tlv_end)(struct te_context *ctx);
+ int (*visit_subtlv)(int type, struct te_context *ctx);
+ int (*visit_subtlv_end)(int type, struct te_context *ctx);
+ int (*visit_encap)(const struct te_encap *encap, struct te_context *ctx);
+ int (*visit_ep)(const struct te_endpoint *ep, struct te_context *ctx);
+ int (*visit_color)(u32 color, struct te_context *ctx);
+ int (*visit_udp_dest_port)(u16 port, struct te_context *ctx);
+ int (*visit_unknown)(int type, const struct te_unknown *unknown, struct te_context *ctx);
+};
+
+struct te_buffer {
+ byte *pos;
+ uint size;
+ int tlv;
+ int tlv_type;
+ int subtlv;
+};
+
+struct tlv_buffer;
+
+typedef int (*format_tunnel_encap_fn)(const struct te_encap *, byte *buf, uint size);
+
+void tunnel_encap_init(void);
+int walk_tunnel_encap(const struct adata *a, const struct te_visitor *visitor, void *opaque);
+int te_count_subtlvs(struct te_context *ctx);
+
+const struct te_visitor *te_get_format_visitor(void);
+int format_tunnel_encap(const struct adata *a, byte *buf, uint size);
+
+const struct te_visitor *te_get_encode_visitor(void);
+int te_init_encode_visitor(struct tlv_buffer *buf, byte *p, uint size);
+uint te_get_encode_length(struct tlv_buffer *buf);
+
+void register_format_tunnel_encap(int type, const char *name, format_tunnel_encap_fn cb);
+void unregister_format_tunnel_encap(int type, format_tunnel_encap_fn cb);
+
+#endif /* _BIRD_TUNNEL_ENCAPS_ */