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