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