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