]> git.proxmox.com Git - mirror_frr.git/blame - doc/developer/workflow.rst
doc: add comment on PR title and description
[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
338
b22ba015 339Coding Practices & Style
9de103f0 340========================
d1890d04
QY
341
342Commit messages
9de103f0 343---------------
d1890d04
QY
344
345Commit messages should be formatted in the same way as Linux kernel
b6820993 346commit messages. The format is roughly::
d1890d04
QY
347
348 dir: short summary
349
350 extended summary
351
b6820993
QY
352``dir`` should be the top level source directory under which the change was
353made. For example, a change in :file:`bgpd/rfapi` would be formatted as::
d1890d04 354
9de103f0 355 bgpd: short summary
d1890d04 356
b6820993
QY
357 ...
358
359The first line should be no longer than 50 characters. Subsequent lines should
360be wrapped to 72 characters.
d1890d04 361
b6820993
QY
362You must also sign off on your commit.
363
364.. seealso:: :ref:`signing-off`
365
366Source File Header
9de103f0 367------------------
d1890d04 368
b6820993
QY
369New files must have a copyright header (see :ref:`license-for-contributions`
370above) added to the file. The header should be:
d1890d04 371
b6820993 372.. code-block:: c
d1890d04
QY
373
374 /*
375 * Title/Function of file
376 * Copyright (C) YEAR Author’s Name
377 *
378 * This program is free software; you can redistribute it and/or modify it
379 * under the terms of the GNU General Public License as published by the Free
380 * Software Foundation; either version 2 of the License, or (at your option)
381 * any later version.
382 *
383 * This program is distributed in the hope that it will be useful, but WITHOUT
384 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
385 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
386 * more details.
387 *
388 * You should have received a copy of the GNU General Public License along
389 * with this program; see the file COPYING; if not, write to the Free Software
390 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
391 */
392
393 #include <zebra.h>
394
b6820993
QY
395Please copy-paste this header verbatim. In particular:
396
397- Do not replace "This program" with "FRR"
398- Do not change the address of the FSF
399
400Adding Copyright Claims to Existing Files
9de103f0 401-----------------------------------------
d1890d04 402
b6820993
QY
403When adding copyright claims for modifications to an existing file, please
404add a ``Portions:`` section as shown below. If this section already exists, add
405your new claim at the end of the list.
d1890d04 406
b6820993 407.. code-block:: c
d1890d04 408
b6820993
QY
409 /*
410 * Title/Function of file
411 * Copyright (C) YEAR Author’s Name
412 * Portions:
413 * Copyright (C) 2010 Entity A ....
414 * Copyright (C) 2016 Your name [optional brief change description]
415 * ...
416 */
d1890d04 417
c964e511 418Code Formatting
9de103f0 419---------------
d1890d04 420
b6820993
QY
421FRR uses Linux kernel style except where noted below. Code which does not
422comply with these style guidelines will not be accepted.
d1890d04 423
281ba953
QY
424The project provides multiple tools to allow you to correctly style your code
425as painlessly as possible, primarily built around ``clang-format``.
426
427clang-format
428 In the project root there is a :file:`.clang-format` configuration file
429 which can be used with the ``clang-format`` source formatter tool from the
430 LLVM project. Most of the time, this is the easiest and smartest tool to
431 use. It can be run in a variety of ways. If you point it at a C source file
432 or directory of source files, it will format all of them. In the LLVM source
433 tree there are scripts that allow you to integrate it with ``git``, ``vim``
434 and ``emacs``, and there are third-party plugins for other editors. The
435 ``git`` integration is particularly useful; suppose you have some changes in
436 your git index. Then, with the integration installed, you can do the
437 following:
438
439 ::
440
441 git clang-format
442
443 This will format *only* the changes present in your index. If you have just
444 made a few commits and would like to correctly style only the changes made
445 in those commits, you can use the following syntax:
446
447 ::
448
449 git clang-format HEAD~X
450
451 Where X is one more than the number of commits back from the tip of your
452 branch you would like ``clang-format`` to look at (similar to specifying the
453 target for a rebase).
454
455 The ``vim`` plugin is particularly useful. It allows you to select lines in
456 visual line mode and press a key binding to invoke ``clang-format`` on only
457 those lines.
458
459 When using ``clang-format``, it is recommended to use the latest version.
460 Each consecutive version generally has better handling of various edge
461 cases. You may notice on occasion that two consecutive runs of
462 ``clang-format`` over the same code may result in changes being made on the
463 second run. This is an unfortunate artifact of the tool. Please check with
464 the kernel style guide if in doubt.
465
466 One stylistic problem with the FRR codebase is the use of ``DEFUN`` macros
467 for defining CLI commands. ``clang-format`` will happily format these macro
468 invocations, but the result is often unsightly and difficult to read.
469 Consequently, FRR takes a more relaxed position with how these are
470 formatted. In general you should lean towards using the style exemplified in
471 the section on :ref:`command-line-interface`. Because ``clang-format``
472 mangles this style, there is a Python script named ``tools/indent.py`` that
473 wraps ``clang-format`` and handles ``DEFUN`` macros as well as some other
474 edge cases specific to FRR. If you are submitting a new file, it is
475 recommended to run that script over the new file, preferably after ensuring
476 that the latest stable release of ``clang-format`` is in your ``PATH``.
477
478 Documentation on ``clang-format`` and its various integrations is maintained
479 on the LLVM website.
480
481 https://clang.llvm.org/docs/ClangFormat.html
482
483checkpatch.sh
484 In the Linux kernel source tree there is a Perl script used to check
485 incoming patches for style errors. FRR uses an adapted version of this
486 script for the same purpose. It can be found at
2780ae0c 487 :file:`tools/checkpatch.sh`. This script takes a git-formatted diff or
281ba953
QY
488 patch file, applies it to a clean FRR tree, and inspects the result to catch
489 potential style errors. Running this script on your patches before
490 submission is highly recommended. The CI system runs this script as well and
491 will comment on the PR with the results if style errors are found.
492
b6820993 493 It is run like this::
281ba953 494
b6820993 495 ./checkpatch.sh <patch> <tree>
281ba953
QY
496
497 Reports are generated on ``stderr`` and the exit code indicates whether
498 issues were found (2, 1) or not (0).
499
500 Where ``<patch>`` is the path to the diff or patch file and ``<tree>`` is
501 the path to your FRR source tree. The tree should be on the branch that you
502 intend to submit the patch against. The script will make a best-effort
503 attempt to save the state of your working tree and index before applying the
504 patch, and to restore it when it is done, but it is still recommended that
505 you have a clean working tree as the script does perform a hard reset on
506 your tree during its run.
507
508 The script reports two classes of issues, namely WARNINGs and ERRORs. Please
509 pay attention to both of them. The script will generally report WARNINGs
510 where it cannot be 100% sure that a particular issue is real. In most cases
511 WARNINGs indicate an issue that needs to be fixed. Sometimes the script will
512 report false positives; these will be handled in code review on a
513 case-by-case basis. Since the script only looks at changed lines,
514 occasionally changing one part of a line can cause the script to report a
515 style issue already present on that line that is unrelated to the change.
516 When convenient it is preferred that these be cleaned up inline, but this is
517 not required.
518
115e70a1
PZ
519 In general, a developer should heed the information reported by checkpatch.
520 However, some flexibility is needed for cases where human judgement yields
521 better clarity than the script. Accordingly, it may be appropriate to
522 ignore some checkpatch.sh warnings per discussion among the submitter(s)
523 and reviewer(s) of a change. Misreporting of errors by the script is
d3c2e316
QY
524 possible. When this occurs, the exception should be handled either by
525 patching checkpatch to correct the false error report, or by documenting the
526 exception in this document under :ref:`style-exceptions`. If the incorrect
527 report is likely to appear again, a checkpatch update is preferred.
115e70a1 528
281ba953
QY
529 If the script finds one or more WARNINGs it will exit with 1. If it finds
530 one or more ERRORs it will exit with 2.
531
532
533Please remember that while FRR provides these tools for your convenience,
534responsibility for properly formatting your code ultimately lies on the
535shoulders of the submitter. As such, it is recommended to double-check the
536results of these tools to avoid delays in merging your submission.
d1890d04 537
115e70a1
PZ
538In some cases, these tools modify or flag the format in ways that go beyond or
539even conflict [#tool_style_conflicts]_ with the canonical documented Linux
540kernel style. In these cases, the Linux kernel style takes priority;
541non-canonical issues flagged by the tools are not compulsory but rather are
542opportunities for discussion among the submitter(s) and reviewer(s) of a change.
543
d1890d04
QY
544**Whitespace changes in untouched parts of the code are not acceptable
545in patches that change actual code.** To change/fix formatting issues,
546please create a separate patch that only does formatting changes and
547nothing else.
548
d1890d04
QY
549Kernel and BSD styles are documented externally:
550
551- https://www.kernel.org/doc/html/latest/process/coding-style.html
552- http://man.openbsd.org/style
553
554For GNU coding style, use ``indent`` with the following invocation:
555
556::
557
558 indent -nut -nfc1 file_for_submission.c
559
28ac5a03
QY
560
561Historically, FRR used fixed-width integral types that do not exist in any
562standard but were defined by most platforms at some point. Officially these
563types are not guaranteed to exist. Therefore, please use the fixed-width
564integral types introduced in the C99 standard when contributing new code to
565FRR. If you need to convert a large amount of code to use the correct types,
566there is a shell script in :file:`tools/convert-fixedwidth.sh` that will do the
567necessary replacements.
568
569+-----------+--------------------------+
570| Incorrect | Correct |
571+===========+==========================+
572| u_int8_t | uint8_t |
573+-----------+--------------------------+
574| u_int16_t | uint16_t |
575+-----------+--------------------------+
576| u_int32_t | uint32_t |
577+-----------+--------------------------+
578| u_int64_t | uint64_t |
579+-----------+--------------------------+
580| u_char | uint8_t or unsigned char |
581+-----------+--------------------------+
582| u_short | unsigned short |
583+-----------+--------------------------+
584| u_int | unsigned int |
585+-----------+--------------------------+
586| u_long | unsigned long |
587+-----------+--------------------------+
588
d3c2e316
QY
589.. _style-exceptions:
590
d1890d04
QY
591Exceptions
592^^^^^^^^^^
593
594FRR project code comes from a variety of sources, so there are some
595stylistic exceptions in place. They are organized here by branch.
596
9de103f0
QY
597For ``master``
598""""""""""""""
d1890d04
QY
599
600BSD coding style applies to:
601
602- ``ldpd/``
603
604``babeld`` uses, approximately, the following style:
605
606- K&R style braces
607- Indents are 4 spaces
608- Function return types are on their own line
609
9de103f0
QY
610For ``stable/3.0`` and ``stable/2.0``
611"""""""""""""""""""""""""""""""""""""
d1890d04
QY
612
613GNU coding style apply to the following parts:
614
615- ``lib/``
616- ``zebra/``
617- ``bgpd/``
618- ``ospfd/``
619- ``ospf6d/``
620- ``isisd/``
621- ``ripd/``
622- ``ripngd/``
623- ``vtysh/``
624
625BSD coding style applies to:
626
627- ``ldpd/``
628
d3c2e316
QY
629
630Specific Exceptions
631^^^^^^^^^^^^^^^^^^^
632
633Most of the time checkpatch errors should be corrected. Occasionally as a group
634maintainers will decide to ignore certain stylistic issues. Usually this is
635because correcting the issue is not possible without large unrelated code
636changes. When an exception is made, if it is unlikely to show up again and
637doesn't warrant an update to checkpatch, it is documented here.
638
639+------------------------------------------+---------------------------------------------------------------+
640| Issue | Ignore Reason |
641+==========================================+===============================================================+
642| DEFPY_HIDDEN, DEFPY_ATTR: complex macros | DEF* macros cannot be wrapped in parentheses without updating |
643| should be wrapped in parentheses | all usages of the macro, which would be highly disruptive. |
644+------------------------------------------+---------------------------------------------------------------+
645
d1890d04 646Compile-time conditional code
9de103f0 647-----------------------------
d1890d04
QY
648
649Many users access FRR via binary packages from 3rd party sources;
650compile-time code puts inclusion/exclusion in the hands of the package
651maintainer. Please think very carefully before making code conditional
652at compile time, as it increases regression testing, maintenance
653burdens, and user confusion. In particular, please avoid gratuitous
654``--enable-…`` switches to the configure script - in general, code
655should be of high quality and in working condition, or it shouldn’t be
656in FRR at all.
657
658When code must be compile-time conditional, try have the compiler make
659it conditional rather than the C pre-processor so that it will still be
660checked by the compiler, even if disabled. For example,
661
662::
663
664 if (SOME_SYMBOL)
665 frobnicate();
666
667is preferred to
668
669::
670
671 #ifdef SOME_SYMBOL
672 frobnicate ();
673 #endif /* SOME_SYMBOL */
674
b6820993
QY
675Note that the former approach requires ensuring that ``SOME_SYMBOL`` will be
676defined (watch your ``AC_DEFINE``\ s).
d1890d04
QY
677
678Debug-guards in code
9de103f0 679--------------------
d1890d04 680
b6820993
QY
681Debugging statements are an important methodology to allow developers to fix
682issues found in the code after it has been released. The caveat here is that
683the developer must remember that people will be using the code at scale and in
684ways that can be unexpected for the original implementor. As such debugs
685**MUST** be guarded in such a way that they can be turned off. FRR has the
686ability to turn on/off debugs from the CLI and it is expected that the
687developer will use this convention to allow control of their debugs.
d1890d04 688
9e001286
QY
689Static Analysis and Sanitizers
690------------------------------
691Clang/LLVM comes with a variety of tools that can be used to help find bugs in FRR.
692
693clang-analyze
694 This is a static analyzer that scans the source code looking for patterns
695 that are likely to be bugs. The tool is run automatically on pull requests
696 as part of CI and new static analysis warnings will be placed in the CI
697 results. FRR aims for absolutely zero static analysis errors. While the
698 project is not quite there, code that introduces new static analysis errors
699 is very unlikely to be merged.
700
701AddressSanitizer
702 This is an excellent tool that provides runtime instrumentation for
703 detecting memory errors. As part of CI FRR is built with this
704 instrumentation and run through a series of tests to look for any results.
705 Testing your own code with this tool before submission is encouraged. You
706 can enable it by passing::
d5403d4f 707
9e001286
QY
708 --enable-address-sanitizer
709
710 to ``configure``.
711
712ThreadSanitizer
713 Similar to AddressSanitizer, this tool provides runtime instrumentation for
714 detecting data races. If you are working on or around multithreaded code,
715 extensive testing with this instrumtation enabled is *highly* recommended.
716 You can enable it by passing::
d5403d4f 717
9e001286
QY
718 --enable-thread-sanitizer
719
720 to ``configure``.
721
722MemorySanitizer
723 Similar to AddressSanitizer, this tool provides runtime instrumentation for
724 detecting use of uninitialized heap memory. Testing your own code with this
725 tool before submission is encouraged. You can enable it by passing::
d5403d4f 726
9e001286
QY
727 --enable-memory-sanitizer
728
729 to ``configure``.
730
731All of the above tools are available in the Clang/LLVM toolchain since 3.4.
732AddressSanitizer and ThreadSanitizer are available in recent versions of GCC,
733but are no longer actively maintained. MemorySanitizer is not available in GCC.
734
735Additionally, the FRR codebase is regularly scanned with Coverity.
736Unfortunately Coverity does not have the ability to handle scanning pull
737requests, but after code is merged it will send an email notifying project
738members with Coverity access of newly introduced defects.
739
d1890d04 740CLI changes
9de103f0 741-----------
d1890d04 742
b6820993
QY
743CLI's are a complicated ugly beast. Additions or changes to the CLI should use
744a DEFUN to encapsulate one setting as much as is possible. Additionally as new
745DEFUN's are added to the system, documentation should be provided for the new
746commands.
d1890d04
QY
747
748Backwards Compatibility
9de103f0 749-----------------------
d1890d04 750
b6820993
QY
751As a general principle, changes to CLI and code in the lib/ directory should be
752made in a backwards compatible fashion. This means that changes that are purely
753stylistic in nature should be avoided, e.g., renaming an existing macro or
754library function name without any functional change. When adding new parameters
755to common functions, it is also good to consider if this too should be done in
756a backward compatible fashion, e.g., by preserving the old form in addition to
d1890d04
QY
757adding the new form.
758
b6820993
QY
759This is not to say that minor or even major functional changes to CLI and
760common code should be avoided, but rather that the benefit gained from a change
761should be weighed against the added cost/complexity to existing code. Also,
762that when making such changes, it is good to preserve compatibility when
763possible to do so without introducing maintenance overhead/cost. It is also
764important to keep in mind, existing code includes code that may reside in
765private repositories (and is yet to be submitted) or code that has yet to be
766migrated from Quagga to FRR.
110bb121 767
b6820993
QY
768That said, compatibility measures can (and should) be removed when either:
769
770- they become a significant burden, e.g. when data structures change and the
771 compatibility measure would need a complex adaptation layer or becomes
772 flat-out impossible
773- some measure of time (dependent on the specific case) has passed, so that
774 the compatibility grace period is considered expired.
775
776In all cases, compatibility pieces should be marked with compiler/preprocessor
777annotations to print warnings at compile time, pointing to the appropriate
778update path. A ``-Werror`` build should fail if compatibility bits are used. To
779avoid compilation issues in released code, such compiler/preprocessor
780annotations must be ignored non-development branches. For example:
781
782.. code-block:: c
783
e60dd6ca 784 #if CONFDATE > 20180403
b6820993
QY
785 CPP_NOTICE("Use of <XYZ> is deprecated, please use <ABC>")
786 #endif
d1890d04 787
cab3f811
LB
788Preferably, the shell script :file:`tools/fixup-deprecated.py` will be
789updated along with making non-backwards compatible code changes, or an
790alternate script should be introduced, to update the code to match the
791change. When the script is updated, there is no need to preserve the
792deprecated code. Note that this does not apply to user interface
793changes, just internal code, macros and libraries.
794
d1890d04 795Miscellaneous
9de103f0 796-------------
d1890d04 797
b6820993
QY
798When in doubt, follow the guidelines in the Linux kernel style guide, or ask on
799the development mailing list / public Slack instance.
9de103f0
QY
800
801
802.. _documentation:
803
804Documentation
805=============
806
807FRR uses Sphinx+RST as its documentation system. The document you are currently
808reading was generated by Sphinx from RST source in
809:file:`doc/developer/workflow.rst`. The documentation is structured as follows:
810
d5403d4f
QY
811+-----------------------+-------------------------------------------+
812| Directory | Contents |
813+=======================+===========================================+
814| :file:`doc/user` | User documentation; configuration guides; |
815| | protocol overviews |
816+-----------------------+-------------------------------------------+
817| :file:`doc/developer` | Developer's documentation; API specs; |
818| | datastructures; architecture overviews; |
819| | project management procedure |
820+-----------------------+-------------------------------------------+
821| :file:`doc/manpages` | Source for manpages |
822+-----------------------+-------------------------------------------+
823| :file:`doc/figures` | Images and diagrams |
824+-----------------------+-------------------------------------------+
825| :file:`doc/extra` | Miscellaneous Sphinx extensions, scripts, |
826| | customizations, etc. |
827+-----------------------+-------------------------------------------+
828
829Each of these directories, with the exception of :file:`doc/figures` and
830:file:`doc/extra`, contains a Sphinx-generated Makefile and configuration
831script :file:`conf.py` used to set various document parameters. The makefile
832can be used for a variety of targets; invoke `make help` in any of these
833directories for a listing of available output formats. For convenience, there
834is a top-level :file:`Makefile.am` that has targets for PDF and HTML
835documentation for both developer and user documentation, respectively. That
836makefile is also responsible for building manual pages packed with distribution
837builds.
9de103f0
QY
838
839Indent and styling should follow existing conventions:
840
841- 3 spaces for indents under directives
842- Cross references may contain only lowercase alphanumeric characters and
843 hyphens ('-')
844- Lines wrapped to 80 characters where possible
845
846Characters for header levels should follow Python documentation guide:
847
848- ``#`` with overline, for parts
849- ``*`` with overline, for chapters
850- ``=``, for sections
851- ``-``, for subsections
852- ``^``, for subsubsections
853- ``"``, for paragraphs
854
855After you have made your changes, please make sure that you can invoke
856``make latexpdf`` and ``make html`` with no warnings.
857
858The documentation is currently incomplete and needs love. If you find a broken
859cross-reference, figure, dead hyperlink, style issue or any other nastiness we
860gladly accept documentation patches.
861
c91e9b8f
QY
862To build the docs, please ensure you have installed a recent version of
863`Sphinx <http://www.sphinx-doc.org/en/stable/install.html>`_. If you want to
864build LaTeX or PDF docs, you will also need a full LaTeX distribution
865installed.
866
9de103f0
QY
867Code
868----
869
870FRR is a large and complex software project developed by many different people
871over a long period of time. Without adequate documentation, it can be
872exceedingly difficult to understand code segments, APIs and other interfaces.
873In the interest of keeping the project healthy and maintainable, you should
874make every effort to document your code so that other people can understand
875what it does without needing to closely read the code itself.
876
877Some specific guidelines that contributors should follow are:
878
879- Functions exposed in header files should have descriptive comments above
880 their signatures in the header file. At a minimum, a function comment should
881 contain information about the return value, parameters, and a general summary
882 of the function's purpose. Documentation on parameter values can be omitted
883 if it is (very) obvious what they are used for.
884
885 Function comments must follow the style for multiline comments laid out in
886 the kernel style guide.
887
888 Example:
889
890 .. code-block:: c
891
892 /*
893 * Determines whether or not a string is cool.
894 *
b6820993
QY
895 * text
896 * the string to check for coolness
897 *
898 * is_clccfc
899 * whether capslock is cruise control for cool
900 *
901 * Returns:
902 * 7 if the text is cool, 0 otherwise
9de103f0
QY
903 */
904 int check_coolness(const char *text, bool is_clccfc);
905
b6820993
QY
906 Function comments should make it clear what parameters and return values are
907 used for.
9de103f0
QY
908
909- Static functions should have descriptive comments in the same form as above
910 if what they do is not immediately obvious. Use good engineering judgement
911 when deciding whether a comment is necessary. If you are unsure, document
912 your code.
913- Global variables, static or not, should have a comment describing their use.
914- **For new code in lib/, these guidelines are hard requirements.**
915
916If you make significant changes to portions of the codebase covered in the
917Developer's Manual, add a major subsystem or feature, or gain arcane mastery of
918some undocumented or poorly documented part of the codebase, please document
919your work so others can benefit. If you add a major feature or introduce a new
920API, please document the architecture and API to the best of your abilities in
921the Developer's Manual, using good judgement when choosing where to place it.
922
923Finally, if you come across some code that is undocumented and feel like
924going above and beyond, document it! We absolutely appreciate and accept
925patches that document previously undocumented code.
926
927User
928----
929
930If you are contributing code that adds significant user-visible functionality
931please document how to use it in :file:`doc/user`. Use good judgement when
932choosing where to place documentation. For example, instructions on how to use
933your implementation of a new BGP draft should go in the BGP chapter instead of
934being its own chapter. If you are adding a new protocol daemon, please create a
935new chapter.
936
d5403d4f
QY
937FRR Specific Markup
938-------------------
939
940FRR has some customizations applied to the Sphinx markup that go a long way
941towards making documentation easier to use, write and maintain.
942
943CLI Commands
944^^^^^^^^^^^^
945
9de103f0
QY
946When documenting CLI please use a combination of the ``.. index::`` and
947``.. clicmd::`` directives. For example, the command :clicmd:`show pony` would
948be documented as follows:
949
950.. code-block:: rest
951
952 .. index:: show pony
953 .. clicmd:: show pony
954
955 Prints an ASCII pony. Example output:::
956
957 >>\.
958 /_ )`.
959 / _)`^)`. _.---. _
960 (_,' \ `^-)"" `.\
961 | | \
962 \ / |
963 / \ /.___.'\ (\ (_
964 < ,"|| \ |`. \`-'
965 \\ () )| )/
966 hjw |_>|> /_] //
967 /_] /_]
968
969When documented this way, CLI commands can be cross referenced with the
970``:clicmd:`` inline markup like so:
971
972.. code-block:: rest
973
974 :clicmd:`show pony`
975
976This is very helpful for users who want to quickly remind themselves what a
977particular command does.
978
d5403d4f
QY
979Configuration Snippets
980^^^^^^^^^^^^^^^^^^^^^^
981
982When putting blocks of example configuration please use the
983``.. code-block::`` directive and specify ``frr`` as the highlighting language,
984as in the following example. This will tell Sphinx to use a custom Pygments
985lexer to highlight FRR configuration syntax.
986
987.. code-block:: rest
988
989 .. code-block:: frr
990
991 !
992 ! Example configuration file.
993 !
994 log file /tmp/log.log
995 service integrated-vtysh-config
996 !
997 ip route 1.2.3.0/24 reject
998 ipv6 route de:ea:db:ee:ff::/64 reject
999 !
1000
1001
9de103f0
QY
1002.. _GitHub: https://github.com/frrouting/frr
1003.. _GitHub issues: https://github.com/frrouting/frr/issues
115e70a1
PZ
1004
1005.. rubric:: Footnotes
1006
1007.. [#tool_style_conflicts] For example, lines over 80 characters are allowed
1008 for text strings to make it possible to search the code for them: please
1009 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>`_
1010 and `Issue #1794 <https://github.com/FRRouting/frr/issues/1794>`_.