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