summaryrefslogtreecommitdiff
path: root/lib/tunnel_encaps.h
blob: fc7bbda6ac9f26404e8f4a4ec52999c125141906 (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
#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_ */