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