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