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