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