]> git.ipfire.org Git - thirdparty/bird.git/blob - proto/mrt/mrt.h
Formalized our contribution policy which we're currently applying
[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 const 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 const struct filter *filter;
45 const 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 const 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 ipv4; /* Processed table is IPv4 */
81 int add_path; /* Current message subtype is *_ADDPATH */
82 int want_add_path; /* Want *_ADDPATH message later */
83 int max; /* Decreasing counter of dumped routes */
84 u32 seqnum; /* MRT message sequence number */
85 btime time_offset; /* Time offset between monotonic and real time */
86 struct bgp_write_state *bws; /* */
87
88 u16 peer_count; /* Number of peers */
89 u32 peer_count_offset; /* Buffer offset to store peer_count later */
90 u16 entry_count; /* Number of RIB Entries */
91 u32 entry_count_offset; /* Buffer offset to store entry_count later */
92
93 struct rfile *file; /* tracking for mrt table dump file */
94 int fd;
95 };
96
97 struct mrt_bgp_data {
98 uint peer_as;
99 uint local_as;
100 uint index;
101 uint af;
102 ip_addr peer_ip;
103 ip_addr local_ip;
104 byte *message;
105 uint msg_len;
106 uint old_state;
107 uint new_state;
108 u8 as4;
109 u8 add_path;
110 };
111
112
113 #define MRT_HDR_LENGTH 12 /* MRT Timestamp + MRT Type + MRT Subtype + MRT Load Length */
114 #define MRT_PEER_TYPE_32BIT_ASN 2 /* MRT Table Dump: Peer Index Table: Peer Type: Use 32bit ASN */
115 #define MRT_PEER_TYPE_IPV6 1 /* MRT Table Dump: Peer Index Table: Peer Type: Use IPv6 IP Address */
116
117 #define MRT_ATTR_BUFFER_SIZE 65536
118
119 /* MRT Types */
120 #define MRT_TABLE_DUMP_V2 13
121 #define MRT_BGP4MP 16
122
123 /* MRT Table Dump v2 Subtypes */
124 #define MRT_PEER_INDEX_TABLE 1
125 #define MRT_RIB_IPV4_UNICAST 2
126 #define MRT_RIB_IPV4_MULTICAST 3
127 #define MRT_RIB_IPV6_UNICAST 4
128 #define MRT_RIB_IPV6_MULTICAST 5
129 #define MRT_RIB_GENERIC 6
130 #define MRT_RIB_IPV4_UNICAST_ADDPATH 8
131 #define MRT_RIB_IPV4_MULTICAST_ADDPATH 9
132 #define MRT_RIB_IPV6_UNICAST_ADDPATH 10
133 #define MRT_RIB_IPV6_MULTICAST_ADDPATH 11
134 #define MRT_RIB_GENERIC_ADDPATH 12
135
136 /* MRT BGP4MP Subtypes */
137 #define MRT_BGP4MP_MESSAGE 1
138 #define MRT_BGP4MP_MESSAGE_AS4 4
139 #define MRT_BGP4MP_STATE_CHANGE_AS4 5
140 #define MRT_BGP4MP_MESSAGE_LOCAL 6
141 #define MRT_BGP4MP_MESSAGE_AS4_LOCAL 7
142 #define MRT_BGP4MP_MESSAGE_ADDPATH 8
143 #define MRT_BGP4MP_MESSAGE_AS4_ADDPATH 9
144 #define MRT_BGP4MP_MESSAGE_LOCAL_ADDPATH 10
145 #define MRT_BGP4MP_MESSAGE_AS4_LOCAL_ADDPATH 11
146
147
148 #ifdef CONFIG_MRT
149 void mrt_dump_cmd(struct mrt_dump_data *d);
150 void mrt_dump_bgp_message(struct mrt_bgp_data *d);
151 void mrt_dump_bgp_state_change(struct mrt_bgp_data *d);
152 void mrt_check_config(struct proto_config *C);
153 #else
154 static inline void mrt_dump_bgp_message(struct mrt_bgp_data *d UNUSED) { }
155 static inline void mrt_dump_bgp_state_change(struct mrt_bgp_data *d UNUSED) { }
156 #endif
157
158 #endif /* _BIRD_MRT_H_ */