]> git.proxmox.com Git - mirror_frr.git/blob - doc/developer/workflow.rst
80029cbd1c27686447a5df0d830fc0c227f566a9
[mirror_frr.git] / doc / developer / workflow.rst
1 .. _process-and-workflow:
2
3 *******************
4 Process & Workflow
5 *******************
6
7 FRR is a large project developed by many different groups. This section
8 documents standards for code style & quality, commit messages, pull requests
9 and best practices that all contributors are asked to follow.
10
11 This chapter is "descriptive/post-factual" in that it documents pratices that
12 are in use; it is not "definitive/pre-factual" in prescribing practices. This
13 means that when a procedure changes, it is agreed upon, then put into practice,
14 and then documented here. If this document doesn't match reality, it's the
15 document that needs to be updated, not reality.
16
17 Mailing Lists
18 =============
19
20 The FRR development group maintains multiple mailing lists for use by the
21 community. Italicized lists are private.
22
23 +----------------------------------+--------------------------------+
24 | Topic | List |
25 +==================================+================================+
26 | Development | dev@lists.frrouting.org |
27 +----------------------------------+--------------------------------+
28 | Users & Operators | frog@lists.frrouting.org |
29 +----------------------------------+--------------------------------+
30 | Announcements | announce@lists.frrouting.org |
31 +----------------------------------+--------------------------------+
32 | *Security* | security@lists.frrouting.org |
33 +----------------------------------+--------------------------------+
34 | *Technical Steering Committee* | tsc@lists.frrouting.org |
35 +----------------------------------+--------------------------------+
36
37 The Development list is used to discuss and document general issues related to
38 project development and governance. The public Slack instance,
39 frrouting.slack.com, and weekly technical meetings provide a higher bandwidth
40 channel for discussions. The results of such discussions must be reflected in
41 updates, as appropriate, to code (i.e., merges), `Github issues`_, and for
42 governance or process changes, updates to the Development list and either this
43 file or information posted at https://frrouting.org/.
44
45 Release Process & Schedule
46 ==========================
47
48 FRR employs a <MAJOR>.<MINOR>.<BUGFIX> versioning scheme.
49
50 MAJOR
51 Significant new features or multiple minor features. The addition of a new
52 routing protocol or daemon would fall under this class.
53
54 MINOR
55 Small features, e.g. options for automatic BGP shutdown.
56
57 BUGFIX
58 Fixes for actual bugs and/or security issues.
59
60 We will pull a new development branch for the next release every 4 months. The
61 current schedule is Feb/June/October 1. The decision for a MAJOR/MINOR release
62 is made at the time of branch pull based on what has been received the previous
63 4 months. The branch name will be dev/MAJOR.MINOR. At this point in time the
64 master branch, :file:`configure.ac`, documentation and packaging systems will
65 be updated to reflect the next possible release name to allow for easy
66 distinguishing. Additionally the new dev branch will have these files updated
67 too.
68
69 After one month the development branch will be renamed to stable/MAJOR.MINOR.
70 This process is not held up unless a crash or security issue has been found and
71 needs to be addressed. Issues being fixed will not cause a delay.
72
73 Bugfix releases are made as needed at 1 month intervals until the next
74 MAJOR.MINOR relese branch is pulled. Depending on the severity of the bugs,
75 bugfix releases may occur sooner.
76
77 Bugfixes are applied to the two most recent releases. Security fixes are
78 backported to all releases less than or equal to one year old. Security fixes
79 may also be backported to older releases depending on severity.
80
81 Changelog
82 =========
83
84 The changelog will be the base for the release notes. A changelog entry for
85 your changes is usually not required and will be added based on your commit
86 messages by the maintainers. However, you are free to include an update to the
87 changelog with some better description.
88
89 Submitting Patches and Enhancements
90 ===================================
91
92 FRR accepts patches from two sources:
93
94 - Email (git format-patch)
95 - Github pull request
96
97 Contributors are highly encouraged to use Github's fork-and-pr workflow. It is
98 easier for us to review it, test it, try it and discuss it on Github than it is
99 via email, thus your patch will get more attention more quickly on Github.
100
101 The base branch for new contributions and non-critical bug fixes should be
102 ``master``. Please ensure your pull request is based on this branch when you
103 submit it.
104
105 Pre-submission Checklist
106 ------------------------
107
108 - Format code (see `Code Formatting <#developers-guidelines>`__)
109 - Verify and acknowledge license (see `License for
110 contributions <#license-for-contributions>`__)
111 - Ensure you have properly signed off (see `Signing
112 Off <#signing-off>`__)
113 - Test building with various configurations:
114
115 - ``buildtest.sh``
116
117 - Verify building source distribution:
118
119 - ``make dist`` (and try rebuilding from the resulting tar file)
120
121 - Run unit tests:
122
123 - ``make test``
124
125 - Document Regression Runs and plans for continued maintenance of the
126 feature
127
128 License for contributions
129 -------------------------
130
131 FRR is under a “GPLv2 or later” license. Any code submitted must
132 be released under the same license (preferred) or any license which
133 allows redistribution under this GPLv2 license (eg MIT License).
134
135 Signing Off
136 -----------
137
138 Code submitted to FRR must be signed off. We have the same
139 requirements for using the signed-off-by process as the Linux kernel. In
140 short, you must include a signed-off-by tag in every patch.
141
142 ``Signed-off-by:`` this is a developer's certification that he or she
143 has the right to submit the patch for inclusion into the project. It is
144 an agreement to the Developer's Certificate of Origin (below). Code
145 without a proper signoff can not and will not be merged.
146
147 If you are unfamiliar with this process, you should read the `official
148 policy at
149 kernel.org <https://www.kernel.org/doc/html/latest/process/submitting-patches.html>`__
150 and you might find this article about `participating in the Linux
151 community on the Linux Foundation
152 website <http://www.linuxfoundation.org/content/how-participate-linux-community-0>`__
153 to be a helpful resource.
154
155 In short, when you sign off on a commit, you assert your agreement to
156 all of the following:
157
158 ::
159
160 Developer's Certificate of Origin 1.1
161
162 By making a contribution to this project, I certify that:
163
164 (a) The contribution was created in whole or in part by me and I
165 have the right to submit it under the open source license
166 indicated in the file; or
167
168 (b) The contribution is based upon previous work that, to the best
169 of my knowledge, is covered under an appropriate open source
170 license and I have the right under that license to submit that
171 work with modifications, whether created in whole or in part by
172 me, under the same open source license (unless I am permitted to
173 submit under a different license), as indicated in the file; or
174
175 (c) The contribution was provided directly to me by some other
176 person who certified (a), (b) or (c) and I have not modified it.
177
178 (d) I understand and agree that this project and the contribution
179 are public and that a record of the contribution (including all
180 personal information I submit with it, including my sign-off) is
181 maintained indefinitely and may be redistributed consistent with
182 this project or the open source license(s) involved.
183
184 What do I submit my changes against?
185 ------------------------------------
186
187 We've documented where we would like to have the different fixes applied
188 at
189 https://github.com/FRR/frr/wiki/Where-Do-I-create-a-Pull-Request-against%3F
190 If you are unsure where your submission goes, look at that document or
191 ask a project maintainer.
192
193 Github pull requests
194 --------------------
195
196 The preferred method of submitting changes is a Github pull request.
197 Code submitted by pull request will be automatically tested by one or
198 more CI systems. Once the automated tests succeed, other developers will
199 review your code for quality and correctness. After any concerns are
200 resolved, your code will be merged into the branch it was submitted
201 against.
202
203 Patch submission via mailing list
204 ---------------------------------
205
206 As an alternative submission method, a patch can be mailed to the
207 development mailing list. Patches received on the mailing list will be
208 picked up by Patchwork and tested against the latest development branch.
209
210 The recommended way to send the patch (or series of NN patches) to the
211 list is by using ``git send-email`` as follows (assuming they are the N
212 most recent commit(s) in your git history:
213
214 ::
215
216 git send-email -NN --annotate --to=dev@lists.frrouting.org
217
218 If your commits do not already contain a ``Signed-off-by`` line, then
219 use the following command to add it (after making sure you agree to the
220 Developer Certificate of Origin as outlined above):
221
222 ::
223
224 git send-email -NN --annotate --signoff --to=dev@lists.frrouting.org
225
226 Submitting multi-commit patches as a Github pull request is **strongly
227 encouraged** and increases the probability of your patch getting
228 reviewed and merged in a timely manner.
229
230 After submitting your changes
231 -----------------------------
232
233 - Watch for Continuous Integration (CI) Test results
234
235 - You should automatically receive an email with the test results
236 within less than 2 hrs of the submission. If you don’t get the
237 email, then check status on the Github pull request.
238 - Please notify the development mailing list if you think something
239 doesn't work.
240
241 - If the tests failed:
242
243 - In general, expect the community to ignore the submission until
244 the tests pass.
245 - It is up to you to fix and resubmit.
246
247 - This includes fixing existing unit (“make test”) tests if your
248 changes broke or changed them.
249 - It also includes fixing distribution packages for the failing
250 platforms (ie if new libraries are required).
251 - Feel free to ask for help on the development list.
252
253 - Go back to the submission process and repeat until the tests pass.
254
255 - If the tests pass:
256
257 - Wait for reviewers. Someone will review your code or be assigned
258 to review your code.
259 - Respond to any comments or concerns the reviewer has.
260 - After all comments and concerns are addressed, expect your patch
261 to be merged.
262
263 - Watch out for questions on the mailing list. At this time there will
264 be a manual code review and further (longer) tests by various
265 community members.
266 - Your submission is done once it is merged to the master branch.
267
268 Git Structure
269 =============
270
271 .. figure:: ../figures/git_branches.png
272 :align: center
273 :scale: 55%
274 :alt: Merging Git branches into a central trunk
275
276 Rough outline of FRR development workflow
277
278 The master Git for FRR resides on `GitHub`_.
279
280 There is one main branch for development, ``master``. For each major release
281 (2.0, 3.0 etc) a new release branch is created based on the master. Subsequent
282 point releases based on a major branch are marked by tagging.
283
284 Programming Languages, Tools and Libraries
285 ==========================================
286
287 The core of FRR is written in C (gcc or clang supported) and makes
288 use of GNU compiler extensions. A few non-essential scripts are
289 implemented in Perl and Python. FRR requires the following tools
290 to build distribution packages: automake, autoconf, texinfo, libtool and
291 gawk and various libraries (i.e. libpam and libjson-c).
292
293 If your contribution requires a new library or other tool, then please
294 highlight this in your description of the change. Also make sure it’s
295 supported by all FRR platform OSes or provide a way to build
296 without the library (potentially without the new feature) on the other
297 platforms.
298
299 Documentation should be written in reStructuredText. Sphinx extensions may be
300 utilized but pure ReST is preferred where possible. See
301 :ref:`documentation`.
302
303
304 Coding Practices & Style
305 ========================
306
307 Commit messages
308 ---------------
309
310 Commit messages should be formatted in the same way as Linux kernel
311 commit messages. The format is roughly
312
313 ::
314
315 dir: short summary
316
317 extended summary
318
319 ``dir`` should be the top level source directory under which the change
320 was made. For example, a change in bgpd/rfapi would be formatted as:::
321
322 bgpd: short summary
323
324 The first line should be no longer than 50 characters. Subsequent lines
325 should be wrapped to 72 characters.
326
327 Source file header
328 ------------------
329
330 New files need to have a Copyright header (see `License for
331 contributions <#license-for-contributions>`__ above) added to the file.
332 Preferred form of the header is as follows:
333
334 ::
335
336 /*
337 * Title/Function of file
338 * Copyright (C) YEAR Author’s Name
339 *
340 * This program is free software; you can redistribute it and/or modify it
341 * under the terms of the GNU General Public License as published by the Free
342 * Software Foundation; either version 2 of the License, or (at your option)
343 * any later version.
344 *
345 * This program is distributed in the hope that it will be useful, but WITHOUT
346 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
347 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
348 * more details.
349 *
350 * You should have received a copy of the GNU General Public License along
351 * with this program; see the file COPYING; if not, write to the Free Software
352 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
353 */
354
355 #include <zebra.h>
356
357 Adding copyright claims to existing files
358 -----------------------------------------
359
360 When adding copyright claims for modifications to an existing file,
361 please preface the claim with "Portions: " on a line before it and
362 indent the "Copyright ..." string. If such a case already exists, add
363 your indented claim immediately after. E.g.:
364
365 ::
366
367 Portions:
368 Copyright (C) 2010 Entity A ....
369 Copyright (C) 2016 Your name [optional brief change description]
370
371 Code formatting
372 ---------------
373
374 FRR uses Linux kernel style except where noted below. Code which does
375 not comply with these style guidelines will not be accepted.
376
377 The project provides multiple tools to allow you to correctly style your code
378 as painlessly as possible, primarily built around ``clang-format``.
379
380 clang-format
381 In the project root there is a :file:`.clang-format` configuration file
382 which can be used with the ``clang-format`` source formatter tool from the
383 LLVM project. Most of the time, this is the easiest and smartest tool to
384 use. It can be run in a variety of ways. If you point it at a C source file
385 or directory of source files, it will format all of them. In the LLVM source
386 tree there are scripts that allow you to integrate it with ``git``, ``vim``
387 and ``emacs``, and there are third-party plugins for other editors. The
388 ``git`` integration is particularly useful; suppose you have some changes in
389 your git index. Then, with the integration installed, you can do the
390 following:
391
392 ::
393
394 git clang-format
395
396 This will format *only* the changes present in your index. If you have just
397 made a few commits and would like to correctly style only the changes made
398 in those commits, you can use the following syntax:
399
400 ::
401
402 git clang-format HEAD~X
403
404 Where X is one more than the number of commits back from the tip of your
405 branch you would like ``clang-format`` to look at (similar to specifying the
406 target for a rebase).
407
408 The ``vim`` plugin is particularly useful. It allows you to select lines in
409 visual line mode and press a key binding to invoke ``clang-format`` on only
410 those lines.
411
412 When using ``clang-format``, it is recommended to use the latest version.
413 Each consecutive version generally has better handling of various edge
414 cases. You may notice on occasion that two consecutive runs of
415 ``clang-format`` over the same code may result in changes being made on the
416 second run. This is an unfortunate artifact of the tool. Please check with
417 the kernel style guide if in doubt.
418
419 One stylistic problem with the FRR codebase is the use of ``DEFUN`` macros
420 for defining CLI commands. ``clang-format`` will happily format these macro
421 invocations, but the result is often unsightly and difficult to read.
422 Consequently, FRR takes a more relaxed position with how these are
423 formatted. In general you should lean towards using the style exemplified in
424 the section on :ref:`command-line-interface`. Because ``clang-format``
425 mangles this style, there is a Python script named ``tools/indent.py`` that
426 wraps ``clang-format`` and handles ``DEFUN`` macros as well as some other
427 edge cases specific to FRR. If you are submitting a new file, it is
428 recommended to run that script over the new file, preferably after ensuring
429 that the latest stable release of ``clang-format`` is in your ``PATH``.
430
431 Documentation on ``clang-format`` and its various integrations is maintained
432 on the LLVM website.
433
434 https://clang.llvm.org/docs/ClangFormat.html
435
436 checkpatch.sh
437 In the Linux kernel source tree there is a Perl script used to check
438 incoming patches for style errors. FRR uses an adapted version of this
439 script for the same purpose. It can be found at
440 :file:`tools/checkpatch.sh`. This script takes a git-formatted diff or
441 patch file, applies it to a clean FRR tree, and inspects the result to catch
442 potential style errors. Running this script on your patches before
443 submission is highly recommended. The CI system runs this script as well and
444 will comment on the PR with the results if style errors are found.
445
446 It is run like this:
447
448 ::
449
450 checkpatch.sh <patch> <tree>
451
452 Reports are generated on ``stderr`` and the exit code indicates whether
453 issues were found (2, 1) or not (0).
454
455 Where ``<patch>`` is the path to the diff or patch file and ``<tree>`` is
456 the path to your FRR source tree. The tree should be on the branch that you
457 intend to submit the patch against. The script will make a best-effort
458 attempt to save the state of your working tree and index before applying the
459 patch, and to restore it when it is done, but it is still recommended that
460 you have a clean working tree as the script does perform a hard reset on
461 your tree during its run.
462
463 The script reports two classes of issues, namely WARNINGs and ERRORs. Please
464 pay attention to both of them. The script will generally report WARNINGs
465 where it cannot be 100% sure that a particular issue is real. In most cases
466 WARNINGs indicate an issue that needs to be fixed. Sometimes the script will
467 report false positives; these will be handled in code review on a
468 case-by-case basis. Since the script only looks at changed lines,
469 occasionally changing one part of a line can cause the script to report a
470 style issue already present on that line that is unrelated to the change.
471 When convenient it is preferred that these be cleaned up inline, but this is
472 not required.
473
474 If the script finds one or more WARNINGs it will exit with 1. If it finds
475 one or more ERRORs it will exit with 2.
476
477
478 Please remember that while FRR provides these tools for your convenience,
479 responsibility for properly formatting your code ultimately lies on the
480 shoulders of the submitter. As such, it is recommended to double-check the
481 results of these tools to avoid delays in merging your submission.
482
483 **Whitespace changes in untouched parts of the code are not acceptable
484 in patches that change actual code.** To change/fix formatting issues,
485 please create a separate patch that only does formatting changes and
486 nothing else.
487
488 Kernel and BSD styles are documented externally:
489
490 - https://www.kernel.org/doc/html/latest/process/coding-style.html
491 - http://man.openbsd.org/style
492
493 For GNU coding style, use ``indent`` with the following invocation:
494
495 ::
496
497 indent -nut -nfc1 file_for_submission.c
498
499
500 Historically, FRR used fixed-width integral types that do not exist in any
501 standard but were defined by most platforms at some point. Officially these
502 types are not guaranteed to exist. Therefore, please use the fixed-width
503 integral types introduced in the C99 standard when contributing new code to
504 FRR. If you need to convert a large amount of code to use the correct types,
505 there is a shell script in :file:`tools/convert-fixedwidth.sh` that will do the
506 necessary replacements.
507
508 +-----------+--------------------------+
509 | Incorrect | Correct |
510 +===========+==========================+
511 | u_int8_t | uint8_t |
512 +-----------+--------------------------+
513 | u_int16_t | uint16_t |
514 +-----------+--------------------------+
515 | u_int32_t | uint32_t |
516 +-----------+--------------------------+
517 | u_int64_t | uint64_t |
518 +-----------+--------------------------+
519 | u_char | uint8_t or unsigned char |
520 +-----------+--------------------------+
521 | u_short | unsigned short |
522 +-----------+--------------------------+
523 | u_int | unsigned int |
524 +-----------+--------------------------+
525 | u_long | unsigned long |
526 +-----------+--------------------------+
527
528 Exceptions
529 ^^^^^^^^^^
530
531 FRR project code comes from a variety of sources, so there are some
532 stylistic exceptions in place. They are organized here by branch.
533
534 For ``master``
535 """"""""""""""
536
537 BSD coding style applies to:
538
539 - ``ldpd/``
540
541 ``babeld`` uses, approximately, the following style:
542
543 - K&R style braces
544 - Indents are 4 spaces
545 - Function return types are on their own line
546
547 For ``stable/3.0`` and ``stable/2.0``
548 """""""""""""""""""""""""""""""""""""
549
550 GNU coding style apply to the following parts:
551
552 - ``lib/``
553 - ``zebra/``
554 - ``bgpd/``
555 - ``ospfd/``
556 - ``ospf6d/``
557 - ``isisd/``
558 - ``ripd/``
559 - ``ripngd/``
560 - ``vtysh/``
561
562 BSD coding style applies to:
563
564 - ``ldpd/``
565
566 Compile-time conditional code
567 -----------------------------
568
569 Many users access FRR via binary packages from 3rd party sources;
570 compile-time code puts inclusion/exclusion in the hands of the package
571 maintainer. Please think very carefully before making code conditional
572 at compile time, as it increases regression testing, maintenance
573 burdens, and user confusion. In particular, please avoid gratuitous
574 ``--enable-…`` switches to the configure script - in general, code
575 should be of high quality and in working condition, or it shouldn’t be
576 in FRR at all.
577
578 When code must be compile-time conditional, try have the compiler make
579 it conditional rather than the C pre-processor so that it will still be
580 checked by the compiler, even if disabled. For example,
581
582 ::
583
584 if (SOME_SYMBOL)
585 frobnicate();
586
587 is preferred to
588
589 ::
590
591 #ifdef SOME_SYMBOL
592 frobnicate ();
593 #endif /* SOME_SYMBOL */
594
595 Note that the former approach requires ensuring that ``SOME_SYMBOL``
596 will be defined (watch your ``AC_DEFINE``\ s).
597
598 Debug-guards in code
599 --------------------
600
601 Debugging statements are an important methodology to allow developers to
602 fix issues found in the code after it has been released. The caveat here
603 is that the developer must remember that people will be using the code
604 at scale and in ways that can be unexpected for the original
605 implementor. As such debugs **MUST** be guarded in such a way that they
606 can be turned off. FRR has the ability to turn on/off debugs from the
607 CLI and it is expected that the developer will use this convention to
608 allow control of their debugs.
609
610 Static Analysis and Sanitizers
611 ------------------------------
612 Clang/LLVM comes with a variety of tools that can be used to help find bugs in FRR.
613
614 clang-analyze
615 This is a static analyzer that scans the source code looking for patterns
616 that are likely to be bugs. The tool is run automatically on pull requests
617 as part of CI and new static analysis warnings will be placed in the CI
618 results. FRR aims for absolutely zero static analysis errors. While the
619 project is not quite there, code that introduces new static analysis errors
620 is very unlikely to be merged.
621
622 AddressSanitizer
623 This is an excellent tool that provides runtime instrumentation for
624 detecting memory errors. As part of CI FRR is built with this
625 instrumentation and run through a series of tests to look for any results.
626 Testing your own code with this tool before submission is encouraged. You
627 can enable it by passing::
628
629 --enable-address-sanitizer
630
631 to ``configure``.
632
633 ThreadSanitizer
634 Similar to AddressSanitizer, this tool provides runtime instrumentation for
635 detecting data races. If you are working on or around multithreaded code,
636 extensive testing with this instrumtation enabled is *highly* recommended.
637 You can enable it by passing::
638
639 --enable-thread-sanitizer
640
641 to ``configure``.
642
643 MemorySanitizer
644 Similar to AddressSanitizer, this tool provides runtime instrumentation for
645 detecting use of uninitialized heap memory. Testing your own code with this
646 tool before submission is encouraged. You can enable it by passing::
647
648 --enable-memory-sanitizer
649
650 to ``configure``.
651
652 All of the above tools are available in the Clang/LLVM toolchain since 3.4.
653 AddressSanitizer and ThreadSanitizer are available in recent versions of GCC,
654 but are no longer actively maintained. MemorySanitizer is not available in GCC.
655
656 Additionally, the FRR codebase is regularly scanned with Coverity.
657 Unfortunately Coverity does not have the ability to handle scanning pull
658 requests, but after code is merged it will send an email notifying project
659 members with Coverity access of newly introduced defects.
660
661 CLI changes
662 -----------
663
664 CLI's are a complicated ugly beast. Additions or changes to the CLI
665 should use a DEFUN to encapsulate one setting as much as is possible.
666 Additionally as new DEFUN's are added to the system, documentation
667 should be provided for the new commands.
668
669 Backwards Compatibility
670 -----------------------
671
672 As a general principle, changes to CLI and code in the lib/ directory
673 should be made in a backwards compatible fashion. This means that
674 changes that are purely stylistic in nature should be avoided, e.g.,
675 renaming an existing macro or library function name without any
676 functional change. When adding new parameters to common functions, it is
677 also good to consider if this too should be done in a backward
678 compatible fashion, e.g., by preserving the old form in addition to
679 adding the new form.
680
681 This is not to say that minor or even major functional changes to CLI
682 and common code should be avoided, but rather that the benefit gained
683 from a change should be weighed against the added cost/complexity to
684 existing code. Also, that when making such changes, it is good to
685 preserve compatibility when possible to do so without introducing
686 maintenance overhead/cost. It is also important to keep in mind,
687 existing code includes code that may reside in private repositories (and
688 is yet to be submitted) or code that has yet to be migrated from Quagga
689 to FRR.
690
691 That said, compatibility measures can (and should) be removed when
692 either:
693
694 - they become a significant burden, e.g. when data structures change
695 and the compatibility measure would need a complex adaptation layer
696 or becomes flat-out impossible
697 - some measure of time (dependent on the specific case) has passed, so
698 that the compatibility grace period is considered expired.
699
700 In all cases, compatibility pieces should be marked with
701 compiler/preprocessor annotations to print warnings at compile time,
702 pointing to the appropriate update path. A ``-Werror`` build should fail
703 if compatibility bits are used.
704
705 Preferably, the shell script :file:`tools/fixup-deprecated.py` will be
706 updated along with making non-backwards compatible code changes, or an
707 alternate script should be introduced, to update the code to match the
708 change. When the script is updated, there is no need to preserve the
709 deprecated code. Note that this does not apply to user interface
710 changes, just internal code, macros and libraries.
711
712 Miscellaneous
713 -------------
714
715 When in doubt, follow the guidelines in the Linux kernel style guide, or
716 ask on the development mailing list / public Slack instance.
717
718
719 .. _documentation:
720
721 Documentation
722 =============
723
724 FRR uses Sphinx+RST as its documentation system. The document you are currently
725 reading was generated by Sphinx from RST source in
726 :file:`doc/developer/workflow.rst`. The documentation is structured as follows:
727
728 +-----------------------+--------------------------------------------------------------+
729 | Directory | Contents |
730 +=======================+==============================================================+
731 | :file:`doc/user` | User documentation; configuration guides; protocol overviews |
732 +-----------------------+--------------------------------------------------------------+
733 | :file:`doc/developer` | Developer's documentation; API specs; datastructures; |
734 | | architecture overviews; project management procedure |
735 +-----------------------+--------------------------------------------------------------+
736 | :file:`doc/manpages` | Source for manpages |
737 +-----------------------+--------------------------------------------------------------+
738 | :file:`doc/figures` | Images and diagrams |
739 +-----------------------+--------------------------------------------------------------+
740
741 Each of these directories, with the exception of :file:`doc/figures`, contains
742 a Sphinx-generated Makefile and configuration script :file:`conf.py` used to
743 set various document parameters. The makefile can be used for a variety of
744 targets; invoke `make help` in any of these directories for a listing of
745 available output formats. For convenience, there is a top-level
746 :file:`Makefile.am` that has targets for PDF and HTML documentation for both
747 developer and user documentation, respectively. That makefile is also
748 responsible for building manual pages packed with distribution builds.
749
750 Indent and styling should follow existing conventions:
751
752 - 3 spaces for indents under directives
753 - Cross references may contain only lowercase alphanumeric characters and
754 hyphens ('-')
755 - Lines wrapped to 80 characters where possible
756
757 Characters for header levels should follow Python documentation guide:
758
759 - ``#`` with overline, for parts
760 - ``*`` with overline, for chapters
761 - ``=``, for sections
762 - ``-``, for subsections
763 - ``^``, for subsubsections
764 - ``"``, for paragraphs
765
766 After you have made your changes, please make sure that you can invoke
767 ``make latexpdf`` and ``make html`` with no warnings.
768
769 The documentation is currently incomplete and needs love. If you find a broken
770 cross-reference, figure, dead hyperlink, style issue or any other nastiness we
771 gladly accept documentation patches.
772
773 To build the docs, please ensure you have installed a recent version of
774 `Sphinx <http://www.sphinx-doc.org/en/stable/install.html>`_. If you want to
775 build LaTeX or PDF docs, you will also need a full LaTeX distribution
776 installed.
777
778 Code
779 ----
780
781 FRR is a large and complex software project developed by many different people
782 over a long period of time. Without adequate documentation, it can be
783 exceedingly difficult to understand code segments, APIs and other interfaces.
784 In the interest of keeping the project healthy and maintainable, you should
785 make every effort to document your code so that other people can understand
786 what it does without needing to closely read the code itself.
787
788 Some specific guidelines that contributors should follow are:
789
790 - Functions exposed in header files should have descriptive comments above
791 their signatures in the header file. At a minimum, a function comment should
792 contain information about the return value, parameters, and a general summary
793 of the function's purpose. Documentation on parameter values can be omitted
794 if it is (very) obvious what they are used for.
795
796 Function comments must follow the style for multiline comments laid out in
797 the kernel style guide.
798
799 Example:
800
801 .. code-block:: c
802
803 /*
804 * Determines whether or not a string is cool.
805 *
806 * @param text - the string to check for coolness
807 * @param is_clccfc - whether capslock is cruise control for cool
808 * @return 7 if the text is cool, 0 otherwise
809 */
810 int check_coolness(const char *text, bool is_clccfc);
811
812 The Javadoc-style annotations are not required, but you should still strive
813 to make it equally clear what parameters and return values are used for.
814
815 - Static functions should have descriptive comments in the same form as above
816 if what they do is not immediately obvious. Use good engineering judgement
817 when deciding whether a comment is necessary. If you are unsure, document
818 your code.
819 - Global variables, static or not, should have a comment describing their use.
820 - **For new code in lib/, these guidelines are hard requirements.**
821
822 If you make significant changes to portions of the codebase covered in the
823 Developer's Manual, add a major subsystem or feature, or gain arcane mastery of
824 some undocumented or poorly documented part of the codebase, please document
825 your work so others can benefit. If you add a major feature or introduce a new
826 API, please document the architecture and API to the best of your abilities in
827 the Developer's Manual, using good judgement when choosing where to place it.
828
829 Finally, if you come across some code that is undocumented and feel like
830 going above and beyond, document it! We absolutely appreciate and accept
831 patches that document previously undocumented code.
832
833 User
834 ----
835
836 If you are contributing code that adds significant user-visible functionality
837 please document how to use it in :file:`doc/user`. Use good judgement when
838 choosing where to place documentation. For example, instructions on how to use
839 your implementation of a new BGP draft should go in the BGP chapter instead of
840 being its own chapter. If you are adding a new protocol daemon, please create a
841 new chapter.
842
843 When documenting CLI please use a combination of the ``.. index::`` and
844 ``.. clicmd::`` directives. For example, the command :clicmd:`show pony` would
845 be documented as follows:
846
847 .. code-block:: rest
848
849 .. index:: show pony
850 .. clicmd:: show pony
851
852 Prints an ASCII pony. Example output:::
853
854 >>\.
855 /_ )`.
856 / _)`^)`. _.---. _
857 (_,' \ `^-)"" `.\
858 | | \
859 \ / |
860 / \ /.___.'\ (\ (_
861 < ,"|| \ |`. \`-'
862 \\ () )| )/
863 hjw |_>|> /_] //
864 /_] /_]
865
866 When documented this way, CLI commands can be cross referenced with the
867 ``:clicmd:`` inline markup like so:
868
869 .. code-block:: rest
870
871 :clicmd:`show pony`
872
873 This is very helpful for users who want to quickly remind themselves what a
874 particular command does.
875
876 .. _GitHub: https://github.com/frrouting/frr
877 .. _GitHub issues: https://github.com/frrouting/frr/issues