]> git.proxmox.com Git - mirror_frr.git/blob - doc/developer/zebra.rst
doc: fix typo RFC7572 to RFC7752
[mirror_frr.git] / doc / developer / zebra.rst
1 .. _zebra:
2
3 *****
4 Zebra
5 *****
6
7 .. _zebra-protocol:
8
9 Overview of the Zebra Protocol
10 ==============================
11
12 The Zebra protocol (or ``ZAPI``) is used by protocol daemons to
13 communicate with the **zebra** daemon.
14
15 Each protocol daemon may request and send information to and from the
16 **zebra** daemon such as interface states, routing state,
17 nexthop-validation, and so on. Protocol daemons may also install
18 routes with **zebra**. The **zebra** daemon manages which routes are
19 installed into the forwarding table with the kernel. Some daemons use
20 more than one ZAPI connection. This is supported: each ZAPI session is
21 identified by a tuple of: ``{protocol, instance, session_id}``. LDPD
22 is an example: it uses a second, synchronous ZAPI session to manage
23 label blocks. The default value for ``session_id`` is zero; daemons
24 who use multiple ZAPI sessions must assign unique values to the
25 sessions' ids.
26
27 The Zebra protocol is a streaming protocol, with a common header. Version 0
28 lacks a version field and is implicitly versioned. Version 1 and all subsequent
29 versions have a version field. Version 0 can be distinguished from all other
30 versions by examining the 3rd byte of the header, which contains a marker value
31 of 255 (in Quagga) or 254 (in FRR) for all versions except version 0. The
32 marker byte corresponds to the command field in version 0, and the marker value
33 is a reserved command in version 0.
34
35 Version History
36 ---------------
37
38 - Version 0
39
40 Used by all versions of GNU Zebra and all version of Quagga up to and
41 including Quagga 0.98. This version has no ``version`` field, and so is
42 implicitly versioned as version 0.
43
44 - Version 1
45
46 Added ``marker`` and ``version`` fields, increased ``command`` field to 16
47 bits. Used by Quagga versions 0.99.3 through 0.99.20.
48
49 - Version 2
50
51 Used by Quagga versions 0.99.21 through 0.99.23.
52
53 - Version 3
54
55 Added ``vrf_id`` field. Used by Quagga versions 0.99.23 until FRR fork.
56
57 - Version 4
58
59 Change marker value to 254 to prevent people mixing and matching Quagga and
60 FRR daemon binaries. Used by FRR versions 2.0 through 3.0.3.
61
62 - Version 5
63
64 Increased VRF identifier field from 16 to 32 bits. Used by FRR versions 4.0
65 through 5.0.1.
66
67 - Version 6
68
69 Removed the following commands:
70
71 * ZEBRA_IPV4_ROUTE_ADD
72 * ZEBRA_IPV4_ROUTE_DELETE
73 * ZEBRA_IPV6_ROUTE_ADD
74 * ZEBRA_IPV6_ROUTE_DELETE
75
76 Used since FRR version 6.0.
77
78
79 Zebra Protocol Definition
80 =========================
81
82 Zebra Protocol Header Field Definitions
83 ---------------------------------------
84
85 Length
86 Total packet length including this header.
87
88 Marker
89 Static marker. The marker value, when it exists, is 255 in all versions of
90 Quagga. It is 254 in all versions of FRR. This is to allow version 0 headers
91 (which do not include version explicitly) to be distinguished from versioned
92 headers.
93
94 Version
95 Zebra protocol version number. Clients should not continue processing
96 messages past the version field for versions they do not recognise.
97
98 Command
99 The Zebra protocol command.
100
101
102 Current Version
103 ^^^^^^^^^^^^^^^
104
105 ::
106
107 Version 5, 6
108
109 0 1 2 3
110 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
111 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
112 | Length | Marker | Version |
113 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
114 | VRF ID |
115 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
116 | Command |
117 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
118
119
120 Past Versions
121 ^^^^^^^^^^^^^
122
123 ::
124
125 Version 0
126
127 0 1 2 3
128 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
129 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
130 | Length | Command |
131 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
132
133 ::
134
135 Version 1, 2
136
137 0 1 2 3
138 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
139 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
140 | Length | Marker | Version |
141 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
142 | Command |
143 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
144
145
146 ::
147
148 Version 3, 4
149
150 0 1 2 3
151 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
152 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
153 | Length | Marker | Version |
154 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
155 | VRF ID | Command |
156 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
157
158
159 Zebra Protocol Commands
160 -----------------------
161
162 +------------------------------------+-------+
163 | Command | Value |
164 +====================================+=======+
165 | ZEBRA_INTERFACE_ADD | 0 |
166 +------------------------------------+-------+
167 | ZEBRA_INTERFACE_DELETE | 1 |
168 +------------------------------------+-------+
169 | ZEBRA_INTERFACE_ADDRESS_ADD | 2 |
170 +------------------------------------+-------+
171 | ZEBRA_INTERFACE_ADDRESS_DELETE | 3 |
172 +------------------------------------+-------+
173 | ZEBRA_INTERFACE_UP | 4 |
174 +------------------------------------+-------+
175 | ZEBRA_INTERFACE_DOWN | 5 |
176 +------------------------------------+-------+
177 | ZEBRA_INTERFACE_SET_MASTER | 6 |
178 +------------------------------------+-------+
179 | ZEBRA_INTERFACE_SET_PROTODOWN | 7 |
180 +------------------------------------+-------+
181 | ZEBRA_ROUTE_ADD | 8 |
182 +------------------------------------+-------+
183 | ZEBRA_ROUTE_DELETE | 9 |
184 +------------------------------------+-------+
185 | ZEBRA_ROUTE_NOTIFY_OWNER | 10 |
186 +------------------------------------+-------+
187 | ZEBRA_REDISTRIBUTE_ADD | 11 |
188 +------------------------------------+-------+
189 | ZEBRA_REDISTRIBUTE_DELETE | 12 |
190 +------------------------------------+-------+
191 | ZEBRA_REDISTRIBUTE_DEFAULT_ADD | 13 |
192 +------------------------------------+-------+
193 | ZEBRA_REDISTRIBUTE_DEFAULT_DELETE | 14 |
194 +------------------------------------+-------+
195 | ZEBRA_ROUTER_ID_ADD | 15 |
196 +------------------------------------+-------+
197 | ZEBRA_ROUTER_ID_DELETE | 16 |
198 +------------------------------------+-------+
199 | ZEBRA_ROUTER_ID_UPDATE | 17 |
200 +------------------------------------+-------+
201 | ZEBRA_HELLO | 18 |
202 +------------------------------------+-------+
203 | ZEBRA_CAPABILITIES | 19 |
204 +------------------------------------+-------+
205 | ZEBRA_NEXTHOP_REGISTER | 20 |
206 +------------------------------------+-------+
207 | ZEBRA_NEXTHOP_UNREGISTER | 21 |
208 +------------------------------------+-------+
209 | ZEBRA_NEXTHOP_UPDATE | 22 |
210 +------------------------------------+-------+
211 | ZEBRA_INTERFACE_NBR_ADDRESS_ADD | 23 |
212 +------------------------------------+-------+
213 | ZEBRA_INTERFACE_NBR_ADDRESS_DELETE | 24 |
214 +------------------------------------+-------+
215 | ZEBRA_INTERFACE_BFD_DEST_UPDATE | 25 |
216 +------------------------------------+-------+
217 | ZEBRA_IMPORT_ROUTE_REGISTER | 26 |
218 +------------------------------------+-------+
219 | ZEBRA_IMPORT_ROUTE_UNREGISTER | 27 |
220 +------------------------------------+-------+
221 | ZEBRA_IMPORT_CHECK_UPDATE | 28 |
222 +------------------------------------+-------+
223 | ZEBRA_BFD_DEST_REGISTER | 29 |
224 +------------------------------------+-------+
225 | ZEBRA_BFD_DEST_DEREGISTER | 30 |
226 +------------------------------------+-------+
227 | ZEBRA_BFD_DEST_UPDATE | 31 |
228 +------------------------------------+-------+
229 | ZEBRA_BFD_DEST_REPLAY | 32 |
230 +------------------------------------+-------+
231 | ZEBRA_REDISTRIBUTE_ROUTE_ADD | 33 |
232 +------------------------------------+-------+
233 | ZEBRA_REDISTRIBUTE_ROUTE_DEL | 34 |
234 +------------------------------------+-------+
235 | ZEBRA_VRF_UNREGISTER | 35 |
236 +------------------------------------+-------+
237 | ZEBRA_VRF_ADD | 36 |
238 +------------------------------------+-------+
239 | ZEBRA_VRF_DELETE | 37 |
240 +------------------------------------+-------+
241 | ZEBRA_VRF_LABEL | 38 |
242 +------------------------------------+-------+
243 | ZEBRA_INTERFACE_VRF_UPDATE | 39 |
244 +------------------------------------+-------+
245 | ZEBRA_BFD_CLIENT_REGISTER | 40 |
246 +------------------------------------+-------+
247 | ZEBRA_BFD_CLIENT_DEREGISTER | 41 |
248 +------------------------------------+-------+
249 | ZEBRA_INTERFACE_ENABLE_RADV | 42 |
250 +------------------------------------+-------+
251 | ZEBRA_INTERFACE_DISABLE_RADV | 43 |
252 +------------------------------------+-------+
253 | ZEBRA_NEXTHOP_LOOKUP_MRIB | 44 |
254 +------------------------------------+-------+
255 | ZEBRA_INTERFACE_LINK_PARAMS | 45 |
256 +------------------------------------+-------+
257 | ZEBRA_MPLS_LABELS_ADD | 46 |
258 +------------------------------------+-------+
259 | ZEBRA_MPLS_LABELS_DELETE | 47 |
260 +------------------------------------+-------+
261 | ZEBRA_MPLS_LABELS_REPLACE | 48 |
262 +------------------------------------+-------+
263 | ZEBRA_IPMR_ROUTE_STATS | 49 |
264 +------------------------------------+-------+
265 | ZEBRA_LABEL_MANAGER_CONNECT | 50 |
266 +------------------------------------+-------+
267 | ZEBRA_LABEL_MANAGER_CONNECT_ASYNC | 51 |
268 +------------------------------------+-------+
269 | ZEBRA_GET_LABEL_CHUNK | 52 |
270 +------------------------------------+-------+
271 | ZEBRA_RELEASE_LABEL_CHUNK | 53 |
272 +------------------------------------+-------+
273 | ZEBRA_FEC_REGISTER | 54 |
274 +------------------------------------+-------+
275 | ZEBRA_FEC_UNREGISTER | 55 |
276 +------------------------------------+-------+
277 | ZEBRA_FEC_UPDATE | 56 |
278 +------------------------------------+-------+
279 | ZEBRA_ADVERTISE_DEFAULT_GW | 57 |
280 +------------------------------------+-------+
281 | ZEBRA_ADVERTISE_SVI_MACIP | 58 |
282 +------------------------------------+-------+
283 | ZEBRA_ADVERTISE_SUBNET | 59 |
284 +------------------------------------+-------+
285 | ZEBRA_ADVERTISE_ALL_VNI | 60 |
286 +------------------------------------+-------+
287 | ZEBRA_LOCAL_ES_ADD | 61 |
288 +------------------------------------+-------+
289 | ZEBRA_LOCAL_ES_DEL | 62 |
290 +------------------------------------+-------+
291 | ZEBRA_VNI_ADD | 63 |
292 +------------------------------------+-------+
293 | ZEBRA_VNI_DEL | 64 |
294 +------------------------------------+-------+
295 | ZEBRA_L3VNI_ADD | 65 |
296 +------------------------------------+-------+
297 | ZEBRA_L3VNI_DEL | 66 |
298 +------------------------------------+-------+
299 | ZEBRA_REMOTE_VTEP_ADD | 67 |
300 +------------------------------------+-------+
301 | ZEBRA_REMOTE_VTEP_DEL | 68 |
302 +------------------------------------+-------+
303 | ZEBRA_MACIP_ADD | 69 |
304 +------------------------------------+-------+
305 | ZEBRA_MACIP_DEL | 70 |
306 +------------------------------------+-------+
307 | ZEBRA_IP_PREFIX_ROUTE_ADD | 71 |
308 +------------------------------------+-------+
309 | ZEBRA_IP_PREFIX_ROUTE_DEL | 72 |
310 +------------------------------------+-------+
311 | ZEBRA_REMOTE_MACIP_ADD | 73 |
312 +------------------------------------+-------+
313 | ZEBRA_REMOTE_MACIP_DEL | 74 |
314 +------------------------------------+-------+
315 | ZEBRA_DUPLICATE_ADDR_DETECTION | 75 |
316 +------------------------------------+-------+
317 | ZEBRA_PW_ADD | 76 |
318 +------------------------------------+-------+
319 | ZEBRA_PW_DELETE | 77 |
320 +------------------------------------+-------+
321 | ZEBRA_PW_SET | 78 |
322 +------------------------------------+-------+
323 | ZEBRA_PW_UNSET | 79 |
324 +------------------------------------+-------+
325 | ZEBRA_PW_STATUS_UPDATE | 80 |
326 +------------------------------------+-------+
327 | ZEBRA_RULE_ADD | 81 |
328 +------------------------------------+-------+
329 | ZEBRA_RULE_DELETE | 82 |
330 +------------------------------------+-------+
331 | ZEBRA_RULE_NOTIFY_OWNER | 83 |
332 +------------------------------------+-------+
333 | ZEBRA_TABLE_MANAGER_CONNECT | 84 |
334 +------------------------------------+-------+
335 | ZEBRA_GET_TABLE_CHUNK | 85 |
336 +------------------------------------+-------+
337 | ZEBRA_RELEASE_TABLE_CHUNK | 86 |
338 +------------------------------------+-------+
339 | ZEBRA_IPSET_CREATE | 87 |
340 +------------------------------------+-------+
341 | ZEBRA_IPSET_DESTROY | 88 |
342 +------------------------------------+-------+
343 | ZEBRA_IPSET_ENTRY_ADD | 89 |
344 +------------------------------------+-------+
345 | ZEBRA_IPSET_ENTRY_DELETE | 90 |
346 +------------------------------------+-------+
347 | ZEBRA_IPSET_NOTIFY_OWNER | 91 |
348 +------------------------------------+-------+
349 | ZEBRA_IPSET_ENTRY_NOTIFY_OWNER | 92 |
350 +------------------------------------+-------+
351 | ZEBRA_IPTABLE_ADD | 93 |
352 +------------------------------------+-------+
353 | ZEBRA_IPTABLE_DELETE | 94 |
354 +------------------------------------+-------+
355 | ZEBRA_IPTABLE_NOTIFY_OWNER | 95 |
356 +------------------------------------+-------+
357 | ZEBRA_VXLAN_FLOOD_CONTROL | 96 |
358 +------------------------------------+-------+
359 | ZEBRA_VXLAN_SG_ADD | 97 |
360 +------------------------------------+-------+
361 | ZEBRA_VXLAN_SG_DEL | 98 |
362 +------------------------------------+-------+
363 | ZEBRA_VXLAN_SG_REPLAY | 99 |
364 +------------------------------------+-------+
365 | ZEBRA_MLAG_PROCESS_UP | 100 |
366 +------------------------------------+-------+
367 | ZEBRA_MLAG_PROCESS_DOWN | 101 |
368 +------------------------------------+-------+
369 | ZEBRA_MLAG_CLIENT_REGISTER | 102 |
370 +------------------------------------+-------+
371 | ZEBRA_MLAG_CLIENT_UNREGISTER | 103 |
372 +------------------------------------+-------+
373 | ZEBRA_MLAG_FORWARD_MSG | 104 |
374 +------------------------------------+-------+
375 | ZEBRA_ERROR | 105 |
376 +------------------------------------+-------+
377 | ZEBRA_CLIENT_CAPABILITIES | 106 |
378 +------------------------------------+-------+
379 | ZEBRA_OPAQUE_MESSAGE | 107 |
380 +------------------------------------+-------+
381 | ZEBRA_OPAQUE_REGISTER | 108 |
382 +------------------------------------+-------+
383 | ZEBRA_OPAQUE_UNREGISTER | 109 |
384 +------------------------------------+-------+
385 | ZEBRA_NEIGH_DISCOVER | 110 |
386 +------------------------------------+-------+
387
388 Dataplane batching
389 ==================
390
391 Dataplane batching is an optimization feature that reduces the processing
392 time involved in the user space to kernel space transition for every message we
393 want to send.
394
395 Design
396 -----------
397
398 With our dataplane abstraction, we create a queue of dataplane context objects
399 for the messages we want to send to the kernel. In a separate pthread, we
400 loop over this queue and send the context objects to the appropriate
401 dataplane. A batching enhancement tightly integrates with the dataplane
402 context objects so they are able to be batch sent to dataplanes that support
403 it.
404
405 There is one main change in the dataplane code. It does not call
406 kernel-dependent functions one-by-one, but instead it hands a list of work down
407 to the kernel level for processing.
408
409 Netlink
410 ^^^^^^^
411
412 At the moment, this is the only dataplane that allows for batch sending
413 messages to it.
414
415 When messages must be sent to the kernel, they are consecutively added
416 to the batch represented by the `struct nl_batch`. Context objects are firstly
417 encoded to their binary representation. All the encoding functions use the same
418 interface: take a context object, a buffer and a size of the buffer as an
419 argument. It is important that they should handle a situation in which a message
420 wouldn't fit in the buffer and return a proper error. To achieve a zero-copy
421 (in the user space only) messages are encoded to the same buffer which will
422 be passed to the kernel. Hence, we can theoretically hit the boundary of the
423 buffer.
424
425 Messages stored in the batch are sent if one of the conditions occurs:
426
427 - When an encoding function returns the buffer overflow error. The context
428 object that caused this error is re-added to the new, empty batch.
429
430 - When the size of the batch hits certain limit.
431
432 - When the namespace of a currently being processed context object is
433 different from all the previous ones. They have to be sent through
434 distinct sockets, so the messages cannot share the same buffer.
435
436 - After the last message from the list is processed.
437
438 As mentioned earlier, there is a special threshold which is smaller than
439 the size of the underlying buffer. It prevents the overflow error and thus
440 eliminates the case, in which a message is encoded twice.
441
442 The buffer used in the batching is global, since allocating that big amount of
443 memory every time wouldn't be most effective. However, its size can be changed
444 dynamically, using hidden vtysh command:
445 ``zebra kernel netlink batch-tx-buf (1-1048576) (1-1048576)``. This feature is
446 only used in tests and shouldn't be utilized in any other place.
447
448 For every failed message in the batch, the kernel responds with an error
449 message. Error messages are kept in the same order as they were sent, so parsing the
450 response is straightforward. We use the two pointer technique to match
451 requests with responses and then set appropriate status of dataplane context
452 objects. There is also a global receive buffer and it is assumed that whatever
453 the kernel sends it will fit in this buffer. The payload of netlink error messages
454 consists of a error code and the original netlink message of the request, so
455 the batch response won't be bigger than the batch request increased by
456 some space for the headers.