]> git.ipfire.org Git - thirdparty/bird.git/blob - proto/mrt/mrt.h
The MRT protocol
[thirdparty/bird.git] / proto / mrt / mrt.h
1 /*
2 * BIRD -- Multi-Threaded Routing Toolkit (MRT) Protocol
3 *
4 * (c) 2017--2018 Ondrej Zajicek <santiago@crfreenet.org>
5 * (c) 2017--2018 CZ.NIC z.s.p.o.
6 *
7 * Can be freely distributed and used under the terms of the GNU GPL.
8 */
9
10 #ifndef _BIRD_MRT_H_
11 #define _BIRD_MRT_H_
12
13 #include "nest/bird.h"
14 #include "nest/protocol.h"
15 #include "lib/lists.h"
16 #include "nest/route.h"
17 #include "lib/event.h"
18 #include "lib/hash.h"
19
20
21 struct mrt_config {
22 struct proto_config c;
23
24 struct rtable_config *table_cf;
25 const char *table_expr;
26 struct filter *filter;
27 const char *filename;
28 uint period;
29 int always_add_path;
30 };
31
32 struct mrt_proto {
33 struct proto p;
34 timer *timer;
35 event *event;
36
37 struct mrt_target *file;
38 struct mrt_table_dump_state *table_dump;
39 };
40
41 struct mrt_dump_data {
42 const char *table_expr;
43 struct rtable *table_ptr;
44 struct filter *filter;
45 char *filename;
46 };
47
48 struct mrt_peer_entry {
49 u32 index;
50 u32 peer_id;
51 u32 peer_as;
52 ip_addr peer_ip;
53 struct mrt_peer_entry *next;
54 };
55
56 struct mrt_table_dump_state {
57 struct mrt_proto *proto; /* Protocol for regular MRT dumps (or NULL) */
58 struct cli *cli; /* CLI for irregular MRT dumps (or NULL) */
59 struct config *config; /* Config valid during start of dump, locked */
60
61 /* Configuration information */
62 const char *table_expr; /* Wildcard for table name (or NULL) */
63 struct rtable *table_ptr; /* Explicit table (or NULL) */
64 struct filter *filter; /* Optional filter */
65 const char *filename; /* Filename pattern */
66 int always_add_path; /* Always use *_ADDPATH message subtypes */
67
68 /* Allocated by mrt_table_dump_init() */
69 pool *pool; /* Pool for table dump */
70 linpool *linpool; /* Temporary linear pool */
71 linpool *peer_lp; /* Linear pool for peer entries in peer_hash */
72 buffer buf; /* Buffer for MRT messages */
73
74 HASH(struct mrt_peer_entry) peer_hash; /* Hash for peers to find the index */
75
76 struct rtable *table; /* Processed table, NULL initially */
77 struct fib_iterator fit; /* Iterator in processed table */
78 int table_open; /* Whether iterator is linked */
79
80 int add_path; /* Current message subtype is *_ADDPATH */
81 int want_add_path; /* Want *_ADDPATH message later */
82 int max; /* Decreasing counter of dumped routes */
83 u32 seqnum; /* MRT message sequence number */
84 bird_clock_t time_offset; /* Time offset between monotonic and real time */
85
86 u16 peer_count; /* Number of peers */
87 u32 peer_count_offset; /* Buffer offset to store peer_count later */
88 u16 entry_count; /* Number of RIB Entries */
89 u32 entry_count_offset; /* Buffer offset to store entry_count later */
90
91 struct rfile *file; /* tracking for mrt table dump file */
92 int fd;
93 };
94
95 struct mrt_bgp_data {
96 uint peer_as;
97 uint local_as;
98 uint index;
99 uint af;
100 ip_addr peer_ip;
101 ip_addr local_ip;
102 byte *message;
103 uint msg_len;
104 uint old_state;
105 uint new_state;
106 u8 as4;
107 u8 add_path;
108 };
109
110
111 #define MRT_HDR_LENGTH 12 /* MRT Timestamp + MRT Type + MRT Subtype + MRT Load Length */
112 #define MRT_PEER_TYPE_32BIT_ASN 2 /* MRT Table Dump: Peer Index Table: Peer Type: Use 32bit ASN */
113 #define MRT_PEER_TYPE_IPV6 1 /* MRT Table Dump: Peer Index Table: Peer Type: Use IPv6 IP Address */
114
115 #define MRT_ATTR_BUFFER_SIZE 65536
116
117 /* MRT Types */
118 #define MRT_TABLE_DUMP_V2 13
119 #define MRT_BGP4MP 16
120
121 /* MRT Table Dump v2 Subtypes */
122 #define MRT_PEER_INDEX_TABLE 1
123 #define MRT_RIB_IPV4_UNICAST 2
124 #define MRT_RIB_IPV4_MULTICAST 3
125 #define MRT_RIB_IPV6_UNICAST 4
126 #define MRT_RIB_IPV6_MULTICAST 5
127 #define MRT_RIB_GENERIC 6
128 #define MRT_RIB_IPV4_UNICAST_ADDPATH 8
129 #define MRT_RIB_IPV4_MULTICAST_ADDPATH 9
130 #define MRT_RIB_IPV6_UNICAST_ADDPATH 10
131 #define MRT_RIB_IPV6_MULTICAST_ADDPATH 11
132 #define MRT_RIB_GENERIC_ADDPATH 12
133
134 /* MRT BGP4MP Subtypes */
135 #define MRT_BGP4MP_MESSAGE 1
136 #define MRT_BGP4MP_MESSAGE_AS4 4
137 #define MRT_BGP4MP_STATE_CHANGE_AS4 5
138 #define MRT_BGP4MP_MESSAGE_LOCAL 6
139 #define MRT_BGP4MP_MESSAGE_AS4_LOCAL 7
140 #define MRT_BGP4MP_MESSAGE_ADDPATH 8
141 #define MRT_BGP4MP_MESSAGE_AS4_ADDPATH 9
142 #define MRT_BGP4MP_MESSAGE_LOCAL_ADDPATH 10
143 #define MRT_BGP4MP_MESSAGE_AS4_LOCAL_ADDPATH 11
144
145
146 #ifdef CONFIG_MRT
147 void mrt_dump_cmd(struct mrt_dump_data *d);
148 void mrt_dump_bgp_message(struct mrt_bgp_data *d);
149 void mrt_dump_bgp_state_change(struct mrt_bgp_data *d);
150 void mrt_check_config(struct proto_config *C);
151 #else
152 static inline void mrt_dump_bgp_message(struct mrt_bgp_data *d UNUSED) { }
153 static inline void mrt_dump_bgp_state_change(struct mrt_bgp_data *d UNUSED) { }
154 #endif
155
156 #endif /* _BIRD_MRT_H_ */