]> git.proxmox.com Git - mirror_frr.git/blame - doc/developer/workflow.rst
Merge pull request #1946 from qlyoung/asan-configure-option
[mirror_frr.git] / doc / developer / workflow.rst
CommitLineData
9de103f0
QY
1.. _process-and-workflow:
2
3*******************
b22ba015 4Process & Workflow
9de103f0 5*******************
d1890d04 6
b22ba015
QY
7FRR is a large project developed by many different groups. This section
8documents standards for code style & quality, commit messages, pull requests
9and best practices that all contributors are asked to follow.
d1890d04 10
9de103f0
QY
11This chapter is "descriptive/post-factual" in that it documents pratices that
12are in use; it is not "definitive/pre-factual" in prescribing practices. This
b22ba015
QY
13means that when a procedure changes, it is agreed upon, then put into practice,
14and then documented here. If this document doesn't match reality, it's the
15document that needs to be updated, not reality.
d1890d04 16
9de103f0
QY
17Mailing Lists
18=============
d1890d04 19
b22ba015
QY
20The FRR development group maintains multiple mailing lists for use by the
21community. Italicized lists are private.
d1890d04
QY
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
9de103f0
QY
37The Development list is used to discuss and document general issues related to
38project development and governance. The public Slack instance,
39frrouting.slack.com, and weekly technical meetings provide a higher bandwidth
40channel for discussions. The results of such discussions must be reflected in
41updates, as appropriate, to code (i.e., merges), `Github issues`_, and for
42governance or process changes, updates to the Development list and either this
43file or information posted at https://frrouting.org/.
8ce7861f 44
c804874a
QY
45Release Process & Schedule
46==========================
47
48FRR employs a <MAJOR>.<MINOR>.<BUGFIX> versioning scheme.
49
50MAJOR
51 Significant new features or multiple minor features. The addition of a new
52 routing protocol or daemon would fall under this class.
53
54MINOR
55 Small features, e.g. options for automatic BGP shutdown.
56
57BUGFIX
58 Fixes for actual bugs and/or security issues.
59
60We will pull a new development branch for the next release every 4 months. The
61current schedule is Feb/June/October 1. The decision for a MAJOR/MINOR release
62is made at the time of branch pull based on what has been received the previous
634 months. The branch name will be dev/MAJOR.MINOR. At this point in time the
64master branch, :file:`configure.ac`, documentation and packaging systems will
65be updated to reflect the next possible release name to allow for easy
66distinguishing. Additionally the new dev branch will have these files updated
67too.
68
69After one month the development branch will be renamed to stable/MAJOR.MINOR.
70This process is not held up unless a crash or security issue has been found and
71needs to be addressed. Issues being fixed will not cause a delay.
72
73Bugfix releases are made as needed at 1 month intervals until the next
74MAJOR.MINOR relese branch is pulled. Depending on the severity of the bugs,
75bugfix releases may occur sooner.
76
77Bugfixes are applied to the two most recent releases. Security fixes are
78backported to all releases less than or equal to one year old. Security fixes
79may also be backported to older releases depending on severity.
8ce7861f 80
d1890d04 81Changelog
9de103f0 82=========
d1890d04 83
b22ba015
QY
84The changelog will be the base for the release notes. A changelog entry for
85your changes is usually not required and will be added based on your commit
86messages by the maintainers. However, you are free to include an update to the
87changelog with some better description.
d1890d04
QY
88
89Submitting Patches and Enhancements
9de103f0 90===================================
d1890d04 91
b22ba015
QY
92FRR accepts patches from two sources:
93
94- Email (git format-patch)
95- Github pull request
96
97Contributors are highly encouraged to use Github's fork-and-pr workflow. It is
98easier for us to review it, test it, try it and discuss it on Github than it is
99via email, thus your patch will get more attention more quickly on Github.
100
101The 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
103submit it.
104
d1890d04 105Pre-submission Checklist
9de103f0 106------------------------
d1890d04 107
b22ba015 108- Format code (see `Code Formatting <#developers-guidelines>`__)
d1890d04
QY
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
128License for contributions
9de103f0 129-------------------------
d1890d04 130
b22ba015 131FRR is under a “GPLv2 or later” license. Any code submitted must
d1890d04
QY
132be released under the same license (preferred) or any license which
133allows redistribution under this GPLv2 license (eg MIT License).
134
135Signing Off
9de103f0 136-----------
d1890d04 137
b22ba015 138Code submitted to FRR must be signed off. We have the same
d1890d04
QY
139requirements for using the signed-off-by process as the Linux kernel. In
140short, 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
143has the right to submit the patch for inclusion into the project. It is
144an agreement to the Developer's Certificate of Origin (below). Code
145without a proper signoff can not and will not be merged.
146
147If you are unfamiliar with this process, you should read the `official
148policy at
149kernel.org <https://www.kernel.org/doc/html/latest/process/submitting-patches.html>`__
150and you might find this article about `participating in the Linux
151community on the Linux Foundation
152website <http://www.linuxfoundation.org/content/how-participate-linux-community-0>`__
153to be a helpful resource.
154
155In short, when you sign off on a commit, you assert your agreement to
156all of the following:
157
b22ba015
QY
158::
159
d1890d04
QY
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
184What do I submit my changes against?
9de103f0 185------------------------------------
d1890d04
QY
186
187We've documented where we would like to have the different fixes applied
188at
b22ba015 189https://github.com/FRR/frr/wiki/Where-Do-I-create-a-Pull-Request-against%3F
d1890d04
QY
190If you are unsure where your submission goes, look at that document or
191ask a project maintainer.
192
193Github pull requests
9de103f0 194--------------------
d1890d04
QY
195
196The preferred method of submitting changes is a Github pull request.
197Code submitted by pull request will be automatically tested by one or
198more CI systems. Once the automated tests succeed, other developers will
199review your code for quality and correctness. After any concerns are
200resolved, your code will be merged into the branch it was submitted
201against.
202
203Patch submission via mailing list
9de103f0 204---------------------------------
d1890d04
QY
205
206As an alternative submission method, a patch can be mailed to the
207development mailing list. Patches received on the mailing list will be
208picked up by Patchwork and tested against the latest development branch.
209
210The recommended way to send the patch (or series of NN patches) to the
211list is by using ``git send-email`` as follows (assuming they are the N
212most recent commit(s) in your git history:
213
214::
215
216 git send-email -NN --annotate --to=dev@lists.frrouting.org
217
218If your commits do not already contain a ``Signed-off-by`` line, then
219use the following command to add it (after making sure you agree to the
220Developer Certificate of Origin as outlined above):
221
222::
223
224 git send-email -NN --annotate --signoff --to=dev@lists.frrouting.org
225
226Submitting multi-commit patches as a Github pull request is **strongly
227encouraged** and increases the probability of your patch getting
228reviewed and merged in a timely manner.
229
230After 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
b22ba015 237 email, then check status on the Github pull request.
d1890d04 238 - Please notify the development mailing list if you think something
b22ba015 239 doesn't work.
d1890d04
QY
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
9de103f0
QY
268Git 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
278The master Git for FRR resides on `GitHub`_.
279
280There 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
282point releases based on a major branch are marked by tagging.
283
284Programming Languages, Tools and Libraries
285==========================================
286
287The core of FRR is written in C (gcc or clang supported) and makes
288use of GNU compiler extensions. A few non-essential scripts are
289implemented in Perl and Python. FRR requires the following tools
290to build distribution packages: automake, autoconf, texinfo, libtool and
291gawk and various libraries (i.e. libpam and libjson-c).
292
293If your contribution requires a new library or other tool, then please
294highlight this in your description of the change. Also make sure it’s
295supported by all FRR platform OSes or provide a way to build
296without the library (potentially without the new feature) on the other
297platforms.
298
299Documentation should be written in reStructuredText. Sphinx extensions may be
300utilized but pure ReST is preferred where possible. See
301:ref:`documentation`.
302
303
b22ba015 304Coding Practices & Style
9de103f0 305========================
d1890d04
QY
306
307Commit messages
9de103f0 308---------------
d1890d04
QY
309
310Commit messages should be formatted in the same way as Linux kernel
311commit 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
9de103f0 320was made. For example, a change in bgpd/rfapi would be formatted as:::
d1890d04 321
9de103f0 322 bgpd: short summary
d1890d04
QY
323
324The first line should be no longer than 50 characters. Subsequent lines
325should be wrapped to 72 characters.
326
327Source file header
9de103f0 328------------------
d1890d04
QY
329
330New files need to have a Copyright header (see `License for
331contributions <#license-for-contributions>`__ above) added to the file.
332Preferred 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
357Adding copyright claims to existing files
9de103f0 358-----------------------------------------
d1890d04
QY
359
360When adding copyright claims for modifications to an existing file,
361please preface the claim with "Portions: " on a line before it and
362indent the "Copyright ..." string. If such a case already exists, add
363your 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
371Code formatting
9de103f0 372---------------
d1890d04
QY
373
374FRR uses Linux kernel style except where noted below. Code which does
375not comply with these style guidelines will not be accepted.
376
281ba953
QY
377The project provides multiple tools to allow you to correctly style your code
378as painlessly as possible, primarily built around ``clang-format``.
379
380clang-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
436checkpatch.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
2780ae0c 440 :file:`tools/checkpatch.sh`. This script takes a git-formatted diff or
281ba953
QY
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
478Please remember that while FRR provides these tools for your convenience,
479responsibility for properly formatting your code ultimately lies on the
480shoulders of the submitter. As such, it is recommended to double-check the
481results of these tools to avoid delays in merging your submission.
d1890d04
QY
482
483**Whitespace changes in untouched parts of the code are not acceptable
484in patches that change actual code.** To change/fix formatting issues,
485please create a separate patch that only does formatting changes and
486nothing else.
487
d1890d04
QY
488Kernel 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
493For GNU coding style, use ``indent`` with the following invocation:
494
495::
496
497 indent -nut -nfc1 file_for_submission.c
498
499Exceptions
500^^^^^^^^^^
501
502FRR project code comes from a variety of sources, so there are some
503stylistic exceptions in place. They are organized here by branch.
504
9de103f0
QY
505For ``master``
506""""""""""""""
d1890d04
QY
507
508BSD coding style applies to:
509
510- ``ldpd/``
511
512``babeld`` uses, approximately, the following style:
513
514- K&R style braces
515- Indents are 4 spaces
516- Function return types are on their own line
517
9de103f0
QY
518For ``stable/3.0`` and ``stable/2.0``
519"""""""""""""""""""""""""""""""""""""
d1890d04
QY
520
521GNU coding style apply to the following parts:
522
523- ``lib/``
524- ``zebra/``
525- ``bgpd/``
526- ``ospfd/``
527- ``ospf6d/``
528- ``isisd/``
529- ``ripd/``
530- ``ripngd/``
531- ``vtysh/``
532
533BSD coding style applies to:
534
535- ``ldpd/``
536
d1890d04 537Compile-time conditional code
9de103f0 538-----------------------------
d1890d04
QY
539
540Many users access FRR via binary packages from 3rd party sources;
541compile-time code puts inclusion/exclusion in the hands of the package
542maintainer. Please think very carefully before making code conditional
543at compile time, as it increases regression testing, maintenance
544burdens, and user confusion. In particular, please avoid gratuitous
545``--enable-…`` switches to the configure script - in general, code
546should be of high quality and in working condition, or it shouldn’t be
547in FRR at all.
548
549When code must be compile-time conditional, try have the compiler make
550it conditional rather than the C pre-processor so that it will still be
551checked by the compiler, even if disabled. For example,
552
553::
554
555 if (SOME_SYMBOL)
556 frobnicate();
557
558is preferred to
559
560::
561
562 #ifdef SOME_SYMBOL
563 frobnicate ();
564 #endif /* SOME_SYMBOL */
565
566Note that the former approach requires ensuring that ``SOME_SYMBOL``
567will be defined (watch your ``AC_DEFINE``\ s).
568
569Debug-guards in code
9de103f0 570--------------------
d1890d04
QY
571
572Debugging statements are an important methodology to allow developers to
573fix issues found in the code after it has been released. The caveat here
574is that the developer must remember that people will be using the code
575at scale and in ways that can be unexpected for the original
576implementor. As such debugs **MUST** be guarded in such a way that they
577can be turned off. FRR has the ability to turn on/off debugs from the
578CLI and it is expected that the developer will use this convention to
579allow control of their debugs.
580
9e001286
QY
581Static Analysis and Sanitizers
582------------------------------
583Clang/LLVM comes with a variety of tools that can be used to help find bugs in FRR.
584
585clang-analyze
586 This is a static analyzer that scans the source code looking for patterns
587 that are likely to be bugs. The tool is run automatically on pull requests
588 as part of CI and new static analysis warnings will be placed in the CI
589 results. FRR aims for absolutely zero static analysis errors. While the
590 project is not quite there, code that introduces new static analysis errors
591 is very unlikely to be merged.
592
593AddressSanitizer
594 This is an excellent tool that provides runtime instrumentation for
595 detecting memory errors. As part of CI FRR is built with this
596 instrumentation and run through a series of tests to look for any results.
597 Testing your own code with this tool before submission is encouraged. You
598 can enable it by passing::
599
600 --enable-address-sanitizer
601
602 to ``configure``.
603
604ThreadSanitizer
605 Similar to AddressSanitizer, this tool provides runtime instrumentation for
606 detecting data races. If you are working on or around multithreaded code,
607 extensive testing with this instrumtation enabled is *highly* recommended.
608 You can enable it by passing::
609
610 --enable-thread-sanitizer
611
612 to ``configure``.
613
614MemorySanitizer
615 Similar to AddressSanitizer, this tool provides runtime instrumentation for
616 detecting use of uninitialized heap memory. Testing your own code with this
617 tool before submission is encouraged. You can enable it by passing::
618
619 --enable-memory-sanitizer
620
621 to ``configure``.
622
623All of the above tools are available in the Clang/LLVM toolchain since 3.4.
624AddressSanitizer and ThreadSanitizer are available in recent versions of GCC,
625but are no longer actively maintained. MemorySanitizer is not available in GCC.
626
627Additionally, the FRR codebase is regularly scanned with Coverity.
628Unfortunately Coverity does not have the ability to handle scanning pull
629requests, but after code is merged it will send an email notifying project
630members with Coverity access of newly introduced defects.
631
d1890d04 632CLI changes
9de103f0 633-----------
d1890d04
QY
634
635CLI's are a complicated ugly beast. Additions or changes to the CLI
636should use a DEFUN to encapsulate one setting as much as is possible.
637Additionally as new DEFUN's are added to the system, documentation
638should be provided for the new commands.
639
640Backwards Compatibility
9de103f0 641-----------------------
d1890d04
QY
642
643As a general principle, changes to CLI and code in the lib/ directory
644should be made in a backwards compatible fashion. This means that
645changes that are purely stylistic in nature should be avoided, e.g.,
646renaming an existing macro or library function name without any
647functional change. When adding new parameters to common functions, it is
648also good to consider if this too should be done in a backward
649compatible fashion, e.g., by preserving the old form in addition to
650adding the new form.
651
652This is not to say that minor or even major functional changes to CLI
653and common code should be avoided, but rather that the benefit gained
654from a change should be weighed against the added cost/complexity to
655existing code. Also, that when making such changes, it is good to
656preserve compatibility when possible to do so without introducing
657maintenance overhead/cost. It is also important to keep in mind,
658existing code includes code that may reside in private repositories (and
659is yet to be submitted) or code that has yet to be migrated from Quagga
660to FRR.
661
662That said, compatibility measures can (and should) be removed when
663either:
664
665- they become a significant burden, e.g. when data structures change
666 and the compatibility measure would need a complex adaptation layer
667 or becomes flat-out impossible
668- some measure of time (dependent on the specific case) has passed, so
669 that the compatibility grace period is considered expired.
670
671In all cases, compatibility pieces should be marked with
672compiler/preprocessor annotations to print warnings at compile time,
673pointing to the appropriate update path. A ``-Werror`` build should fail
674if compatibility bits are used.
675
676Miscellaneous
9de103f0 677-------------
d1890d04
QY
678
679When in doubt, follow the guidelines in the Linux kernel style guide, or
680ask on the development mailing list / public Slack instance.
9de103f0
QY
681
682
683.. _documentation:
684
685Documentation
686=============
687
688FRR uses Sphinx+RST as its documentation system. The document you are currently
689reading was generated by Sphinx from RST source in
690:file:`doc/developer/workflow.rst`. The documentation is structured as follows:
691
692+-----------------------+--------------------------------------------------------------+
693| Directory | Contents |
694+=======================+==============================================================+
695| :file:`doc/user` | User documentation; configuration guides; protocol overviews |
696+-----------------------+--------------------------------------------------------------+
697| :file:`doc/developer` | Developer's documentation; API specs; datastructures; |
698| | architecture overviews; project management procedure |
699+-----------------------+--------------------------------------------------------------+
700| :file:`doc/manpages` | Source for manpages |
701+-----------------------+--------------------------------------------------------------+
702| :file:`doc/figures` | Images and diagrams |
703+-----------------------+--------------------------------------------------------------+
704
705Each of these directories, with the exception of :file:`doc/figures`, contains
706a Sphinx-generated Makefile and configuration script :file:`conf.py` used to
707set various document parameters. The makefile can be used for a variety of
708targets; invoke `make help` in any of these directories for a listing of
709available output formats. For convenience, there is a top-level
710:file:`Makefile.am` that has targets for PDF and HTML documentation for both
711developer and user documentation, respectively. That makefile is also
712responsible for building manual pages packed with distribution builds.
713
714Indent and styling should follow existing conventions:
715
716- 3 spaces for indents under directives
717- Cross references may contain only lowercase alphanumeric characters and
718 hyphens ('-')
719- Lines wrapped to 80 characters where possible
720
721Characters for header levels should follow Python documentation guide:
722
723- ``#`` with overline, for parts
724- ``*`` with overline, for chapters
725- ``=``, for sections
726- ``-``, for subsections
727- ``^``, for subsubsections
728- ``"``, for paragraphs
729
730After you have made your changes, please make sure that you can invoke
731``make latexpdf`` and ``make html`` with no warnings.
732
733The documentation is currently incomplete and needs love. If you find a broken
734cross-reference, figure, dead hyperlink, style issue or any other nastiness we
735gladly accept documentation patches.
736
c91e9b8f
QY
737To build the docs, please ensure you have installed a recent version of
738`Sphinx <http://www.sphinx-doc.org/en/stable/install.html>`_. If you want to
739build LaTeX or PDF docs, you will also need a full LaTeX distribution
740installed.
741
9de103f0
QY
742Code
743----
744
745FRR is a large and complex software project developed by many different people
746over a long period of time. Without adequate documentation, it can be
747exceedingly difficult to understand code segments, APIs and other interfaces.
748In the interest of keeping the project healthy and maintainable, you should
749make every effort to document your code so that other people can understand
750what it does without needing to closely read the code itself.
751
752Some specific guidelines that contributors should follow are:
753
754- Functions exposed in header files should have descriptive comments above
755 their signatures in the header file. At a minimum, a function comment should
756 contain information about the return value, parameters, and a general summary
757 of the function's purpose. Documentation on parameter values can be omitted
758 if it is (very) obvious what they are used for.
759
760 Function comments must follow the style for multiline comments laid out in
761 the kernel style guide.
762
763 Example:
764
765 .. code-block:: c
766
767 /*
768 * Determines whether or not a string is cool.
769 *
770 * @param text - the string to check for coolness
771 * @param is_clccfc - whether capslock is cruise control for cool
772 * @return 7 if the text is cool, 0 otherwise
773 */
774 int check_coolness(const char *text, bool is_clccfc);
775
776 The Javadoc-style annotations are not required, but you should still strive
777 to make it equally clear what parameters and return values are used for.
778
779- Static functions should have descriptive comments in the same form as above
780 if what they do is not immediately obvious. Use good engineering judgement
781 when deciding whether a comment is necessary. If you are unsure, document
782 your code.
783- Global variables, static or not, should have a comment describing their use.
784- **For new code in lib/, these guidelines are hard requirements.**
785
786If you make significant changes to portions of the codebase covered in the
787Developer's Manual, add a major subsystem or feature, or gain arcane mastery of
788some undocumented or poorly documented part of the codebase, please document
789your work so others can benefit. If you add a major feature or introduce a new
790API, please document the architecture and API to the best of your abilities in
791the Developer's Manual, using good judgement when choosing where to place it.
792
793Finally, if you come across some code that is undocumented and feel like
794going above and beyond, document it! We absolutely appreciate and accept
795patches that document previously undocumented code.
796
797User
798----
799
800If you are contributing code that adds significant user-visible functionality
801please document how to use it in :file:`doc/user`. Use good judgement when
802choosing where to place documentation. For example, instructions on how to use
803your implementation of a new BGP draft should go in the BGP chapter instead of
804being its own chapter. If you are adding a new protocol daemon, please create a
805new chapter.
806
807When documenting CLI please use a combination of the ``.. index::`` and
808``.. clicmd::`` directives. For example, the command :clicmd:`show pony` would
809be documented as follows:
810
811.. code-block:: rest
812
813 .. index:: show pony
814 .. clicmd:: show pony
815
816 Prints an ASCII pony. Example output:::
817
818 >>\.
819 /_ )`.
820 / _)`^)`. _.---. _
821 (_,' \ `^-)"" `.\
822 | | \
823 \ / |
824 / \ /.___.'\ (\ (_
825 < ,"|| \ |`. \`-'
826 \\ () )| )/
827 hjw |_>|> /_] //
828 /_] /_]
829
830When documented this way, CLI commands can be cross referenced with the
831``:clicmd:`` inline markup like so:
832
833.. code-block:: rest
834
835 :clicmd:`show pony`
836
837This is very helpful for users who want to quickly remind themselves what a
838particular command does.
839
840.. _GitHub: https://github.com/frrouting/frr
841.. _GitHub issues: https://github.com/frrouting/frr/issues