Squashed 'shared/n-acd/' changes from 9eb7bf7173..5470816839
5470816839 test: increase timeout on test-veth d44dfa1ba7 build: update c-stdaux 26b10b6514 build: pull in submodule updates 7817fc0a95 n-acd: switch to c-stdaux 5033b2ecdd n-acd: include dependency headers aaf2a66788 build: update README b9448eff98 build: pull in c-stdaux 8ac364e9a3 test: raise MEMLOCK if possible 3cd197162e ci: drop root 0289a33412 test: allow running without root 67a343fe87 build: update email address 3c364ba95f build: bump version d0f7d71fa1 build: document build configuration options 014b00cd27 build: fill in NEWS 180990288a n-acd: document API 79904585df build: update submodules 8185e6ed89 build: reduce boilerplate git-subtree-dir: shared/n-acd git-subtree-split: 54708168399f1662c652b5931608e5077ef462f6
This commit is contained in:
@@ -8,5 +8,5 @@ cd "./ci-build"
|
|||||||
|
|
||||||
${CHERRY_LIB_MESONSETUP} . "${CHERRY_LIB_SRCDIR}" ${N_ACD_CONF}
|
${CHERRY_LIB_MESONSETUP} . "${CHERRY_LIB_SRCDIR}" ${N_ACD_CONF}
|
||||||
${CHERRY_LIB_NINJABUILD}
|
${CHERRY_LIB_NINJABUILD}
|
||||||
sudo ${CHERRY_LIB_MESONTEST}
|
${CHERRY_LIB_MESONTEST}
|
||||||
# no valgrind tests, since bpf(2) is not supported by it
|
# no valgrind tests, since bpf(2) is not supported by it
|
||||||
|
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -7,3 +7,6 @@
|
|||||||
[submodule "subprojects/c-rbtree"]
|
[submodule "subprojects/c-rbtree"]
|
||||||
path = subprojects/c-rbtree
|
path = subprojects/c-rbtree
|
||||||
url = https://github.com/c-util/c-rbtree.git
|
url = https://github.com/c-util/c-rbtree.git
|
||||||
|
[submodule "subprojects/c-stdaux"]
|
||||||
|
path = subprojects/c-stdaux
|
||||||
|
url = https://github.com/c-util/c-stdaux.git
|
||||||
|
4
AUTHORS
4
AUTHORS
@@ -30,10 +30,10 @@ AUTHORS-LGPL:
|
|||||||
along with this program; If not, see <http://www.gnu.org/licenses/>.
|
along with this program; If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
COPYRIGHT: (ordered alphabetically)
|
COPYRIGHT: (ordered alphabetically)
|
||||||
Copyright (C) 2015-2018 Red Hat, Inc.
|
Copyright (C) 2015-2019 Red Hat, Inc.
|
||||||
|
|
||||||
AUTHORS: (ordered alphabetically)
|
AUTHORS: (ordered alphabetically)
|
||||||
Beniamino Galvani <bgalvani@redhat.com>
|
Beniamino Galvani <bgalvani@redhat.com>
|
||||||
David Herrmann <dh.herrmann@gmail.com>
|
David Rheinsberg <david.rheinsberg@gmail.com>
|
||||||
Thomas Haller <thaller@redhat.com>
|
Thomas Haller <thaller@redhat.com>
|
||||||
Tom Gundersen <teg@jklm.no>
|
Tom Gundersen <teg@jklm.no>
|
||||||
|
201
AUTHORS-ASL
201
AUTHORS-ASL
@@ -1,201 +0,0 @@
|
|||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright {yyyy} {name of copyright owner}
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
502
AUTHORS-LGPL
502
AUTHORS-LGPL
@@ -1,502 +0,0 @@
|
|||||||
GNU LESSER GENERAL PUBLIC LICENSE
|
|
||||||
Version 2.1, February 1999
|
|
||||||
|
|
||||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
[This is the first released version of the Lesser GPL. It also counts
|
|
||||||
as the successor of the GNU Library Public License, version 2, hence
|
|
||||||
the version number 2.1.]
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The licenses for most software are designed to take away your
|
|
||||||
freedom to share and change it. By contrast, the GNU General Public
|
|
||||||
Licenses are intended to guarantee your freedom to share and change
|
|
||||||
free software--to make sure the software is free for all its users.
|
|
||||||
|
|
||||||
This license, the Lesser General Public License, applies to some
|
|
||||||
specially designated software packages--typically libraries--of the
|
|
||||||
Free Software Foundation and other authors who decide to use it. You
|
|
||||||
can use it too, but we suggest you first think carefully about whether
|
|
||||||
this license or the ordinary General Public License is the better
|
|
||||||
strategy to use in any particular case, based on the explanations below.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom of use,
|
|
||||||
not price. Our General Public Licenses are designed to make sure that
|
|
||||||
you have the freedom to distribute copies of free software (and charge
|
|
||||||
for this service if you wish); that you receive source code or can get
|
|
||||||
it if you want it; that you can change the software and use pieces of
|
|
||||||
it in new free programs; and that you are informed that you can do
|
|
||||||
these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to make restrictions that forbid
|
|
||||||
distributors to deny you these rights or to ask you to surrender these
|
|
||||||
rights. These restrictions translate to certain responsibilities for
|
|
||||||
you if you distribute copies of the library or if you modify it.
|
|
||||||
|
|
||||||
For example, if you distribute copies of the library, whether gratis
|
|
||||||
or for a fee, you must give the recipients all the rights that we gave
|
|
||||||
you. You must make sure that they, too, receive or can get the source
|
|
||||||
code. If you link other code with the library, you must provide
|
|
||||||
complete object files to the recipients, so that they can relink them
|
|
||||||
with the library after making changes to the library and recompiling
|
|
||||||
it. And you must show them these terms so they know their rights.
|
|
||||||
|
|
||||||
We protect your rights with a two-step method: (1) we copyright the
|
|
||||||
library, and (2) we offer you this license, which gives you legal
|
|
||||||
permission to copy, distribute and/or modify the library.
|
|
||||||
|
|
||||||
To protect each distributor, we want to make it very clear that
|
|
||||||
there is no warranty for the free library. Also, if the library is
|
|
||||||
modified by someone else and passed on, the recipients should know
|
|
||||||
that what they have is not the original version, so that the original
|
|
||||||
author's reputation will not be affected by problems that might be
|
|
||||||
introduced by others.
|
|
||||||
|
|
||||||
Finally, software patents pose a constant threat to the existence of
|
|
||||||
any free program. We wish to make sure that a company cannot
|
|
||||||
effectively restrict the users of a free program by obtaining a
|
|
||||||
restrictive license from a patent holder. Therefore, we insist that
|
|
||||||
any patent license obtained for a version of the library must be
|
|
||||||
consistent with the full freedom of use specified in this license.
|
|
||||||
|
|
||||||
Most GNU software, including some libraries, is covered by the
|
|
||||||
ordinary GNU General Public License. This license, the GNU Lesser
|
|
||||||
General Public License, applies to certain designated libraries, and
|
|
||||||
is quite different from the ordinary General Public License. We use
|
|
||||||
this license for certain libraries in order to permit linking those
|
|
||||||
libraries into non-free programs.
|
|
||||||
|
|
||||||
When a program is linked with a library, whether statically or using
|
|
||||||
a shared library, the combination of the two is legally speaking a
|
|
||||||
combined work, a derivative of the original library. The ordinary
|
|
||||||
General Public License therefore permits such linking only if the
|
|
||||||
entire combination fits its criteria of freedom. The Lesser General
|
|
||||||
Public License permits more lax criteria for linking other code with
|
|
||||||
the library.
|
|
||||||
|
|
||||||
We call this license the "Lesser" General Public License because it
|
|
||||||
does Less to protect the user's freedom than the ordinary General
|
|
||||||
Public License. It also provides other free software developers Less
|
|
||||||
of an advantage over competing non-free programs. These disadvantages
|
|
||||||
are the reason we use the ordinary General Public License for many
|
|
||||||
libraries. However, the Lesser license provides advantages in certain
|
|
||||||
special circumstances.
|
|
||||||
|
|
||||||
For example, on rare occasions, there may be a special need to
|
|
||||||
encourage the widest possible use of a certain library, so that it becomes
|
|
||||||
a de-facto standard. To achieve this, non-free programs must be
|
|
||||||
allowed to use the library. A more frequent case is that a free
|
|
||||||
library does the same job as widely used non-free libraries. In this
|
|
||||||
case, there is little to gain by limiting the free library to free
|
|
||||||
software only, so we use the Lesser General Public License.
|
|
||||||
|
|
||||||
In other cases, permission to use a particular library in non-free
|
|
||||||
programs enables a greater number of people to use a large body of
|
|
||||||
free software. For example, permission to use the GNU C Library in
|
|
||||||
non-free programs enables many more people to use the whole GNU
|
|
||||||
operating system, as well as its variant, the GNU/Linux operating
|
|
||||||
system.
|
|
||||||
|
|
||||||
Although the Lesser General Public License is Less protective of the
|
|
||||||
users' freedom, it does ensure that the user of a program that is
|
|
||||||
linked with the Library has the freedom and the wherewithal to run
|
|
||||||
that program using a modified version of the Library.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow. Pay close attention to the difference between a
|
|
||||||
"work based on the library" and a "work that uses the library". The
|
|
||||||
former contains code derived from the library, whereas the latter must
|
|
||||||
be combined with the library in order to run.
|
|
||||||
|
|
||||||
GNU LESSER GENERAL PUBLIC LICENSE
|
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
||||||
|
|
||||||
0. This License Agreement applies to any software library or other
|
|
||||||
program which contains a notice placed by the copyright holder or
|
|
||||||
other authorized party saying it may be distributed under the terms of
|
|
||||||
this Lesser General Public License (also called "this License").
|
|
||||||
Each licensee is addressed as "you".
|
|
||||||
|
|
||||||
A "library" means a collection of software functions and/or data
|
|
||||||
prepared so as to be conveniently linked with application programs
|
|
||||||
(which use some of those functions and data) to form executables.
|
|
||||||
|
|
||||||
The "Library", below, refers to any such software library or work
|
|
||||||
which has been distributed under these terms. A "work based on the
|
|
||||||
Library" means either the Library or any derivative work under
|
|
||||||
copyright law: that is to say, a work containing the Library or a
|
|
||||||
portion of it, either verbatim or with modifications and/or translated
|
|
||||||
straightforwardly into another language. (Hereinafter, translation is
|
|
||||||
included without limitation in the term "modification".)
|
|
||||||
|
|
||||||
"Source code" for a work means the preferred form of the work for
|
|
||||||
making modifications to it. For a library, complete source code means
|
|
||||||
all the source code for all modules it contains, plus any associated
|
|
||||||
interface definition files, plus the scripts used to control compilation
|
|
||||||
and installation of the library.
|
|
||||||
|
|
||||||
Activities other than copying, distribution and modification are not
|
|
||||||
covered by this License; they are outside its scope. The act of
|
|
||||||
running a program using the Library is not restricted, and output from
|
|
||||||
such a program is covered only if its contents constitute a work based
|
|
||||||
on the Library (independent of the use of the Library in a tool for
|
|
||||||
writing it). Whether that is true depends on what the Library does
|
|
||||||
and what the program that uses the Library does.
|
|
||||||
|
|
||||||
1. You may copy and distribute verbatim copies of the Library's
|
|
||||||
complete source code as you receive it, in any medium, provided that
|
|
||||||
you conspicuously and appropriately publish on each copy an
|
|
||||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
|
||||||
all the notices that refer to this License and to the absence of any
|
|
||||||
warranty; and distribute a copy of this License along with the
|
|
||||||
Library.
|
|
||||||
|
|
||||||
You may charge a fee for the physical act of transferring a copy,
|
|
||||||
and you may at your option offer warranty protection in exchange for a
|
|
||||||
fee.
|
|
||||||
|
|
||||||
2. You may modify your copy or copies of the Library or any portion
|
|
||||||
of it, thus forming a work based on the Library, and copy and
|
|
||||||
distribute such modifications or work under the terms of Section 1
|
|
||||||
above, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The modified work must itself be a software library.
|
|
||||||
|
|
||||||
b) You must cause the files modified to carry prominent notices
|
|
||||||
stating that you changed the files and the date of any change.
|
|
||||||
|
|
||||||
c) You must cause the whole of the work to be licensed at no
|
|
||||||
charge to all third parties under the terms of this License.
|
|
||||||
|
|
||||||
d) If a facility in the modified Library refers to a function or a
|
|
||||||
table of data to be supplied by an application program that uses
|
|
||||||
the facility, other than as an argument passed when the facility
|
|
||||||
is invoked, then you must make a good faith effort to ensure that,
|
|
||||||
in the event an application does not supply such function or
|
|
||||||
table, the facility still operates, and performs whatever part of
|
|
||||||
its purpose remains meaningful.
|
|
||||||
|
|
||||||
(For example, a function in a library to compute square roots has
|
|
||||||
a purpose that is entirely well-defined independent of the
|
|
||||||
application. Therefore, Subsection 2d requires that any
|
|
||||||
application-supplied function or table used by this function must
|
|
||||||
be optional: if the application does not supply it, the square
|
|
||||||
root function must still compute square roots.)
|
|
||||||
|
|
||||||
These requirements apply to the modified work as a whole. If
|
|
||||||
identifiable sections of that work are not derived from the Library,
|
|
||||||
and can be reasonably considered independent and separate works in
|
|
||||||
themselves, then this License, and its terms, do not apply to those
|
|
||||||
sections when you distribute them as separate works. But when you
|
|
||||||
distribute the same sections as part of a whole which is a work based
|
|
||||||
on the Library, the distribution of the whole must be on the terms of
|
|
||||||
this License, whose permissions for other licensees extend to the
|
|
||||||
entire whole, and thus to each and every part regardless of who wrote
|
|
||||||
it.
|
|
||||||
|
|
||||||
Thus, it is not the intent of this section to claim rights or contest
|
|
||||||
your rights to work written entirely by you; rather, the intent is to
|
|
||||||
exercise the right to control the distribution of derivative or
|
|
||||||
collective works based on the Library.
|
|
||||||
|
|
||||||
In addition, mere aggregation of another work not based on the Library
|
|
||||||
with the Library (or with a work based on the Library) on a volume of
|
|
||||||
a storage or distribution medium does not bring the other work under
|
|
||||||
the scope of this License.
|
|
||||||
|
|
||||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
|
||||||
License instead of this License to a given copy of the Library. To do
|
|
||||||
this, you must alter all the notices that refer to this License, so
|
|
||||||
that they refer to the ordinary GNU General Public License, version 2,
|
|
||||||
instead of to this License. (If a newer version than version 2 of the
|
|
||||||
ordinary GNU General Public License has appeared, then you can specify
|
|
||||||
that version instead if you wish.) Do not make any other change in
|
|
||||||
these notices.
|
|
||||||
|
|
||||||
Once this change is made in a given copy, it is irreversible for
|
|
||||||
that copy, so the ordinary GNU General Public License applies to all
|
|
||||||
subsequent copies and derivative works made from that copy.
|
|
||||||
|
|
||||||
This option is useful when you wish to copy part of the code of
|
|
||||||
the Library into a program that is not a library.
|
|
||||||
|
|
||||||
4. You may copy and distribute the Library (or a portion or
|
|
||||||
derivative of it, under Section 2) in object code or executable form
|
|
||||||
under the terms of Sections 1 and 2 above provided that you accompany
|
|
||||||
it with the complete corresponding machine-readable source code, which
|
|
||||||
must be distributed under the terms of Sections 1 and 2 above on a
|
|
||||||
medium customarily used for software interchange.
|
|
||||||
|
|
||||||
If distribution of object code is made by offering access to copy
|
|
||||||
from a designated place, then offering equivalent access to copy the
|
|
||||||
source code from the same place satisfies the requirement to
|
|
||||||
distribute the source code, even though third parties are not
|
|
||||||
compelled to copy the source along with the object code.
|
|
||||||
|
|
||||||
5. A program that contains no derivative of any portion of the
|
|
||||||
Library, but is designed to work with the Library by being compiled or
|
|
||||||
linked with it, is called a "work that uses the Library". Such a
|
|
||||||
work, in isolation, is not a derivative work of the Library, and
|
|
||||||
therefore falls outside the scope of this License.
|
|
||||||
|
|
||||||
However, linking a "work that uses the Library" with the Library
|
|
||||||
creates an executable that is a derivative of the Library (because it
|
|
||||||
contains portions of the Library), rather than a "work that uses the
|
|
||||||
library". The executable is therefore covered by this License.
|
|
||||||
Section 6 states terms for distribution of such executables.
|
|
||||||
|
|
||||||
When a "work that uses the Library" uses material from a header file
|
|
||||||
that is part of the Library, the object code for the work may be a
|
|
||||||
derivative work of the Library even though the source code is not.
|
|
||||||
Whether this is true is especially significant if the work can be
|
|
||||||
linked without the Library, or if the work is itself a library. The
|
|
||||||
threshold for this to be true is not precisely defined by law.
|
|
||||||
|
|
||||||
If such an object file uses only numerical parameters, data
|
|
||||||
structure layouts and accessors, and small macros and small inline
|
|
||||||
functions (ten lines or less in length), then the use of the object
|
|
||||||
file is unrestricted, regardless of whether it is legally a derivative
|
|
||||||
work. (Executables containing this object code plus portions of the
|
|
||||||
Library will still fall under Section 6.)
|
|
||||||
|
|
||||||
Otherwise, if the work is a derivative of the Library, you may
|
|
||||||
distribute the object code for the work under the terms of Section 6.
|
|
||||||
Any executables containing that work also fall under Section 6,
|
|
||||||
whether or not they are linked directly with the Library itself.
|
|
||||||
|
|
||||||
6. As an exception to the Sections above, you may also combine or
|
|
||||||
link a "work that uses the Library" with the Library to produce a
|
|
||||||
work containing portions of the Library, and distribute that work
|
|
||||||
under terms of your choice, provided that the terms permit
|
|
||||||
modification of the work for the customer's own use and reverse
|
|
||||||
engineering for debugging such modifications.
|
|
||||||
|
|
||||||
You must give prominent notice with each copy of the work that the
|
|
||||||
Library is used in it and that the Library and its use are covered by
|
|
||||||
this License. You must supply a copy of this License. If the work
|
|
||||||
during execution displays copyright notices, you must include the
|
|
||||||
copyright notice for the Library among them, as well as a reference
|
|
||||||
directing the user to the copy of this License. Also, you must do one
|
|
||||||
of these things:
|
|
||||||
|
|
||||||
a) Accompany the work with the complete corresponding
|
|
||||||
machine-readable source code for the Library including whatever
|
|
||||||
changes were used in the work (which must be distributed under
|
|
||||||
Sections 1 and 2 above); and, if the work is an executable linked
|
|
||||||
with the Library, with the complete machine-readable "work that
|
|
||||||
uses the Library", as object code and/or source code, so that the
|
|
||||||
user can modify the Library and then relink to produce a modified
|
|
||||||
executable containing the modified Library. (It is understood
|
|
||||||
that the user who changes the contents of definitions files in the
|
|
||||||
Library will not necessarily be able to recompile the application
|
|
||||||
to use the modified definitions.)
|
|
||||||
|
|
||||||
b) Use a suitable shared library mechanism for linking with the
|
|
||||||
Library. A suitable mechanism is one that (1) uses at run time a
|
|
||||||
copy of the library already present on the user's computer system,
|
|
||||||
rather than copying library functions into the executable, and (2)
|
|
||||||
will operate properly with a modified version of the library, if
|
|
||||||
the user installs one, as long as the modified version is
|
|
||||||
interface-compatible with the version that the work was made with.
|
|
||||||
|
|
||||||
c) Accompany the work with a written offer, valid for at
|
|
||||||
least three years, to give the same user the materials
|
|
||||||
specified in Subsection 6a, above, for a charge no more
|
|
||||||
than the cost of performing this distribution.
|
|
||||||
|
|
||||||
d) If distribution of the work is made by offering access to copy
|
|
||||||
from a designated place, offer equivalent access to copy the above
|
|
||||||
specified materials from the same place.
|
|
||||||
|
|
||||||
e) Verify that the user has already received a copy of these
|
|
||||||
materials or that you have already sent this user a copy.
|
|
||||||
|
|
||||||
For an executable, the required form of the "work that uses the
|
|
||||||
Library" must include any data and utility programs needed for
|
|
||||||
reproducing the executable from it. However, as a special exception,
|
|
||||||
the materials to be distributed need not include anything that is
|
|
||||||
normally distributed (in either source or binary form) with the major
|
|
||||||
components (compiler, kernel, and so on) of the operating system on
|
|
||||||
which the executable runs, unless that component itself accompanies
|
|
||||||
the executable.
|
|
||||||
|
|
||||||
It may happen that this requirement contradicts the license
|
|
||||||
restrictions of other proprietary libraries that do not normally
|
|
||||||
accompany the operating system. Such a contradiction means you cannot
|
|
||||||
use both them and the Library together in an executable that you
|
|
||||||
distribute.
|
|
||||||
|
|
||||||
7. You may place library facilities that are a work based on the
|
|
||||||
Library side-by-side in a single library together with other library
|
|
||||||
facilities not covered by this License, and distribute such a combined
|
|
||||||
library, provided that the separate distribution of the work based on
|
|
||||||
the Library and of the other library facilities is otherwise
|
|
||||||
permitted, and provided that you do these two things:
|
|
||||||
|
|
||||||
a) Accompany the combined library with a copy of the same work
|
|
||||||
based on the Library, uncombined with any other library
|
|
||||||
facilities. This must be distributed under the terms of the
|
|
||||||
Sections above.
|
|
||||||
|
|
||||||
b) Give prominent notice with the combined library of the fact
|
|
||||||
that part of it is a work based on the Library, and explaining
|
|
||||||
where to find the accompanying uncombined form of the same work.
|
|
||||||
|
|
||||||
8. You may not copy, modify, sublicense, link with, or distribute
|
|
||||||
the Library except as expressly provided under this License. Any
|
|
||||||
attempt otherwise to copy, modify, sublicense, link with, or
|
|
||||||
distribute the Library is void, and will automatically terminate your
|
|
||||||
rights under this License. However, parties who have received copies,
|
|
||||||
or rights, from you under this License will not have their licenses
|
|
||||||
terminated so long as such parties remain in full compliance.
|
|
||||||
|
|
||||||
9. You are not required to accept this License, since you have not
|
|
||||||
signed it. However, nothing else grants you permission to modify or
|
|
||||||
distribute the Library or its derivative works. These actions are
|
|
||||||
prohibited by law if you do not accept this License. Therefore, by
|
|
||||||
modifying or distributing the Library (or any work based on the
|
|
||||||
Library), you indicate your acceptance of this License to do so, and
|
|
||||||
all its terms and conditions for copying, distributing or modifying
|
|
||||||
the Library or works based on it.
|
|
||||||
|
|
||||||
10. Each time you redistribute the Library (or any work based on the
|
|
||||||
Library), the recipient automatically receives a license from the
|
|
||||||
original licensor to copy, distribute, link with or modify the Library
|
|
||||||
subject to these terms and conditions. You may not impose any further
|
|
||||||
restrictions on the recipients' exercise of the rights granted herein.
|
|
||||||
You are not responsible for enforcing compliance by third parties with
|
|
||||||
this License.
|
|
||||||
|
|
||||||
11. If, as a consequence of a court judgment or allegation of patent
|
|
||||||
infringement or for any other reason (not limited to patent issues),
|
|
||||||
conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot
|
|
||||||
distribute so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you
|
|
||||||
may not distribute the Library at all. For example, if a patent
|
|
||||||
license would not permit royalty-free redistribution of the Library by
|
|
||||||
all those who receive copies directly or indirectly through you, then
|
|
||||||
the only way you could satisfy both it and this License would be to
|
|
||||||
refrain entirely from distribution of the Library.
|
|
||||||
|
|
||||||
If any portion of this section is held invalid or unenforceable under any
|
|
||||||
particular circumstance, the balance of the section is intended to apply,
|
|
||||||
and the section as a whole is intended to apply in other circumstances.
|
|
||||||
|
|
||||||
It is not the purpose of this section to induce you to infringe any
|
|
||||||
patents or other property right claims or to contest validity of any
|
|
||||||
such claims; this section has the sole purpose of protecting the
|
|
||||||
integrity of the free software distribution system which is
|
|
||||||
implemented by public license practices. Many people have made
|
|
||||||
generous contributions to the wide range of software distributed
|
|
||||||
through that system in reliance on consistent application of that
|
|
||||||
system; it is up to the author/donor to decide if he or she is willing
|
|
||||||
to distribute software through any other system and a licensee cannot
|
|
||||||
impose that choice.
|
|
||||||
|
|
||||||
This section is intended to make thoroughly clear what is believed to
|
|
||||||
be a consequence of the rest of this License.
|
|
||||||
|
|
||||||
12. If the distribution and/or use of the Library is restricted in
|
|
||||||
certain countries either by patents or by copyrighted interfaces, the
|
|
||||||
original copyright holder who places the Library under this License may add
|
|
||||||
an explicit geographical distribution limitation excluding those countries,
|
|
||||||
so that distribution is permitted only in or among countries not thus
|
|
||||||
excluded. In such case, this License incorporates the limitation as if
|
|
||||||
written in the body of this License.
|
|
||||||
|
|
||||||
13. The Free Software Foundation may publish revised and/or new
|
|
||||||
versions of the Lesser General Public License from time to time.
|
|
||||||
Such new versions will be similar in spirit to the present version,
|
|
||||||
but may differ in detail to address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the Library
|
|
||||||
specifies a version number of this License which applies to it and
|
|
||||||
"any later version", you have the option of following the terms and
|
|
||||||
conditions either of that version or of any later version published by
|
|
||||||
the Free Software Foundation. If the Library does not specify a
|
|
||||||
license version number, you may choose any version ever published by
|
|
||||||
the Free Software Foundation.
|
|
||||||
|
|
||||||
14. If you wish to incorporate parts of the Library into other free
|
|
||||||
programs whose distribution conditions are incompatible with these,
|
|
||||||
write to the author to ask for permission. For software which is
|
|
||||||
copyrighted by the Free Software Foundation, write to the Free
|
|
||||||
Software Foundation; we sometimes make exceptions for this. Our
|
|
||||||
decision will be guided by the two goals of preserving the free status
|
|
||||||
of all derivatives of our free software and of promoting the sharing
|
|
||||||
and reuse of software generally.
|
|
||||||
|
|
||||||
NO WARRANTY
|
|
||||||
|
|
||||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
|
||||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
|
||||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
|
||||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
|
||||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
|
||||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
|
||||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
|
||||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
|
||||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
|
||||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
|
||||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
|
||||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
|
||||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
|
||||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
|
||||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
||||||
DAMAGES.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Libraries
|
|
||||||
|
|
||||||
If you develop a new library, and you want it to be of the greatest
|
|
||||||
possible use to the public, we recommend making it free software that
|
|
||||||
everyone can redistribute and change. You can do so by permitting
|
|
||||||
redistribution under these terms (or, alternatively, under the terms of the
|
|
||||||
ordinary General Public License).
|
|
||||||
|
|
||||||
To apply these terms, attach the following notices to the library. It is
|
|
||||||
safest to attach them to the start of each source file to most effectively
|
|
||||||
convey the exclusion of warranty; and each file should have at least the
|
|
||||||
"copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the library's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Lesser General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2.1 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or your
|
|
||||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
|
||||||
necessary. Here is a sample; alter the names:
|
|
||||||
|
|
||||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
|
||||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
|
||||||
|
|
||||||
<signature of Ty Coon>, 1 April 1990
|
|
||||||
Ty Coon, President of Vice
|
|
||||||
|
|
||||||
That's all there is to it!
|
|
21
NEWS
21
NEWS
@@ -1,21 +0,0 @@
|
|||||||
n-acd - IPv4 Address Conflict Detection
|
|
||||||
|
|
||||||
CHANGES WITH 1:
|
|
||||||
|
|
||||||
* Initial release of n-acd. This project implements the IPv4 Address
|
|
||||||
Conflict Detection standard as defined in RFC-5227. The state machine
|
|
||||||
is implemented in a shared library and provides a stable ISO-C11 API.
|
|
||||||
The implementation is linux-only and relies heavily on the API
|
|
||||||
behavior of recent linux kernel releases.
|
|
||||||
|
|
||||||
* Compared to the pre-releases, this release supports many parallel
|
|
||||||
probes on a single n-acd context. This reduces the number of
|
|
||||||
allocated network resources to O(1), based on the number of running
|
|
||||||
parallel probes.
|
|
||||||
|
|
||||||
* The n-acd project is now dual-licensed: ASL-2.0 and LGPL-2.1+
|
|
||||||
|
|
||||||
Contributions from: Beniamino Galvani, David Herrmann, Thomas Haller,
|
|
||||||
Tom Gundersen
|
|
||||||
|
|
||||||
- Tübingen, 2018-08-08
|
|
46
NEWS.md
Normal file
46
NEWS.md
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# n-acd - IPv4 Address Conflict Detection
|
||||||
|
|
||||||
|
## CHANGES WITH 2:
|
||||||
|
|
||||||
|
* All public destructors now include a variant that returns `void`.
|
||||||
|
This was requested for easier integration with `glib` and friends.
|
||||||
|
Similar to the `cleanup` variants, these variants are denoted by a
|
||||||
|
single-character function-name suffix. E.g., `n_acd_freev()`
|
||||||
|
|
||||||
|
* A fallback to `CLOCK_MONOTONIC` is now provided in case
|
||||||
|
`CLOCK_BOOTTIME` is not supported by the kernel. Note that this is in
|
||||||
|
no way signalled through the API, so if timers should follow the
|
||||||
|
`BOOTTIME` rather than monotonic clock, a kernel with this clock is
|
||||||
|
required.
|
||||||
|
|
||||||
|
* The `c-sundry` dependency is no longer needed.
|
||||||
|
|
||||||
|
* The `transport` configuration property is now mandatory for
|
||||||
|
`n_acd_new()`. It defaulted to `ETHERNET` before, by mistake.
|
||||||
|
|
||||||
|
* In-source documentation for the public API is now provided.
|
||||||
|
|
||||||
|
Contributions from: Beniamino Galvani, David Herrmann, David
|
||||||
|
Rheinsberg, Thomas Haller, Tom Gundersen
|
||||||
|
|
||||||
|
- Tübingen, 2019-03-20
|
||||||
|
|
||||||
|
## CHANGES WITH 1:
|
||||||
|
|
||||||
|
* Initial release of n-acd. This project implements the IPv4 Address
|
||||||
|
Conflict Detection standard as defined in RFC-5227. The state machine
|
||||||
|
is implemented in a shared library and provides a stable ISO-C11 API.
|
||||||
|
The implementation is linux-only and relies heavily on the API
|
||||||
|
behavior of recent linux kernel releases.
|
||||||
|
|
||||||
|
* Compared to the pre-releases, this release supports many parallel
|
||||||
|
probes on a single n-acd context. This reduces the number of
|
||||||
|
allocated network resources to O(1), based on the number of running
|
||||||
|
parallel probes.
|
||||||
|
|
||||||
|
* The n-acd project is now dual-licensed: ASL-2.0 and LGPL-2.1+
|
||||||
|
|
||||||
|
Contributions from: Beniamino Galvani, David Herrmann, Thomas Haller,
|
||||||
|
Tom Gundersen
|
||||||
|
|
||||||
|
- Tübingen, 2018-08-08
|
54
README
54
README
@@ -1,54 +0,0 @@
|
|||||||
n-acd - IPv4 Address Conflict Detection
|
|
||||||
|
|
||||||
ABOUT:
|
|
||||||
The n-acd project implements the IPv4 Address Conflict Detection
|
|
||||||
standard as defined in RFC-5227. The state machine is implemented in a
|
|
||||||
shared library and provides a stable ISO-C11 API. The implementation is
|
|
||||||
linux-only and relies heavily on the API behavior of recent linux
|
|
||||||
kernel releases.
|
|
||||||
|
|
||||||
DETAILS:
|
|
||||||
https://nettools.github.io/n-acd
|
|
||||||
|
|
||||||
BUG REPORTS:
|
|
||||||
https://github.com/nettools/n-acd/issues
|
|
||||||
|
|
||||||
GIT:
|
|
||||||
git@github.com:nettools/n-acd.git
|
|
||||||
https://github.com/nettools/n-acd.git
|
|
||||||
|
|
||||||
GITWEB:
|
|
||||||
https://github.com/nettools/n-acd
|
|
||||||
|
|
||||||
MAILINGLIST:
|
|
||||||
https://groups.google.com/forum/#!forum/nettools-devel
|
|
||||||
|
|
||||||
LICENSE:
|
|
||||||
Apache Software License 2.0
|
|
||||||
Lesser General Public License 2.1+
|
|
||||||
See AUTHORS for details.
|
|
||||||
|
|
||||||
REQUIREMENTS:
|
|
||||||
The requirements for n-acd are:
|
|
||||||
|
|
||||||
Linux kernel >= 3.19
|
|
||||||
libc (e.g., glibc >= 2.16)
|
|
||||||
|
|
||||||
At build-time, the following software is required:
|
|
||||||
|
|
||||||
meson >= 0.41
|
|
||||||
pkg-config >= 0.29
|
|
||||||
|
|
||||||
INSTALL:
|
|
||||||
The meson build-system is used for this project. Contact upstream
|
|
||||||
documentation for detailed help. In most situations the following
|
|
||||||
commands are sufficient to build and install from source:
|
|
||||||
|
|
||||||
$ mkdir build
|
|
||||||
$ cd build
|
|
||||||
$ meson setup ..
|
|
||||||
$ ninja
|
|
||||||
$ meson test
|
|
||||||
# ninja install
|
|
||||||
|
|
||||||
For custom configuration options see meson_options.txt.
|
|
60
README.md
Normal file
60
README.md
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
n-acd
|
||||||
|
=====
|
||||||
|
|
||||||
|
IPv4 Address Conflict Detection
|
||||||
|
|
||||||
|
The n-acd project implements the IPv4 Address Conflict Detection standard as
|
||||||
|
defined in RFC-5227. The state machine is implemented in a shared library and
|
||||||
|
provides a stable ISO-C11 API. The implementation is linux-only and relies
|
||||||
|
heavily on the API behavior of recent linux kernel releases.
|
||||||
|
|
||||||
|
### Project
|
||||||
|
|
||||||
|
* **Website**: <https://nettools.github.io/n-acd>
|
||||||
|
* **Bug Tracker**: <https://github.com/nettools/n-acd/issues>
|
||||||
|
* **Mailing-List**: <https://groups.google.com/forum/#!forum/nettools-devel>
|
||||||
|
|
||||||
|
### Requirements
|
||||||
|
|
||||||
|
The requirements for this project are:
|
||||||
|
|
||||||
|
* `Linux kernel >= 3.19`
|
||||||
|
* `libc` (e.g., `glibc >= 2.16`)
|
||||||
|
|
||||||
|
At build-time, the following software is required:
|
||||||
|
|
||||||
|
* `meson >= 0.41`
|
||||||
|
* `pkg-config >= 0.29`
|
||||||
|
|
||||||
|
### Build
|
||||||
|
|
||||||
|
The meson build-system is used for this project. Contact upstream
|
||||||
|
documentation for detailed help. In most situations the following
|
||||||
|
commands are sufficient to build and install from source:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
meson setup ..
|
||||||
|
ninja
|
||||||
|
meson test
|
||||||
|
ninja install
|
||||||
|
```
|
||||||
|
|
||||||
|
The following configuration options are available:
|
||||||
|
|
||||||
|
* `ebpf`: This boolean controls whether `ebpf` features are used to improve
|
||||||
|
the package filtering performance. If disabled, classic bpf will be
|
||||||
|
used. This feature requires a rather recent kernel (>=3.19).
|
||||||
|
Default is: true
|
||||||
|
|
||||||
|
### Repository:
|
||||||
|
|
||||||
|
- **web**: <https://github.com/nettools/n-acd>
|
||||||
|
- **https**: `https://github.com/nettools/n-acd.git`
|
||||||
|
- **ssh**: `git@github.com:nettools/n-acd.git`
|
||||||
|
|
||||||
|
### License:
|
||||||
|
|
||||||
|
- **Apache-2.0** OR **LGPL-2.1-or-later**
|
||||||
|
- See AUTHORS file for details.
|
@@ -1,7 +1,7 @@
|
|||||||
project(
|
project(
|
||||||
'n-acd',
|
'n-acd',
|
||||||
'c',
|
'c',
|
||||||
version: '1',
|
version: '2',
|
||||||
license: 'Apache',
|
license: 'Apache',
|
||||||
default_options: [
|
default_options: [
|
||||||
'c_std=c11',
|
'c_std=c11',
|
||||||
@@ -15,10 +15,12 @@ mod_pkgconfig = import('pkgconfig')
|
|||||||
sub_clist = subproject('c-list')
|
sub_clist = subproject('c-list')
|
||||||
sub_crbtree = subproject('c-rbtree')
|
sub_crbtree = subproject('c-rbtree')
|
||||||
sub_csiphash = subproject('c-siphash')
|
sub_csiphash = subproject('c-siphash')
|
||||||
|
sub_cstdaux = subproject('c-stdaux')
|
||||||
|
|
||||||
dep_clist = sub_clist.get_variable('libclist_dep')
|
dep_clist = sub_clist.get_variable('libclist_dep')
|
||||||
dep_crbtree = sub_crbtree.get_variable('libcrbtree_dep')
|
dep_crbtree = sub_crbtree.get_variable('libcrbtree_dep')
|
||||||
dep_csiphash = sub_csiphash.get_variable('libcsiphash_dep')
|
dep_csiphash = sub_csiphash.get_variable('libcsiphash_dep')
|
||||||
|
dep_cstdaux = sub_cstdaux.get_variable('libcstdaux_dep')
|
||||||
|
|
||||||
use_ebpf = get_option('ebpf')
|
use_ebpf = get_option('ebpf')
|
||||||
|
|
||||||
|
@@ -8,6 +8,7 @@ libnacd_deps = [
|
|||||||
dep_clist,
|
dep_clist,
|
||||||
dep_crbtree,
|
dep_crbtree,
|
||||||
dep_csiphash,
|
dep_csiphash,
|
||||||
|
dep_cstdaux,
|
||||||
]
|
]
|
||||||
|
|
||||||
libnacd_sources = [
|
libnacd_sources = [
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
* See n-acd-bpf.c for documentation.
|
* See n-acd-bpf.c for documentation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <c-stdaux.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include "n-acd-private.h"
|
#include "n-acd-private.h"
|
||||||
|
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
* that have already been removed.
|
* that have already been removed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <c-stdaux.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <linux/bpf.h>
|
#include <linux/bpf.h>
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <c-list.h>
|
#include <c-list.h>
|
||||||
#include <c-rbtree.h>
|
#include <c-rbtree.h>
|
||||||
|
#include <c-stdaux.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <netinet/if_ether.h>
|
#include <netinet/if_ether.h>
|
||||||
@@ -13,9 +14,6 @@
|
|||||||
|
|
||||||
typedef struct NAcdEventNode NAcdEventNode;
|
typedef struct NAcdEventNode NAcdEventNode;
|
||||||
|
|
||||||
#define _cleanup_(_x) __attribute__((__cleanup__(_x)))
|
|
||||||
#define _public_ __attribute__((__visibility__("default")))
|
|
||||||
|
|
||||||
/* This augments the error-codes with internal ones that are never exposed. */
|
/* This augments the error-codes with internal ones that are never exposed. */
|
||||||
enum {
|
enum {
|
||||||
_N_ACD_INTERNAL = _N_ACD_E_N,
|
_N_ACD_INTERNAL = _N_ACD_E_N,
|
||||||
@@ -150,23 +148,7 @@ int n_acd_bpf_compile(int *progfdp, int mapfd, struct ether_addr *mac);
|
|||||||
|
|
||||||
/* inline helpers */
|
/* inline helpers */
|
||||||
|
|
||||||
static inline int n_acd_errno(void) {
|
|
||||||
/*
|
|
||||||
* Compilers continuously warn about uninitialized variables since they
|
|
||||||
* cannot deduce that `return -errno;` will always be negative. This
|
|
||||||
* small wrapper makes sure compilers figure that out. Use it as
|
|
||||||
* replacement for `errno` read access. Yes, it generates worse code,
|
|
||||||
* but only marginally and only affects slow-paths.
|
|
||||||
*/
|
|
||||||
return abs(errno) ? : EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void n_acd_event_node_freep(NAcdEventNode **node) {
|
static inline void n_acd_event_node_freep(NAcdEventNode **node) {
|
||||||
if (*node)
|
if (*node)
|
||||||
n_acd_event_node_free(*node);
|
n_acd_event_node_free(*node);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void n_acd_closep(int *fdp) {
|
|
||||||
if (*fdp >= 0)
|
|
||||||
close(*fdp);
|
|
||||||
}
|
|
||||||
|
@@ -1,9 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* IPv4 Address Conflict Detection
|
* IPv4 Address Conflict Detection
|
||||||
|
*
|
||||||
|
* This file implements the probe object. A probe is basically the
|
||||||
|
* state-machine of a single ACD run. It takes an address to probe for, checks
|
||||||
|
* for conflicts and then defends it once configured.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <c-rbtree.h>
|
#include <c-rbtree.h>
|
||||||
|
#include <c-stdaux.h>
|
||||||
#include <endian.h>
|
#include <endian.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
@@ -19,8 +24,8 @@
|
|||||||
#include "n-acd-private.h"
|
#include "n-acd-private.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These parameters and timing intervals specified in RFC-5227. The original
|
* These parameters and timing intervals are specified in RFC-5227. The
|
||||||
* values are:
|
* original values are:
|
||||||
*
|
*
|
||||||
* PROBE_NUM 3
|
* PROBE_NUM 3
|
||||||
* PROBE_WAIT 1s
|
* PROBE_WAIT 1s
|
||||||
@@ -66,10 +71,19 @@
|
|||||||
#define N_ACD_RFC_DEFEND_INTERVAL_NSEC (UINT64_C(10000000000)) /* 10s */
|
#define N_ACD_RFC_DEFEND_INTERVAL_NSEC (UINT64_C(10000000000)) /* 10s */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XXX
|
* n_acd_probe_config_new() - create probe configuration
|
||||||
|
* @configp: output argument for new probe configuration
|
||||||
|
*
|
||||||
|
* This creates a new probe configuration. It will be returned in @configp to
|
||||||
|
* the caller, which upon return fully owns the object.
|
||||||
|
*
|
||||||
|
* A probe configuration collects parameters for probes. It never validates the
|
||||||
|
* input, but this is left to the consumer of the configuration to do.
|
||||||
|
*
|
||||||
|
* Return: 0 on success, negative error code on failure.
|
||||||
*/
|
*/
|
||||||
_public_ int n_acd_probe_config_new(NAcdProbeConfig **configp) {
|
_c_public_ int n_acd_probe_config_new(NAcdProbeConfig **configp) {
|
||||||
_cleanup_(n_acd_probe_config_freep) NAcdProbeConfig *config = NULL;
|
_c_cleanup_(n_acd_probe_config_freep) NAcdProbeConfig *config = NULL;
|
||||||
|
|
||||||
config = malloc(sizeof(*config));
|
config = malloc(sizeof(*config));
|
||||||
if (!config)
|
if (!config)
|
||||||
@@ -83,9 +97,15 @@ _public_ int n_acd_probe_config_new(NAcdProbeConfig **configp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XXX
|
* n_acd_probe_config_free() - destroy probe configuration
|
||||||
|
* @config: configuration to operate on, or NULL
|
||||||
|
*
|
||||||
|
* This destroys the probe configuration and all associated objects. If @config
|
||||||
|
* is NULL, this is a no-op.
|
||||||
|
*
|
||||||
|
* Return: NULL is returned.
|
||||||
*/
|
*/
|
||||||
_public_ NAcdProbeConfig *n_acd_probe_config_free(NAcdProbeConfig *config) {
|
_c_public_ NAcdProbeConfig *n_acd_probe_config_free(NAcdProbeConfig *config) {
|
||||||
if (!config)
|
if (!config)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -95,16 +115,45 @@ _public_ NAcdProbeConfig *n_acd_probe_config_free(NAcdProbeConfig *config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XXX
|
* n_acd_probe_config_set_ip() - set ip property
|
||||||
|
* @config: configuration to operate on
|
||||||
|
* @ip: ip to set
|
||||||
|
*
|
||||||
|
* This sets the IP property to the value `ip`. The address is copied into the
|
||||||
|
* configuration object. No validation is performed.
|
||||||
|
*
|
||||||
|
* The IP property selects the IP address that a probe checks for. It is the
|
||||||
|
* caller's responsibility to guarantee the address is valid and can be used.
|
||||||
*/
|
*/
|
||||||
_public_ void n_acd_probe_config_set_ip(NAcdProbeConfig *config, struct in_addr ip) {
|
_c_public_ void n_acd_probe_config_set_ip(NAcdProbeConfig *config, struct in_addr ip) {
|
||||||
config->ip = ip;
|
config->ip = ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XXX
|
* n_acd_probe_config_set_timeout() - set timeout property
|
||||||
|
* @config: configuration to operate on
|
||||||
|
* @msecs: timeout to set, in milliseconds
|
||||||
|
*
|
||||||
|
* This sets the timeout to use for a conflict detection probe. The
|
||||||
|
* specification default is provided as `N_ACD_TIMEOUT_RFC5227` and corresponds
|
||||||
|
* to 9 seconds.
|
||||||
|
*
|
||||||
|
* If set to 0, conflict detection is skipped and the address is immediately
|
||||||
|
* advertised and defended.
|
||||||
|
*
|
||||||
|
* Depending on the transport used, the API user should select a suitable
|
||||||
|
* timeout. Since `ACD` only operates on the link layer, timeouts in the
|
||||||
|
* hundreds of milliseconds range should be more than enough for any modern
|
||||||
|
* network. Note that increasing this value directly affects the time it takes
|
||||||
|
* to connect to a network, since an address should not be used unless conflict
|
||||||
|
* detection finishes.
|
||||||
|
*
|
||||||
|
* Using the specification default is **discouraged**. It is way too slow and
|
||||||
|
* not appropriate for modern networks.
|
||||||
|
*
|
||||||
|
* Default value is `N_ACD_TIMEOUT_RFC5227`.
|
||||||
*/
|
*/
|
||||||
_public_ void n_acd_probe_config_set_timeout(NAcdProbeConfig *config, uint64_t msecs) {
|
_c_public_ void n_acd_probe_config_set_timeout(NAcdProbeConfig *config, uint64_t msecs) {
|
||||||
config->timeout_msecs = msecs;
|
config->timeout_msecs = msecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,14 +263,14 @@ static void n_acd_probe_unlink(NAcdProbe *probe) {
|
|||||||
*/
|
*/
|
||||||
if (n_acd_probe_is_unique(probe)) {
|
if (n_acd_probe_is_unique(probe)) {
|
||||||
r = n_acd_bpf_map_remove(probe->acd->fd_bpf_map, &probe->ip);
|
r = n_acd_bpf_map_remove(probe->acd->fd_bpf_map, &probe->ip);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
--probe->acd->n_bpf_map;
|
--probe->acd->n_bpf_map;
|
||||||
}
|
}
|
||||||
c_rbnode_unlink(&probe->ip_node);
|
c_rbnode_unlink(&probe->ip_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
int n_acd_probe_new(NAcdProbe **probep, NAcd *acd, NAcdProbeConfig *config) {
|
int n_acd_probe_new(NAcdProbe **probep, NAcd *acd, NAcdProbeConfig *config) {
|
||||||
_cleanup_(n_acd_probe_freep) NAcdProbe *probe = NULL;
|
_c_cleanup_(n_acd_probe_freep) NAcdProbe *probe = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!config->ip.s_addr)
|
if (!config->ip.s_addr)
|
||||||
@@ -285,9 +334,20 @@ int n_acd_probe_new(NAcdProbe **probep, NAcd *acd, NAcdProbeConfig *config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XXX
|
* n_acd_probe_free() - destroy a probe
|
||||||
|
* @probe: probe to operate on, or NULL
|
||||||
|
*
|
||||||
|
* This destroys the probe specified by @probe. All operations are immediately
|
||||||
|
* ceded and all associated objects are released.
|
||||||
|
*
|
||||||
|
* If @probe is NULL, this is a no-op.
|
||||||
|
*
|
||||||
|
* This function will flush all events associated with @probe from the event
|
||||||
|
* queue. That is, no events will be returned for this @probe anymore.
|
||||||
|
*
|
||||||
|
* Return: NULL is returned.
|
||||||
*/
|
*/
|
||||||
_public_ NAcdProbe *n_acd_probe_free(NAcdProbe *probe) {
|
_c_public_ NAcdProbe *n_acd_probe_free(NAcdProbe *probe) {
|
||||||
NAcdEventNode *node, *t_node;
|
NAcdEventNode *node, *t_node;
|
||||||
|
|
||||||
if (!probe)
|
if (!probe)
|
||||||
@@ -305,7 +365,7 @@ _public_ NAcdProbe *n_acd_probe_free(NAcdProbe *probe) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int n_acd_probe_raise(NAcdProbe *probe, NAcdEventNode **nodep, unsigned int event) {
|
int n_acd_probe_raise(NAcdProbe *probe, NAcdEventNode **nodep, unsigned int event) {
|
||||||
_cleanup_(n_acd_event_node_freep) NAcdEventNode *node = NULL;
|
_c_cleanup_(n_acd_event_node_freep) NAcdEventNode *node = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = n_acd_raise(probe->acd, &node, event);
|
r = n_acd_raise(probe->acd, &node, event);
|
||||||
@@ -326,8 +386,8 @@ int n_acd_probe_raise(NAcdProbe *probe, NAcdEventNode **nodep, unsigned int even
|
|||||||
node->event.conflict.probe = probe;
|
node->event.conflict.probe = probe;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
c_assert(0);
|
||||||
return -EIO;
|
return -ENOTRECOVERABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
c_list_link_tail(&probe->event_list, &node->probe_link);
|
c_list_link_tail(&probe->event_list, &node->probe_link);
|
||||||
@@ -450,8 +510,8 @@ int n_acd_probe_handle_timeout(NAcdProbe *probe) {
|
|||||||
* There are no timeouts in these states. If we trigger one,
|
* There are no timeouts in these states. If we trigger one,
|
||||||
* something is fishy.
|
* something is fishy.
|
||||||
*/
|
*/
|
||||||
assert(0);
|
c_assert(0);
|
||||||
return -EIO;
|
return -ENOTRECOVERABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -582,31 +642,47 @@ int n_acd_probe_handle_packet(NAcdProbe *probe, struct ether_arp *packet, bool h
|
|||||||
* We are not listening for packets in these states. If we receive one,
|
* We are not listening for packets in these states. If we receive one,
|
||||||
* something is fishy.
|
* something is fishy.
|
||||||
*/
|
*/
|
||||||
assert(0);
|
c_assert(0);
|
||||||
return -EIO;
|
return -ENOTRECOVERABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* n_acd_probe_set_userdata - XXX
|
* n_acd_probe_set_userdata - set userdata
|
||||||
|
* @probe: probe to operate on
|
||||||
|
* @userdata: userdata pointer
|
||||||
|
*
|
||||||
|
* This can be used to set a caller-controlled user-data pointer on @probe. The
|
||||||
|
* value of the pointer is never inspected or used by `n-acd` and is fully
|
||||||
|
* under control of the caller.
|
||||||
|
*
|
||||||
|
* The default value is NULL.
|
||||||
*/
|
*/
|
||||||
_public_ void n_acd_probe_set_userdata(NAcdProbe *probe, void *userdata) {
|
_c_public_ void n_acd_probe_set_userdata(NAcdProbe *probe, void *userdata) {
|
||||||
probe->userdata = userdata;
|
probe->userdata = userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* n_acd_probe_get_userdata - XXX
|
* n_acd_probe_get_userdata - get userdata
|
||||||
|
* @probe: probe to operate on
|
||||||
|
*
|
||||||
|
* This queries the userdata pointer that was previously set through
|
||||||
|
* n_acd_probe_set_userdata().
|
||||||
|
*
|
||||||
|
* The default value is NULL.
|
||||||
|
*
|
||||||
|
* Return: The stored userdata pointer is returned.
|
||||||
*/
|
*/
|
||||||
_public_ void n_acd_probe_get_userdata(NAcdProbe *probe, void **userdatap) {
|
_c_public_ void n_acd_probe_get_userdata(NAcdProbe *probe, void **userdatap) {
|
||||||
*userdatap = probe->userdata;
|
*userdatap = probe->userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* n_acd_probe_announce() - announce the configured IP address
|
* n_acd_probe_announce() - announce the configured IP address
|
||||||
* @probe: probe object
|
* @probe: probe to operate on
|
||||||
* @defend: defence policy
|
* @defend: defence policy
|
||||||
*
|
*
|
||||||
* Announce the IP address on the local link, and start defending it according
|
* Announce the IP address on the local link, and start defending it according
|
||||||
* to the given policy, which mut be one of N_ACD_DEFEND_ONCE,
|
* to the given policy, which mut be one of N_ACD_DEFEND_ONCE,
|
||||||
@@ -618,7 +694,7 @@ _public_ void n_acd_probe_get_userdata(NAcdProbe *probe, void **userdatap) {
|
|||||||
* Return: 0 on success, N_ACD_E_INVALID_ARGUMENT in case the defence policy
|
* Return: 0 on success, N_ACD_E_INVALID_ARGUMENT in case the defence policy
|
||||||
* is invalid, negative error code on failure.
|
* is invalid, negative error code on failure.
|
||||||
*/
|
*/
|
||||||
_public_ int n_acd_probe_announce(NAcdProbe *probe, unsigned int defend) {
|
_c_public_ int n_acd_probe_announce(NAcdProbe *probe, unsigned int defend) {
|
||||||
if (defend >= _N_ACD_DEFEND_N)
|
if (defend >= _N_ACD_DEFEND_N)
|
||||||
return N_ACD_E_INVALID_ARGUMENT;
|
return N_ACD_E_INVALID_ARGUMENT;
|
||||||
|
|
||||||
|
264
src/n-acd.c
264
src/n-acd.c
@@ -1,11 +1,56 @@
|
|||||||
/*
|
/*
|
||||||
* IPv4 Address Conflict Detection
|
* IPv4 Address Conflict Detection
|
||||||
|
*
|
||||||
|
* This file contains the main context initialization and management functions,
|
||||||
|
* as well as a bunch of utilities used through the n-acd modules.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DOC: IPv4 Address Conflict Detection
|
||||||
|
*
|
||||||
|
* The `n-acd` project implements the IPv4 Address Conflict Detection protocol
|
||||||
|
* as defined in RFC-5227. The protocol originates in the IPv4 Link Local
|
||||||
|
* Address selection but was later on generalized and resulted in `ACD`. The
|
||||||
|
* idea is to use `ARP` to query a link for an address to see whether it
|
||||||
|
* already exists on the network, as well as defending an address that is in
|
||||||
|
* use on a network interface. Furthermore, `ACD` provides passive diagnostics
|
||||||
|
* for administrators, as it will detect address conflicts automatically, which
|
||||||
|
* then can be logged or shown to a user.
|
||||||
|
*
|
||||||
|
* The main context object of `n-acd` is the `NAcd` structure. It is a passive
|
||||||
|
* ref-counted context object which drives `ACD` probes running on it. A
|
||||||
|
* context is specific to a linux network device and transport. If multiple
|
||||||
|
* network devices are used, then separate `NAcd` contexts must be deployed.
|
||||||
|
*
|
||||||
|
* The `NAcdProbe` object drives a single `ACD` state-machine. A probe is
|
||||||
|
* created on an `NAcd` context by providing an address to probe for. The probe
|
||||||
|
* will then raise notifications whether the address conflict detection found
|
||||||
|
* something, or whether the address is ready to be used. Optionally, the probe
|
||||||
|
* will then enter into passive mode and defend the address as long as it is
|
||||||
|
* kept active.
|
||||||
|
*
|
||||||
|
* Note that the `n-acd` project only implements the networking protocol. It
|
||||||
|
* never queries or modifies network interfaces. It completely relies on the
|
||||||
|
* API user to react to notifications and update network interfaces
|
||||||
|
* respectively. `n-acd` uses an event-mechanism on every context object. All
|
||||||
|
* events raise by any probe or operation on a given context will queue all
|
||||||
|
* events on that context object. The event-queue can then be drained by the
|
||||||
|
* API user. All events are properly asynchronous and designed in a way that no
|
||||||
|
* synchronous reaction to any event is required. That is, the events are
|
||||||
|
* carefully designed to allow forwarding via IPC (or even networks) to a
|
||||||
|
* controller that handles them and specifies how to react. Furthermore, none
|
||||||
|
* of the function calls of `n-acd` require synchronous error handling.
|
||||||
|
* Instead, functions only ever return values on fatal errors. Everything else
|
||||||
|
* is queued as events, thus guaranteeing that synchronous handling of return
|
||||||
|
* values is not required. Exceptions are functions that do not affect internal
|
||||||
|
* state or do not have an associated context object.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <c-list.h>
|
#include <c-list.h>
|
||||||
#include <c-rbtree.h>
|
#include <c-rbtree.h>
|
||||||
#include <c-siphash.h>
|
#include <c-siphash.h>
|
||||||
|
#include <c-stdaux.h>
|
||||||
#include <endian.h>
|
#include <endian.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
@@ -55,7 +100,7 @@ static int n_acd_get_random(unsigned int *random) {
|
|||||||
|
|
||||||
r = clock_gettime(CLOCK_MONOTONIC, &ts);
|
r = clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return -n_acd_errno();
|
return -c_errno();
|
||||||
|
|
||||||
c_siphash_append(&hash, (const uint8_t *)&ts.tv_sec, sizeof(ts.tv_sec));
|
c_siphash_append(&hash, (const uint8_t *)&ts.tv_sec, sizeof(ts.tv_sec));
|
||||||
c_siphash_append(&hash, (const uint8_t *)&ts.tv_nsec, sizeof(ts.tv_nsec));
|
c_siphash_append(&hash, (const uint8_t *)&ts.tv_nsec, sizeof(ts.tv_nsec));
|
||||||
@@ -76,19 +121,19 @@ static int n_acd_socket_new(int *fdp, int fd_bpf_prog, NAcdConfig *config) {
|
|||||||
|
|
||||||
s = socket(PF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
|
s = socket(PF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
|
||||||
if (s < 0) {
|
if (s < 0) {
|
||||||
r = -n_acd_errno();
|
r = -c_errno();
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd_bpf_prog >= 0) {
|
if (fd_bpf_prog >= 0) {
|
||||||
r = setsockopt(s, SOL_SOCKET, SO_ATTACH_BPF, &fd_bpf_prog, sizeof(fd_bpf_prog));
|
r = setsockopt(s, SOL_SOCKET, SO_ATTACH_BPF, &fd_bpf_prog, sizeof(fd_bpf_prog));
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return -n_acd_errno();
|
return -c_errno();
|
||||||
}
|
}
|
||||||
|
|
||||||
r = bind(s, (struct sockaddr *)&address, sizeof(address));
|
r = bind(s, (struct sockaddr *)&address, sizeof(address));
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
r = -n_acd_errno();
|
r = -c_errno();
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,10 +148,21 @@ error:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XXX
|
* n_acd_config_new() - create configuration object
|
||||||
|
* @configp: output argument for new configuration
|
||||||
|
*
|
||||||
|
* This creates a new configuration object and provides it to the caller. The
|
||||||
|
* object is fully owned by the caller upon function return.
|
||||||
|
*
|
||||||
|
* A configuration object is a passive structure that is used to collect
|
||||||
|
* information that is then passed to a constructor or other function. A
|
||||||
|
* configuration never validates the data, but it is up to the consumer of a
|
||||||
|
* configuration to do that.
|
||||||
|
*
|
||||||
|
* Return: 0 on success, negative error code on failure.
|
||||||
*/
|
*/
|
||||||
_public_ int n_acd_config_new(NAcdConfig **configp) {
|
_c_public_ int n_acd_config_new(NAcdConfig **configp) {
|
||||||
_cleanup_(n_acd_config_freep) NAcdConfig *config = NULL;
|
_c_cleanup_(n_acd_config_freep) NAcdConfig *config = NULL;
|
||||||
|
|
||||||
config = malloc(sizeof(*config));
|
config = malloc(sizeof(*config));
|
||||||
if (!config)
|
if (!config)
|
||||||
@@ -120,9 +176,15 @@ _public_ int n_acd_config_new(NAcdConfig **configp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XXX
|
* n_acd_config_free() - destroy configuration object
|
||||||
|
* @config: configuration to operate on, or NULL
|
||||||
|
*
|
||||||
|
* This destroys the configuration object @config. If @config is NULL, this is
|
||||||
|
* a no-op.
|
||||||
|
*
|
||||||
|
* Return: NULL is returned.
|
||||||
*/
|
*/
|
||||||
_public_ NAcdConfig *n_acd_config_free(NAcdConfig *config) {
|
_c_public_ NAcdConfig *n_acd_config_free(NAcdConfig *config) {
|
||||||
if (!config)
|
if (!config)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -132,23 +194,55 @@ _public_ NAcdConfig *n_acd_config_free(NAcdConfig *config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XXX
|
* n_acd_config_set_ifindex() - set ifindex property
|
||||||
|
* @config: configuration to operate on
|
||||||
|
* @ifindex: ifindex to set
|
||||||
|
*
|
||||||
|
* This sets the @ifindex property of the configuration object. Any previous
|
||||||
|
* value is overwritten.
|
||||||
|
*
|
||||||
|
* A valid ifindex is a 32bit integer greater than 0. Any other value is
|
||||||
|
* treated as unspecified.
|
||||||
|
*
|
||||||
|
* The ifindex corresponds to the interface index provided by the linux kernel.
|
||||||
|
* It specifies the network device to be used.
|
||||||
*/
|
*/
|
||||||
_public_ void n_acd_config_set_ifindex(NAcdConfig *config, int ifindex) {
|
_c_public_ void n_acd_config_set_ifindex(NAcdConfig *config, int ifindex) {
|
||||||
config->ifindex = ifindex;
|
config->ifindex = ifindex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XXX
|
* n_acd_config_set_transport() - set transport property
|
||||||
|
* @config: configuration to operate on
|
||||||
|
* @transport: transport to set
|
||||||
|
*
|
||||||
|
* This specifies the transport to use. A transport must be one of the
|
||||||
|
* `N_ACD_TRANSPORT_*` identifiers. It selects which transport protocol `n-acd`
|
||||||
|
* will run on.
|
||||||
*/
|
*/
|
||||||
_public_ void n_acd_config_set_transport(NAcdConfig *config, unsigned int transport) {
|
_c_public_ void n_acd_config_set_transport(NAcdConfig *config, unsigned int transport) {
|
||||||
config->transport = transport;
|
config->transport = transport;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XXX
|
* n_acd_config_set_mac() - set mac property
|
||||||
|
* @config: configuration to operate on
|
||||||
|
* @mac: mac to set
|
||||||
|
*
|
||||||
|
* This specifies the hardware address (also referred to as `MAC Address`) to
|
||||||
|
* use. Any hardware address can be specified. It is the caller's
|
||||||
|
* responsibility to make sure the address can actually be used.
|
||||||
|
*
|
||||||
|
* The address in @mac is copied into @config. It does not have to be retained
|
||||||
|
* by the caller.
|
||||||
*/
|
*/
|
||||||
_public_ void n_acd_config_set_mac(NAcdConfig *config, const uint8_t *mac, size_t n_mac) {
|
_c_public_ void n_acd_config_set_mac(NAcdConfig *config, const uint8_t *mac, size_t n_mac) {
|
||||||
|
/*
|
||||||
|
* We truncate the address at the maximum we support. We still remember
|
||||||
|
* the original length, so any consumer of this configuration can then
|
||||||
|
* complain about an unsupported address length. This allows us to
|
||||||
|
* avoid a memory allocation here and having to return `int`.
|
||||||
|
*/
|
||||||
config->n_mac = n_mac;
|
config->n_mac = n_mac;
|
||||||
memcpy(config->mac, mac, n_mac > ETH_ALEN ? ETH_ALEN : n_mac);
|
memcpy(config->mac, mac, n_mac > ETH_ALEN ? ETH_ALEN : n_mac);
|
||||||
}
|
}
|
||||||
@@ -179,7 +273,7 @@ NAcdEventNode *n_acd_event_node_free(NAcdEventNode *node) {
|
|||||||
|
|
||||||
int n_acd_ensure_bpf_map_space(NAcd *acd) {
|
int n_acd_ensure_bpf_map_space(NAcd *acd) {
|
||||||
NAcdProbe *probe;
|
NAcdProbe *probe;
|
||||||
_cleanup_(n_acd_closep) int fd_map = -1, fd_prog = -1;
|
_c_cleanup_(c_closep) int fd_map = -1, fd_prog = -1;
|
||||||
size_t max_map;
|
size_t max_map;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
@@ -205,7 +299,7 @@ int n_acd_ensure_bpf_map_space(NAcd *acd) {
|
|||||||
if (fd_prog >= 0) {
|
if (fd_prog >= 0) {
|
||||||
r = setsockopt(acd->fd_socket, SOL_SOCKET, SO_ATTACH_BPF, &fd_prog, sizeof(fd_prog));
|
r = setsockopt(acd->fd_socket, SOL_SOCKET, SO_ATTACH_BPF, &fd_prog, sizeof(fd_prog));
|
||||||
if (r)
|
if (r)
|
||||||
return -n_acd_errno();
|
return -c_errno();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (acd->fd_bpf_map >= 0)
|
if (acd->fd_bpf_map >= 0)
|
||||||
@@ -218,16 +312,20 @@ int n_acd_ensure_bpf_map_space(NAcd *acd) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* n_acd_new() - create a new ACD context
|
* n_acd_new() - create a new ACD context
|
||||||
* @acdp: output argument for context
|
* @acdp: output argument for new context object
|
||||||
* @config: configuration parameters
|
* @config: configuration parameters
|
||||||
*
|
*
|
||||||
* Create a new ACD context and return it in @acdp.
|
* Create a new ACD context and return it in @acdp. The configuration @config
|
||||||
|
* must be initialized by the caller and must specify a valid network
|
||||||
|
* interface, transport mechanism, as well as hardware address compatible with
|
||||||
|
* the selected transport. The configuration is copied into the context. The
|
||||||
|
* @config object thus does not have to be retained by the caller.
|
||||||
*
|
*
|
||||||
* Return: 0 on success, or a negative error code on failure.
|
* Return: 0 on success, negative error code on failure.
|
||||||
*/
|
*/
|
||||||
_public_ int n_acd_new(NAcd **acdp, NAcdConfig *config) {
|
_c_public_ int n_acd_new(NAcd **acdp, NAcdConfig *config) {
|
||||||
_cleanup_(n_acd_unrefp) NAcd *acd = NULL;
|
_c_cleanup_(n_acd_unrefp) NAcd *acd = NULL;
|
||||||
_cleanup_(n_acd_closep) int fd_bpf_prog = -1;
|
_c_cleanup_(c_closep) int fd_bpf_prog = -1;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (config->ifindex <= 0 ||
|
if (config->ifindex <= 0 ||
|
||||||
@@ -250,7 +348,7 @@ _public_ int n_acd_new(NAcd **acdp, NAcdConfig *config) {
|
|||||||
|
|
||||||
acd->fd_epoll = epoll_create1(EPOLL_CLOEXEC);
|
acd->fd_epoll = epoll_create1(EPOLL_CLOEXEC);
|
||||||
if (acd->fd_epoll < 0)
|
if (acd->fd_epoll < 0)
|
||||||
return -n_acd_errno();
|
return -c_errno();
|
||||||
|
|
||||||
r = timer_init(&acd->timer);
|
r = timer_init(&acd->timer);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@@ -276,7 +374,7 @@ _public_ int n_acd_new(NAcd **acdp, NAcdConfig *config) {
|
|||||||
.data.u32 = N_ACD_EPOLL_TIMER,
|
.data.u32 = N_ACD_EPOLL_TIMER,
|
||||||
});
|
});
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return -n_acd_errno();
|
return -c_errno();
|
||||||
|
|
||||||
r = epoll_ctl(acd->fd_epoll, EPOLL_CTL_ADD, acd->fd_socket,
|
r = epoll_ctl(acd->fd_epoll, EPOLL_CTL_ADD, acd->fd_socket,
|
||||||
&(struct epoll_event){
|
&(struct epoll_event){
|
||||||
@@ -284,14 +382,14 @@ _public_ int n_acd_new(NAcd **acdp, NAcdConfig *config) {
|
|||||||
.data.u32 = N_ACD_EPOLL_SOCKET,
|
.data.u32 = N_ACD_EPOLL_SOCKET,
|
||||||
});
|
});
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return -n_acd_errno();
|
return -c_errno();
|
||||||
|
|
||||||
*acdp = acd;
|
*acdp = acd;
|
||||||
acd = NULL;
|
acd = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void n_acd_free(NAcd *acd) {
|
static void n_acd_free_internal(NAcd *acd) {
|
||||||
NAcdEventNode *node, *t_node;
|
NAcdEventNode *node, *t_node;
|
||||||
|
|
||||||
if (!acd)
|
if (!acd)
|
||||||
@@ -300,10 +398,10 @@ static void n_acd_free(NAcd *acd) {
|
|||||||
c_list_for_each_entry_safe(node, t_node, &acd->event_list, acd_link)
|
c_list_for_each_entry_safe(node, t_node, &acd->event_list, acd_link)
|
||||||
n_acd_event_node_free(node);
|
n_acd_event_node_free(node);
|
||||||
|
|
||||||
assert(c_rbtree_is_empty(&acd->ip_tree));
|
c_assert(c_rbtree_is_empty(&acd->ip_tree));
|
||||||
|
|
||||||
if (acd->fd_socket >= 0) {
|
if (acd->fd_socket >= 0) {
|
||||||
assert(acd->fd_epoll >= 0);
|
c_assert(acd->fd_epoll >= 0);
|
||||||
epoll_ctl(acd->fd_epoll, EPOLL_CTL_DEL, acd->fd_socket, NULL);
|
epoll_ctl(acd->fd_epoll, EPOLL_CTL_DEL, acd->fd_socket, NULL);
|
||||||
close(acd->fd_socket);
|
close(acd->fd_socket);
|
||||||
acd->fd_socket = -1;
|
acd->fd_socket = -1;
|
||||||
@@ -315,7 +413,7 @@ static void n_acd_free(NAcd *acd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (acd->timer.fd >= 0) {
|
if (acd->timer.fd >= 0) {
|
||||||
assert(acd->fd_epoll >= 0);
|
c_assert(acd->fd_epoll >= 0);
|
||||||
epoll_ctl(acd->fd_epoll, EPOLL_CTL_DEL, acd->timer.fd, NULL);
|
epoll_ctl(acd->fd_epoll, EPOLL_CTL_DEL, acd->timer.fd, NULL);
|
||||||
timer_deinit(&acd->timer);
|
timer_deinit(&acd->timer);
|
||||||
}
|
}
|
||||||
@@ -329,20 +427,32 @@ static void n_acd_free(NAcd *acd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XXX
|
* n_acd_ref() - acquire reference
|
||||||
|
* @acd: context to operate on, or NULL
|
||||||
|
*
|
||||||
|
* This acquires a single reference to the context specified as @acd. If @acd
|
||||||
|
* is NULL, this is a no-op.
|
||||||
|
*
|
||||||
|
* Return: @acd is returned.
|
||||||
*/
|
*/
|
||||||
_public_ NAcd *n_acd_ref(NAcd *acd) {
|
_c_public_ NAcd *n_acd_ref(NAcd *acd) {
|
||||||
if (acd)
|
if (acd)
|
||||||
++acd->n_refs;
|
++acd->n_refs;
|
||||||
return acd;
|
return acd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XXX
|
* n_acd_unref() - release reference
|
||||||
|
* @acd: context to operate on, or NULL
|
||||||
|
*
|
||||||
|
* This releases a single reference to the context @acd. If this is the last
|
||||||
|
* reference, the context is torn down and deallocated.
|
||||||
|
*
|
||||||
|
* Return: NULL is returned.
|
||||||
*/
|
*/
|
||||||
_public_ NAcd *n_acd_unref(NAcd *acd) {
|
_c_public_ NAcd *n_acd_unref(NAcd *acd) {
|
||||||
if (acd && !--acd->n_refs)
|
if (acd && !--acd->n_refs)
|
||||||
n_acd_free(acd);
|
n_acd_free_internal(acd);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,7 +536,7 @@ int n_acd_send(NAcd *acd, const struct in_addr *tpa, const struct in_addr *spa)
|
|||||||
* Random network error. We treat this as fatal and propagate
|
* Random network error. We treat this as fatal and propagate
|
||||||
* the error, so it is noticed and can be investigated.
|
* the error, so it is noticed and can be investigated.
|
||||||
*/
|
*/
|
||||||
return -n_acd_errno();
|
return -c_errno();
|
||||||
} else if (l != (ssize_t)sizeof(arp)) {
|
} else if (l != (ssize_t)sizeof(arp)) {
|
||||||
/*
|
/*
|
||||||
* Ugh, the kernel modified the packet. This is unexpected. We
|
* Ugh, the kernel modified the packet. This is unexpected. We
|
||||||
@@ -440,13 +550,22 @@ int n_acd_send(NAcd *acd, const struct in_addr *tpa, const struct in_addr *spa)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* n_acd_get_fd() - get pollable file descriptor
|
* n_acd_get_fd() - get pollable file descriptor
|
||||||
* @acd: ACD context
|
* @acd: context object to operate on
|
||||||
* @fdp: output argument for file descriptor
|
* @fdp: output argument for file descriptor
|
||||||
*
|
*
|
||||||
* Returns a file descriptor in @fdp. This file descriptor can be polled by
|
* This returns the backing file-descriptor of the context object @acd. The
|
||||||
* the caller to indicate when the ACD context can be dispatched.
|
* file-descriptor is owned by @acd and valid as long as @acd is. The
|
||||||
|
* file-descriptor never changes, so it can be cached by the caller as long as
|
||||||
|
* they hold a reference to @acd.
|
||||||
|
*
|
||||||
|
* The file-descriptor is internal to the @acd context and should not be
|
||||||
|
* modified by the caller. It is only exposed to allow the caller to poll on
|
||||||
|
* it. Whenever the file-descriptor polls readable, n_acd_dispatch() should be
|
||||||
|
* called.
|
||||||
|
*
|
||||||
|
* Currently, the file-descriptor is an epoll-fd.
|
||||||
*/
|
*/
|
||||||
_public_ void n_acd_get_fd(NAcd *acd, int *fdp) {
|
_c_public_ void n_acd_get_fd(NAcd *acd, int *fdp) {
|
||||||
*fdp = acd->fd_epoll;
|
*fdp = acd->fd_epoll;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -597,7 +716,7 @@ static int n_acd_dispatch_timer(NAcd *acd, struct epoll_event *event) {
|
|||||||
if (r <= 0)
|
if (r <= 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
assert(r == TIMER_E_TRIGGERED);
|
c_assert(r == TIMER_E_TRIGGERED);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A timer triggered, handle all pending timeouts at a given
|
* A timer triggered, handle all pending timeouts at a given
|
||||||
@@ -710,7 +829,7 @@ static int n_acd_dispatch_socket(NAcd *acd, struct epoll_event *event) {
|
|||||||
* Something went wrong. Propagate the error-code, so
|
* Something went wrong. Propagate the error-code, so
|
||||||
* this can be investigated.
|
* this can be investigated.
|
||||||
*/
|
*/
|
||||||
return -n_acd_errno();
|
return -c_errno();
|
||||||
}
|
}
|
||||||
} else if (n >= (ssize_t)n_batch) {
|
} else if (n >= (ssize_t)n_batch) {
|
||||||
/*
|
/*
|
||||||
@@ -750,16 +869,34 @@ static int n_acd_dispatch_socket(NAcd *acd, struct epoll_event *event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XXX
|
* n_acd_dispatch() - dispatch context
|
||||||
|
* @acd: context object to operate on
|
||||||
|
*
|
||||||
|
* This dispatches the internal state-machine of all probes and operations
|
||||||
|
* running on the context @acd.
|
||||||
|
*
|
||||||
|
* Any outside effect or event triggered by this dispatcher will be queued on
|
||||||
|
* the event-queue of @acd. Whenever the dispatcher returns, the caller is
|
||||||
|
* required to drain the event-queue via n_acd_pop_event() until it is empty.
|
||||||
|
*
|
||||||
|
* This function dispatches as many events as possible up to a static limit to
|
||||||
|
* prevent stalling execution. If the static limit is reached, this function
|
||||||
|
* will return with N_ACD_E_PREEMPTED, otherwise 0 is returned. In most cases
|
||||||
|
* preemption can be ignored, because level-triggered event notification
|
||||||
|
* handles it automatically. However, in case of edge-triggered event
|
||||||
|
* mechanisms, the caller must make sure to call the dispatcher again.
|
||||||
|
*
|
||||||
|
* Return: 0 on success, N_ACD_E_PREEMPTED on preemption, negative error code
|
||||||
|
* on failure.
|
||||||
*/
|
*/
|
||||||
_public_ int n_acd_dispatch(NAcd *acd) {
|
_c_public_ int n_acd_dispatch(NAcd *acd) {
|
||||||
struct epoll_event events[2];
|
struct epoll_event events[2];
|
||||||
int n, i, r = 0;
|
int n, i, r = 0;
|
||||||
|
|
||||||
n = epoll_wait(acd->fd_epoll, events, sizeof(events) / sizeof(*events), 0);
|
n = epoll_wait(acd->fd_epoll, events, sizeof(events) / sizeof(*events), 0);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
/* Linux never returns EINTR if `timeout == 0'. */
|
/* Linux never returns EINTR if `timeout == 0'. */
|
||||||
return -n_acd_errno();
|
return -c_errno();
|
||||||
}
|
}
|
||||||
|
|
||||||
acd->preempted = false;
|
acd->preempted = false;
|
||||||
@@ -773,7 +910,7 @@ _public_ int n_acd_dispatch(NAcd *acd) {
|
|||||||
r = n_acd_dispatch_socket(acd, events + i);
|
r = n_acd_dispatch_socket(acd, events + i);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
c_assert(0);
|
||||||
r = 0;
|
r = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -787,8 +924,8 @@ _public_ int n_acd_dispatch(NAcd *acd) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* n_acd_pop_event() - get the next pending event
|
* n_acd_pop_event() - get the next pending event
|
||||||
* @acd: ACD context
|
* @acd: context object to operate on
|
||||||
* @eventp: output argument for the event
|
* @eventp: output argument for the event
|
||||||
*
|
*
|
||||||
* Returns a pointer to the next pending event. The event is still owend by
|
* Returns a pointer to the next pending event. The event is still owend by
|
||||||
* the context, and is only valid until the next call to n_acd_pop_event()
|
* the context, and is only valid until the next call to n_acd_pop_event()
|
||||||
@@ -840,7 +977,7 @@ _public_ int n_acd_dispatch(NAcd *acd) {
|
|||||||
* @eventp and 0 is returned. If an error is returned, @eventp is left
|
* @eventp and 0 is returned. If an error is returned, @eventp is left
|
||||||
* untouched.
|
* untouched.
|
||||||
*/
|
*/
|
||||||
_public_ int n_acd_pop_event(NAcd *acd, NAcdEvent **eventp) {
|
_c_public_ int n_acd_pop_event(NAcd *acd, NAcdEvent **eventp) {
|
||||||
NAcdEventNode *node, *t_node;
|
NAcdEventNode *node, *t_node;
|
||||||
|
|
||||||
c_list_for_each_entry_safe(node, t_node, &acd->event_list, acd_link) {
|
c_list_for_each_entry_safe(node, t_node, &acd->event_list, acd_link) {
|
||||||
@@ -859,8 +996,29 @@ _public_ int n_acd_pop_event(NAcd *acd, NAcdEvent **eventp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XXX
|
* n_acd_probe() - start new probe
|
||||||
|
* @acd: context object to operate on
|
||||||
|
* @probep: output argument for new probe
|
||||||
|
* @config: probe configuration
|
||||||
|
*
|
||||||
|
* This creates a new probe on the context @acd and returns the probe in
|
||||||
|
* @probep. The configuration @config must provide valid probe parameters. At
|
||||||
|
* least a valid IP address must be provided through the configuration.
|
||||||
|
*
|
||||||
|
* This function does not reject duplicate probes for the same address. It is
|
||||||
|
* the caller's decision whether duplicates are allowed or not. But note that
|
||||||
|
* duplicate probes on the same context will not conflict each other. That is,
|
||||||
|
* running a probe for the same address twice on the same context will not
|
||||||
|
* cause them to consider each other a duplicate.
|
||||||
|
*
|
||||||
|
* Probes are rather lightweight objects. They do not create any
|
||||||
|
* file-descriptors or other kernel objects. Probes always re-use the
|
||||||
|
* infrastructure provided by the context object @acd. This allows running many
|
||||||
|
* probes simultaneously without exhausting resources.
|
||||||
|
*
|
||||||
|
* Return: 0 on success, N_ACD_E_INVALID_ARGUMENT on invalid configuration
|
||||||
|
* parameters, negative error code on failure.
|
||||||
*/
|
*/
|
||||||
_public_ int n_acd_probe(NAcd *acd, NAcdProbe **probep, NAcdProbeConfig *config) {
|
_c_public_ int n_acd_probe(NAcd *acd, NAcdProbe **probep, NAcdProbeConfig *config) {
|
||||||
return n_acd_probe_new(probep, acd, config);
|
return n_acd_probe_new(probep, acd, config);
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,9 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
typedef struct NAcd NAcd;
|
typedef struct NAcd NAcd;
|
||||||
typedef struct NAcdConfig NAcdConfig;
|
typedef struct NAcdConfig NAcdConfig;
|
||||||
|
151
src/test-api.c
151
src/test-api.c
@@ -1,105 +1,88 @@
|
|||||||
/*
|
/*
|
||||||
* Tests for n-acd API
|
* Tests for n-acd API
|
||||||
* This verifies the visibility and availability of the public API of the
|
* This verifies the visibility and availability of the public API.
|
||||||
* n-acd library.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#undef NDEBUG
|
||||||
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "test.h"
|
#include "n-acd.h"
|
||||||
|
|
||||||
static void test_api(void) {
|
static void test_api_constants(void) {
|
||||||
NAcdConfig *config = NULL;
|
assert(1 + N_ACD_TIMEOUT_RFC5227);
|
||||||
NAcd *acd = NULL;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
assert(N_ACD_E_PREEMPTED);
|
assert(1 + _N_ACD_E_SUCCESS);
|
||||||
assert(N_ACD_E_INVALID_ARGUMENT);
|
assert(1 + N_ACD_E_PREEMPTED);
|
||||||
|
assert(1 + N_ACD_E_INVALID_ARGUMENT);
|
||||||
|
assert(1 + _N_ACD_E_N);
|
||||||
|
|
||||||
assert(N_ACD_TRANSPORT_ETHERNET != _N_ACD_TRANSPORT_N);
|
assert(1 + N_ACD_TRANSPORT_ETHERNET);
|
||||||
|
assert(1 + _N_ACD_TRANSPORT_N);
|
||||||
|
|
||||||
assert(N_ACD_EVENT_READY != _N_ACD_EVENT_N);
|
assert(1 + N_ACD_EVENT_READY);
|
||||||
assert(N_ACD_EVENT_USED != _N_ACD_EVENT_N);
|
assert(1 + N_ACD_EVENT_USED);
|
||||||
assert(N_ACD_EVENT_DEFENDED != _N_ACD_EVENT_N);
|
assert(1 + N_ACD_EVENT_DEFENDED);
|
||||||
assert(N_ACD_EVENT_CONFLICT != _N_ACD_EVENT_N);
|
assert(1 + N_ACD_EVENT_CONFLICT);
|
||||||
assert(N_ACD_EVENT_DOWN != _N_ACD_EVENT_N);
|
assert(1 + N_ACD_EVENT_DOWN);
|
||||||
|
assert(1 + _N_ACD_EVENT_N);
|
||||||
|
|
||||||
assert(N_ACD_DEFEND_NEVER != _N_ACD_DEFEND_N);
|
assert(1 + N_ACD_DEFEND_NEVER);
|
||||||
assert(N_ACD_DEFEND_ONCE != _N_ACD_DEFEND_N);
|
assert(1 + N_ACD_DEFEND_ONCE);
|
||||||
assert(N_ACD_DEFEND_ALWAYS != _N_ACD_DEFEND_N);
|
assert(1 + N_ACD_DEFEND_ALWAYS);
|
||||||
|
assert(1 + _N_ACD_DEFEND_N);
|
||||||
|
}
|
||||||
|
|
||||||
n_acd_config_freep(&config);
|
static void test_api_types(void) {
|
||||||
|
assert(sizeof(NAcdEvent*));
|
||||||
|
assert(sizeof(NAcdConfig*));
|
||||||
|
assert(sizeof(NAcdProbeConfig*));
|
||||||
|
assert(sizeof(NAcd*));
|
||||||
|
assert(sizeof(NAcdProbe*));
|
||||||
|
}
|
||||||
|
|
||||||
r = n_acd_config_new(&config);
|
static void test_api_functions(void) {
|
||||||
assert(!r);
|
void *fns[] = {
|
||||||
|
(void *)n_acd_config_new,
|
||||||
|
(void *)n_acd_config_free,
|
||||||
|
(void *)n_acd_config_set_ifindex,
|
||||||
|
(void *)n_acd_config_set_transport,
|
||||||
|
(void *)n_acd_config_set_mac,
|
||||||
|
(void *)n_acd_probe_config_new,
|
||||||
|
(void *)n_acd_probe_config_free,
|
||||||
|
(void *)n_acd_probe_config_set_ip,
|
||||||
|
(void *)n_acd_probe_config_set_timeout,
|
||||||
|
|
||||||
n_acd_config_set_ifindex(config, 1);
|
(void *)n_acd_new,
|
||||||
n_acd_config_set_transport(config, N_ACD_TRANSPORT_ETHERNET);
|
(void *)n_acd_ref,
|
||||||
n_acd_config_set_mac(config, (uint8_t[6]){ }, 6);
|
(void *)n_acd_unref,
|
||||||
|
(void *)n_acd_get_fd,
|
||||||
|
(void *)n_acd_dispatch,
|
||||||
|
(void *)n_acd_pop_event,
|
||||||
|
(void *)n_acd_probe,
|
||||||
|
|
||||||
{
|
(void *)n_acd_probe_free,
|
||||||
NAcdEvent *event;
|
(void *)n_acd_probe_set_userdata,
|
||||||
int fd;
|
(void *)n_acd_probe_get_userdata,
|
||||||
|
(void *)n_acd_probe_announce,
|
||||||
|
|
||||||
n_acd_unrefp(&acd);
|
(void *)n_acd_config_freep,
|
||||||
n_acd_ref(NULL);
|
(void *)n_acd_config_freev,
|
||||||
|
(void *)n_acd_probe_config_freep,
|
||||||
|
(void *)n_acd_probe_config_freev,
|
||||||
|
(void *)n_acd_unrefp,
|
||||||
|
(void *)n_acd_unrefv,
|
||||||
|
(void *)n_acd_probe_freep,
|
||||||
|
(void *)n_acd_probe_freev,
|
||||||
|
};
|
||||||
|
size_t i;
|
||||||
|
|
||||||
r = n_acd_new(&acd, config);
|
for (i = 0; i < sizeof(fns) / sizeof(*fns); ++i)
|
||||||
assert(!r);
|
assert(!!fns[i]);
|
||||||
|
|
||||||
n_acd_get_fd(acd, &fd);
|
|
||||||
n_acd_dispatch(acd);
|
|
||||||
n_acd_pop_event(acd, &event);
|
|
||||||
|
|
||||||
{
|
|
||||||
NAcdProbeConfig *c = NULL;
|
|
||||||
|
|
||||||
n_acd_probe_config_freep(&c);
|
|
||||||
|
|
||||||
r = n_acd_probe_config_new(&c);
|
|
||||||
assert(!r);
|
|
||||||
|
|
||||||
n_acd_probe_config_set_ip(c, (struct in_addr){ 1 });
|
|
||||||
n_acd_probe_config_set_timeout(c, N_ACD_TIMEOUT_RFC5227);
|
|
||||||
|
|
||||||
{
|
|
||||||
NAcdProbe *probe = NULL;
|
|
||||||
void *userdata;
|
|
||||||
|
|
||||||
r = n_acd_probe(acd, &probe, c);
|
|
||||||
assert(!r);
|
|
||||||
|
|
||||||
n_acd_probe_get_userdata(probe, &userdata);
|
|
||||||
assert(userdata == NULL);
|
|
||||||
n_acd_probe_set_userdata(probe, acd);
|
|
||||||
n_acd_probe_get_userdata(probe, &userdata);
|
|
||||||
assert(userdata == acd);
|
|
||||||
|
|
||||||
r = n_acd_probe_announce(probe, N_ACD_DEFEND_ONCE);
|
|
||||||
assert(!r);
|
|
||||||
|
|
||||||
n_acd_probe_free(probe);
|
|
||||||
n_acd_probe_freev(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
n_acd_probe_config_free(c);
|
|
||||||
n_acd_probe_config_freev(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
n_acd_unref(acd);
|
|
||||||
n_acd_unrefv(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
n_acd_config_free(config);
|
|
||||||
n_acd_config_freev(NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
int r;
|
test_api_constants();
|
||||||
|
test_api_types();
|
||||||
r = test_setup();
|
test_api_functions();
|
||||||
if (r)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
test_api();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,9 @@
|
|||||||
* eBPF socket filter tests
|
* eBPF socket filter tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#undef NDEBUG
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <c-stdaux.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <netinet/if_ether.h>
|
#include <netinet/if_ether.h>
|
||||||
@@ -46,23 +48,23 @@ static void test_map(void) {
|
|||||||
struct in_addr addr = { 1 };
|
struct in_addr addr = { 1 };
|
||||||
|
|
||||||
r = n_acd_bpf_map_create(&mapfd, 8);
|
r = n_acd_bpf_map_create(&mapfd, 8);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
assert(mapfd >= 0);
|
c_assert(mapfd >= 0);
|
||||||
|
|
||||||
r = n_acd_bpf_map_remove(mapfd, &addr);
|
r = n_acd_bpf_map_remove(mapfd, &addr);
|
||||||
assert(r == -ENOENT);
|
c_assert(r == -ENOENT);
|
||||||
|
|
||||||
r = n_acd_bpf_map_add(mapfd, &addr);
|
r = n_acd_bpf_map_add(mapfd, &addr);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
r = n_acd_bpf_map_add(mapfd, &addr);
|
r = n_acd_bpf_map_add(mapfd, &addr);
|
||||||
assert(r == -EEXIST);
|
c_assert(r == -EEXIST);
|
||||||
|
|
||||||
r = n_acd_bpf_map_remove(mapfd, &addr);
|
r = n_acd_bpf_map_remove(mapfd, &addr);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
r = n_acd_bpf_map_remove(mapfd, &addr);
|
r = n_acd_bpf_map_remove(mapfd, &addr);
|
||||||
assert(r == -ENOENT);
|
c_assert(r == -ENOENT);
|
||||||
|
|
||||||
close(mapfd);
|
close(mapfd);
|
||||||
}
|
}
|
||||||
@@ -72,10 +74,10 @@ static void verify_success(struct ether_arp *packet, int out_fd, int in_fd) {
|
|||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = send(out_fd, packet, sizeof(struct ether_arp), 0);
|
r = send(out_fd, packet, sizeof(struct ether_arp), 0);
|
||||||
assert(r == sizeof(struct ether_arp));
|
c_assert(r == sizeof(struct ether_arp));
|
||||||
|
|
||||||
r = recv(in_fd, buf, sizeof(buf), 0);
|
r = recv(in_fd, buf, sizeof(buf), 0);
|
||||||
assert(r == sizeof(struct ether_arp));
|
c_assert(r == sizeof(struct ether_arp));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void verify_failure(struct ether_arp *packet, int out_fd, int in_fd) {
|
static void verify_failure(struct ether_arp *packet, int out_fd, int in_fd) {
|
||||||
@@ -83,11 +85,11 @@ static void verify_failure(struct ether_arp *packet, int out_fd, int in_fd) {
|
|||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = send(out_fd, packet, sizeof(struct ether_arp), 0);
|
r = send(out_fd, packet, sizeof(struct ether_arp), 0);
|
||||||
assert(r == sizeof(struct ether_arp));
|
c_assert(r == sizeof(struct ether_arp));
|
||||||
|
|
||||||
r = recv(in_fd, buf, sizeof(buf), 0);
|
r = recv(in_fd, buf, sizeof(buf), 0);
|
||||||
assert(r < 0);
|
c_assert(r < 0);
|
||||||
assert(errno == EAGAIN);
|
c_assert(errno == EAGAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_filter(void) {
|
static void test_filter(void) {
|
||||||
@@ -101,21 +103,21 @@ static void test_filter(void) {
|
|||||||
int r, mapfd = -1, progfd = -1, pair[2];
|
int r, mapfd = -1, progfd = -1, pair[2];
|
||||||
|
|
||||||
r = n_acd_bpf_map_create(&mapfd, 1);
|
r = n_acd_bpf_map_create(&mapfd, 1);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
r = n_acd_bpf_compile(&progfd, mapfd, &mac1);
|
r = n_acd_bpf_compile(&progfd, mapfd, &mac1);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
assert(progfd >= 0);
|
c_assert(progfd >= 0);
|
||||||
|
|
||||||
r = socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, pair);
|
r = socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, pair);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
r = setsockopt(pair[1], SOL_SOCKET, SO_ATTACH_BPF, &progfd,
|
r = setsockopt(pair[1], SOL_SOCKET, SO_ATTACH_BPF, &progfd,
|
||||||
sizeof(progfd));
|
sizeof(progfd));
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
r = n_acd_bpf_map_add(mapfd, &ip1);
|
r = n_acd_bpf_map_add(mapfd, &ip1);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
/* valid */
|
/* valid */
|
||||||
*packet = (struct ether_arp)ETHER_ARP_PACKET_INIT(ARPOP_REQUEST, &mac2, &ip1, &ip2);
|
*packet = (struct ether_arp)ETHER_ARP_PACKET_INIT(ARPOP_REQUEST, &mac2, &ip1, &ip2);
|
||||||
@@ -173,19 +175,19 @@ static void test_filter(void) {
|
|||||||
/* long */
|
/* long */
|
||||||
*packet = (struct ether_arp)ETHER_ARP_PACKET_INIT(ARPOP_REQUEST, &mac2, &ip1, &ip2);
|
*packet = (struct ether_arp)ETHER_ARP_PACKET_INIT(ARPOP_REQUEST, &mac2, &ip1, &ip2);
|
||||||
r = send(pair[0], buf, sizeof(struct ether_arp) + 1, 0);
|
r = send(pair[0], buf, sizeof(struct ether_arp) + 1, 0);
|
||||||
assert(r == sizeof(struct ether_arp) + 1);
|
c_assert(r == sizeof(struct ether_arp) + 1);
|
||||||
|
|
||||||
r = recv(pair[1], buf, sizeof(buf), 0);
|
r = recv(pair[1], buf, sizeof(buf), 0);
|
||||||
assert(r == sizeof(struct ether_arp));
|
c_assert(r == sizeof(struct ether_arp));
|
||||||
|
|
||||||
/* short */
|
/* short */
|
||||||
*packet = (struct ether_arp)ETHER_ARP_PACKET_INIT(ARPOP_REQUEST, &mac2, &ip1, &ip2);
|
*packet = (struct ether_arp)ETHER_ARP_PACKET_INIT(ARPOP_REQUEST, &mac2, &ip1, &ip2);
|
||||||
r = send(pair[0], buf, sizeof(struct ether_arp) - 1, 0);
|
r = send(pair[0], buf, sizeof(struct ether_arp) - 1, 0);
|
||||||
assert(r == sizeof(struct ether_arp) - 1);
|
c_assert(r == sizeof(struct ether_arp) - 1);
|
||||||
|
|
||||||
r = recv(pair[1], buf, sizeof(buf), 0);
|
r = recv(pair[1], buf, sizeof(buf), 0);
|
||||||
assert(r < 0);
|
c_assert(r < 0);
|
||||||
assert(errno == EAGAIN);
|
c_assert(errno == EAGAIN);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send one packet before and one packet after modifying the map,
|
* Send one packet before and one packet after modifying the map,
|
||||||
@@ -193,20 +195,20 @@ static void test_filter(void) {
|
|||||||
*/
|
*/
|
||||||
*packet = (struct ether_arp)ETHER_ARP_PACKET_INIT(ARPOP_REQUEST, &mac2, &ip1, &ip2);
|
*packet = (struct ether_arp)ETHER_ARP_PACKET_INIT(ARPOP_REQUEST, &mac2, &ip1, &ip2);
|
||||||
r = send(pair[0], buf, sizeof(struct ether_arp), 0);
|
r = send(pair[0], buf, sizeof(struct ether_arp), 0);
|
||||||
assert(r == sizeof(struct ether_arp));
|
c_assert(r == sizeof(struct ether_arp));
|
||||||
|
|
||||||
r = n_acd_bpf_map_remove(mapfd, &ip1);
|
r = n_acd_bpf_map_remove(mapfd, &ip1);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
r = send(pair[0], buf, sizeof(struct ether_arp), 0);
|
r = send(pair[0], buf, sizeof(struct ether_arp), 0);
|
||||||
assert(r == sizeof(struct ether_arp));
|
c_assert(r == sizeof(struct ether_arp));
|
||||||
|
|
||||||
r = recv(pair[1], buf, sizeof(buf), 0);
|
r = recv(pair[1], buf, sizeof(buf), 0);
|
||||||
assert(r == sizeof(struct ether_arp));
|
c_assert(r == sizeof(struct ether_arp));
|
||||||
|
|
||||||
r = recv(pair[1], buf, sizeof(buf), 0);
|
r = recv(pair[1], buf, sizeof(buf), 0);
|
||||||
assert(r < 0);
|
c_assert(r < 0);
|
||||||
assert(errno == EAGAIN);
|
c_assert(errno == EAGAIN);
|
||||||
|
|
||||||
close(pair[0]);
|
close(pair[0]);
|
||||||
close(pair[1]);
|
close(pair[1]);
|
||||||
@@ -215,11 +217,7 @@ static void test_filter(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
int r;
|
test_setup();
|
||||||
|
|
||||||
r = test_setup();
|
|
||||||
if (r)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
test_map();
|
test_map();
|
||||||
test_filter();
|
test_filter();
|
||||||
|
@@ -5,6 +5,8 @@
|
|||||||
* non-spanning-tree networks, or on networks that echo packets.
|
* non-spanning-tree networks, or on networks that echo packets.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#undef NDEBUG
|
||||||
|
#include <c-stdaux.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
@@ -15,14 +17,14 @@ static void test_loopback(int ifindex, uint8_t *mac, size_t n_mac) {
|
|||||||
int r, fd;
|
int r, fd;
|
||||||
|
|
||||||
r = n_acd_config_new(&config);
|
r = n_acd_config_new(&config);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
n_acd_config_set_ifindex(config, ifindex);
|
n_acd_config_set_ifindex(config, ifindex);
|
||||||
n_acd_config_set_transport(config, N_ACD_TRANSPORT_ETHERNET);
|
n_acd_config_set_transport(config, N_ACD_TRANSPORT_ETHERNET);
|
||||||
n_acd_config_set_mac(config, mac, n_mac);
|
n_acd_config_set_mac(config, mac, n_mac);
|
||||||
|
|
||||||
r = n_acd_new(&acd, config);
|
r = n_acd_new(&acd, config);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
n_acd_config_free(config);
|
n_acd_config_free(config);
|
||||||
|
|
||||||
@@ -32,13 +34,13 @@ static void test_loopback(int ifindex, uint8_t *mac, size_t n_mac) {
|
|||||||
struct in_addr ip = { htobe32((192 << 24) | (168 << 16) | (1 << 0)) };
|
struct in_addr ip = { htobe32((192 << 24) | (168 << 16) | (1 << 0)) };
|
||||||
|
|
||||||
r = n_acd_probe_config_new(&probe_config);
|
r = n_acd_probe_config_new(&probe_config);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
n_acd_probe_config_set_ip(probe_config, ip);
|
n_acd_probe_config_set_ip(probe_config, ip);
|
||||||
n_acd_probe_config_set_timeout(probe_config, 100);
|
n_acd_probe_config_set_timeout(probe_config, 100);
|
||||||
|
|
||||||
r = n_acd_probe(acd, &probe, probe_config);
|
r = n_acd_probe(acd, &probe, probe_config);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
n_acd_probe_config_free(probe_config);
|
n_acd_probe_config_free(probe_config);
|
||||||
|
|
||||||
@@ -48,15 +50,15 @@ static void test_loopback(int ifindex, uint8_t *mac, size_t n_mac) {
|
|||||||
NAcdEvent *event;
|
NAcdEvent *event;
|
||||||
pfds = (struct pollfd){ .fd = fd, .events = POLLIN };
|
pfds = (struct pollfd){ .fd = fd, .events = POLLIN };
|
||||||
r = poll(&pfds, 1, -1);
|
r = poll(&pfds, 1, -1);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
r = n_acd_dispatch(acd);
|
r = n_acd_dispatch(acd);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
r = n_acd_pop_event(acd, &event);
|
r = n_acd_pop_event(acd, &event);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
if (event) {
|
if (event) {
|
||||||
assert(event->event == N_ACD_EVENT_READY);
|
c_assert(event->event == N_ACD_EVENT_READY);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,11 +71,9 @@ static void test_loopback(int ifindex, uint8_t *mac, size_t n_mac) {
|
|||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
struct ether_addr mac;
|
struct ether_addr mac;
|
||||||
int r, ifindex;
|
int ifindex;
|
||||||
|
|
||||||
r = test_setup();
|
test_setup();
|
||||||
if (r)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
test_loopback_up(&ifindex, &mac);
|
test_loopback_up(&ifindex, &mac);
|
||||||
test_loopback(ifindex, mac.ether_addr_octet, sizeof(mac.ether_addr_octet));
|
test_loopback(ifindex, mac.ether_addr_octet, sizeof(mac.ether_addr_octet));
|
||||||
|
@@ -4,6 +4,8 @@
|
|||||||
* it on both ends. We expect the PROBE to fail on at least one of the devices.
|
* it on both ends. We expect the PROBE to fail on at least one of the devices.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#undef NDEBUG
|
||||||
|
#include <c-stdaux.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
@@ -29,17 +31,17 @@ static void test_unused(int ifindex1, uint8_t *mac1, size_t n_mac1, int ifindex2
|
|||||||
int r, fd1, fd2, state1, state2;
|
int r, fd1, fd2, state1, state2;
|
||||||
|
|
||||||
r = n_acd_new(&acd1);
|
r = n_acd_new(&acd1);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
r = n_acd_new(&acd2);
|
r = n_acd_new(&acd2);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
n_acd_get_fd(acd1, &fd1);
|
n_acd_get_fd(acd1, &fd1);
|
||||||
n_acd_get_fd(acd2, &fd2);
|
n_acd_get_fd(acd2, &fd2);
|
||||||
|
|
||||||
r = n_acd_start(acd1, &config1);
|
r = n_acd_start(acd1, &config1);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
r = n_acd_start(acd2, &config2);
|
r = n_acd_start(acd2, &config2);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
for (state1 = state2 = -1; state1 == -1 || state2 == -1; ) {
|
for (state1 = state2 = -1; state1 == -1 || state2 == -1; ) {
|
||||||
NAcdEvent *event;
|
NAcdEvent *event;
|
||||||
@@ -47,31 +49,31 @@ static void test_unused(int ifindex1, uint8_t *mac1, size_t n_mac1, int ifindex2
|
|||||||
pfds[1] = (struct pollfd){ .fd = fd2, .events = (state2 == -1) ? POLLIN : 0 };
|
pfds[1] = (struct pollfd){ .fd = fd2, .events = (state2 == -1) ? POLLIN : 0 };
|
||||||
|
|
||||||
r = poll(pfds, sizeof(pfds) / sizeof(*pfds), -1);
|
r = poll(pfds, sizeof(pfds) / sizeof(*pfds), -1);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
if (state1 == -1) {
|
if (state1 == -1) {
|
||||||
r = n_acd_dispatch(acd1);
|
r = n_acd_dispatch(acd1);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
r = n_acd_pop_event(acd1, &event);
|
r = n_acd_pop_event(acd1, &event);
|
||||||
if (!r) {
|
if (!r) {
|
||||||
assert(event->event == N_ACD_EVENT_READY || event->event == N_ACD_EVENT_USED);
|
c_assert(event->event == N_ACD_EVENT_READY || event->event == N_ACD_EVENT_USED);
|
||||||
state1 = !!(event->event == N_ACD_EVENT_READY);
|
state1 = !!(event->event == N_ACD_EVENT_READY);
|
||||||
} else {
|
} else {
|
||||||
assert(r == N_ACD_E_DONE);
|
c_assert(r == N_ACD_E_DONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state2 == -1) {
|
if (state2 == -1) {
|
||||||
r = n_acd_dispatch(acd2);
|
r = n_acd_dispatch(acd2);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
r = n_acd_pop_event(acd2, &event);
|
r = n_acd_pop_event(acd2, &event);
|
||||||
if (!r) {
|
if (!r) {
|
||||||
assert(event->event == N_ACD_EVENT_READY || event->event == N_ACD_EVENT_USED);
|
c_assert(event->event == N_ACD_EVENT_READY || event->event == N_ACD_EVENT_USED);
|
||||||
state2 = !!(event->event == N_ACD_EVENT_READY);
|
state2 = !!(event->event == N_ACD_EVENT_READY);
|
||||||
} else {
|
} else {
|
||||||
assert(r == N_ACD_E_DONE);
|
c_assert(r == N_ACD_E_DONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,16 +81,14 @@ static void test_unused(int ifindex1, uint8_t *mac1, size_t n_mac1, int ifindex2
|
|||||||
n_acd_free(acd1);
|
n_acd_free(acd1);
|
||||||
n_acd_free(acd2);
|
n_acd_free(acd2);
|
||||||
|
|
||||||
assert(!state1 || !state2);
|
c_assert(!state1 || !state2);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
struct ether_addr mac1, mac2;
|
struct ether_addr mac1, mac2;
|
||||||
int r, ifindex1, ifindex2;
|
int ifindex1, ifindex2;
|
||||||
|
|
||||||
r = test_setup();
|
test_setup();
|
||||||
if (r)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
test_veth_new(&ifindex1, &mac1, &ifindex2, &mac2);
|
test_veth_new(&ifindex1, &mac1, &ifindex2, &mac2);
|
||||||
test_unused(ifindex1, mac1.ether_addr_octet, sizeof(mac2.ether_addr_octet), ifindex2, mac2.ether_addr_octet, sizeof(mac2.ether_addr_octet));
|
test_unused(ifindex1, mac1.ether_addr_octet, sizeof(mac2.ether_addr_octet), ifindex2, mac2.ether_addr_octet, sizeof(mac2.ether_addr_octet));
|
||||||
|
@@ -4,6 +4,8 @@
|
|||||||
* link, but DOWN or UNPLUG the device while running.
|
* link, but DOWN or UNPLUG the device while running.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#undef NDEBUG
|
||||||
|
#include <c-stdaux.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
@@ -24,14 +26,14 @@ static void test_unplug_down(int ifindex, uint8_t *mac, size_t n_mac, unsigned i
|
|||||||
test_veth_cmd(ifindex, "down");
|
test_veth_cmd(ifindex, "down");
|
||||||
|
|
||||||
r = n_acd_new(&acd);
|
r = n_acd_new(&acd);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
if (!run--)
|
if (!run--)
|
||||||
test_veth_cmd(ifindex, "down");
|
test_veth_cmd(ifindex, "down");
|
||||||
|
|
||||||
n_acd_get_fd(acd, &fd);
|
n_acd_get_fd(acd, &fd);
|
||||||
r = n_acd_start(acd, &config);
|
r = n_acd_start(acd, &config);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
if (!run--)
|
if (!run--)
|
||||||
test_veth_cmd(ifindex, "down");
|
test_veth_cmd(ifindex, "down");
|
||||||
@@ -40,24 +42,24 @@ static void test_unplug_down(int ifindex, uint8_t *mac, size_t n_mac, unsigned i
|
|||||||
NAcdEvent *event;
|
NAcdEvent *event;
|
||||||
pfds = (struct pollfd){ .fd = fd, .events = POLLIN };
|
pfds = (struct pollfd){ .fd = fd, .events = POLLIN };
|
||||||
r = poll(&pfds, 1, -1);
|
r = poll(&pfds, 1, -1);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
if (!run--)
|
if (!run--)
|
||||||
test_veth_cmd(ifindex, "down");
|
test_veth_cmd(ifindex, "down");
|
||||||
|
|
||||||
r = n_acd_dispatch(acd);
|
r = n_acd_dispatch(acd);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
r = n_acd_pop_event(acd, &event);
|
r = n_acd_pop_event(acd, &event);
|
||||||
if (!r) {
|
if (!r) {
|
||||||
if (event->event == N_ACD_EVENT_DOWN) {
|
if (event->event == N_ACD_EVENT_DOWN) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
assert(event->event == N_ACD_EVENT_READY);
|
c_assert(event->event == N_ACD_EVENT_READY);
|
||||||
test_veth_cmd(ifindex, "down");
|
test_veth_cmd(ifindex, "down");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
assert(r == N_ACD_E_DONE);
|
c_assert(r == N_ACD_E_DONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,11 +69,9 @@ static void test_unplug_down(int ifindex, uint8_t *mac, size_t n_mac, unsigned i
|
|||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
struct ether_addr mac;
|
struct ether_addr mac;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int r, ifindex;
|
int ifindex;
|
||||||
|
|
||||||
r = test_setup();
|
test_setup();
|
||||||
if (r)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
test_veth_new(&ifindex, &mac, NULL, NULL);
|
test_veth_new(&ifindex, &mac, NULL, NULL);
|
||||||
|
|
||||||
|
@@ -4,6 +4,8 @@
|
|||||||
* link. This should just pass through, with a short, random timeout.
|
* link. This should just pass through, with a short, random timeout.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#undef NDEBUG
|
||||||
|
#include <c-stdaux.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
@@ -21,27 +23,27 @@ static void test_unused(int ifindex, const uint8_t *mac, size_t n_mac) {
|
|||||||
int r, fd;
|
int r, fd;
|
||||||
|
|
||||||
r = n_acd_new(&acd);
|
r = n_acd_new(&acd);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
n_acd_get_fd(acd, &fd);
|
n_acd_get_fd(acd, &fd);
|
||||||
r = n_acd_start(acd, &config);
|
r = n_acd_start(acd, &config);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
NAcdEvent *event;
|
NAcdEvent *event;
|
||||||
pfds = (struct pollfd){ .fd = fd, .events = POLLIN };
|
pfds = (struct pollfd){ .fd = fd, .events = POLLIN };
|
||||||
r = poll(&pfds, 1, -1);
|
r = poll(&pfds, 1, -1);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
r = n_acd_dispatch(acd);
|
r = n_acd_dispatch(acd);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
r = n_acd_pop_event(acd, &event);
|
r = n_acd_pop_event(acd, &event);
|
||||||
if (!r) {
|
if (!r) {
|
||||||
assert(event->event == N_ACD_EVENT_READY);
|
c_assert(event->event == N_ACD_EVENT_READY);
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
assert(r == N_ACD_E_DONE);
|
c_assert(r == N_ACD_E_DONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,11 +52,9 @@ static void test_unused(int ifindex, const uint8_t *mac, size_t n_mac) {
|
|||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
struct ether_addr mac;
|
struct ether_addr mac;
|
||||||
int r, ifindex;
|
int ifindex;
|
||||||
|
|
||||||
r = test_setup();
|
test_setup();
|
||||||
if (r)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
test_veth_new(&ifindex, &mac, NULL, NULL);
|
test_veth_new(&ifindex, &mac, NULL, NULL);
|
||||||
test_unused(ifindex, mac.ether_addr_octet, sizeof(mac.ether_addr_octet));
|
test_unused(ifindex, mac.ether_addr_octet, sizeof(mac.ether_addr_octet));
|
||||||
|
@@ -15,6 +15,8 @@
|
|||||||
* want to verify that resizing the internal maps works correctly.
|
* want to verify that resizing the internal maps works correctly.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#undef NDEBUG
|
||||||
|
#include <c-stdaux.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
@@ -37,19 +39,19 @@ static void test_veth(int ifindex1, uint8_t *mac1, size_t n_mac1,
|
|||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = n_acd_config_new(&config);
|
r = n_acd_config_new(&config);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
n_acd_config_set_transport(config, N_ACD_TRANSPORT_ETHERNET);
|
n_acd_config_set_transport(config, N_ACD_TRANSPORT_ETHERNET);
|
||||||
|
|
||||||
n_acd_config_set_ifindex(config, ifindex1);
|
n_acd_config_set_ifindex(config, ifindex1);
|
||||||
n_acd_config_set_mac(config, mac1, n_mac1);
|
n_acd_config_set_mac(config, mac1, n_mac1);
|
||||||
r = n_acd_new(&acd1, config);
|
r = n_acd_new(&acd1, config);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
n_acd_config_set_ifindex(config, ifindex2);
|
n_acd_config_set_ifindex(config, ifindex2);
|
||||||
n_acd_config_set_mac(config, mac2, n_mac2);
|
n_acd_config_set_mac(config, mac2, n_mac2);
|
||||||
r = n_acd_new(&acd2, config);
|
r = n_acd_new(&acd2, config);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
n_acd_config_free(config);
|
n_acd_config_free(config);
|
||||||
|
|
||||||
@@ -57,10 +59,10 @@ static void test_veth(int ifindex1, uint8_t *mac1, size_t n_mac1,
|
|||||||
NAcdProbeConfig *probe_config;
|
NAcdProbeConfig *probe_config;
|
||||||
|
|
||||||
r = n_acd_probe_config_new(&probe_config);
|
r = n_acd_probe_config_new(&probe_config);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
n_acd_probe_config_set_timeout(probe_config, 64);
|
n_acd_probe_config_set_timeout(probe_config, 1024);
|
||||||
|
|
||||||
assert(TEST_ACD_N_PROBES <= 10 << 24);
|
c_assert(TEST_ACD_N_PROBES <= 10 << 24);
|
||||||
|
|
||||||
for (size_t i = 0; i < TEST_ACD_N_PROBES; ++i) {
|
for (size_t i = 0; i < TEST_ACD_N_PROBES; ++i) {
|
||||||
struct in_addr ip = { htobe32((10 << 24) | i) };
|
struct in_addr ip = { htobe32((10 << 24) | i) };
|
||||||
@@ -73,7 +75,6 @@ static void test_veth(int ifindex1, uint8_t *mac1, size_t n_mac1,
|
|||||||
* Probe on one side, and leave the address
|
* Probe on one side, and leave the address
|
||||||
* unset on the other. The probe must succeed.
|
* unset on the other. The probe must succeed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
/*
|
/*
|
||||||
@@ -81,23 +82,26 @@ static void test_veth(int ifindex1, uint8_t *mac1, size_t n_mac1,
|
|||||||
* probe on the other. The probe must fail.
|
* probe on the other. The probe must fail.
|
||||||
*/
|
*/
|
||||||
test_add_child_ip(&ip);
|
test_add_child_ip(&ip);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
/*
|
/*
|
||||||
* Probe both sides for the same address, at
|
* Probe both sides for the same address, at
|
||||||
* most one may succeed.
|
* most one may succeed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
r = n_acd_probe(acd2, &probes2[i], probe_config);
|
r = n_acd_probe(acd2, &probes2[i], probe_config);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
++n_running;
|
++n_running;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
c_assert(0);
|
||||||
|
abort();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = n_acd_probe(acd1, &probes1[i], probe_config);
|
r = n_acd_probe(acd1, &probes1[i], probe_config);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
++n_running;
|
++n_running;
|
||||||
}
|
}
|
||||||
@@ -115,33 +119,33 @@ static void test_veth(int ifindex1, uint8_t *mac1, size_t n_mac1,
|
|||||||
n_acd_get_fd(acd2, &pfds[1].fd);
|
n_acd_get_fd(acd2, &pfds[1].fd);
|
||||||
|
|
||||||
r = poll(pfds, 2, -1);
|
r = poll(pfds, 2, -1);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
if (pfds[0].revents & POLLIN) {
|
if (pfds[0].revents & POLLIN) {
|
||||||
r = n_acd_dispatch(acd1);
|
r = n_acd_dispatch(acd1);
|
||||||
assert(!r || r == N_ACD_E_PREEMPTED);
|
c_assert(!r || r == N_ACD_E_PREEMPTED);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
r = n_acd_pop_event(acd1, &event);
|
r = n_acd_pop_event(acd1, &event);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
if (event) {
|
if (event) {
|
||||||
switch (event->event) {
|
switch (event->event) {
|
||||||
case N_ACD_EVENT_READY:
|
case N_ACD_EVENT_READY:
|
||||||
n_acd_probe_get_userdata(event->ready.probe, (void**)&state1);
|
n_acd_probe_get_userdata(event->ready.probe, (void**)&state1);
|
||||||
assert(state1 == TEST_ACD_STATE_UNKNOWN);
|
c_assert(state1 == TEST_ACD_STATE_UNKNOWN);
|
||||||
state1 = TEST_ACD_STATE_READY;
|
state1 = TEST_ACD_STATE_READY;
|
||||||
n_acd_probe_set_userdata(event->ready.probe, (void*)state1);
|
n_acd_probe_set_userdata(event->ready.probe, (void*)state1);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case N_ACD_EVENT_USED:
|
case N_ACD_EVENT_USED:
|
||||||
n_acd_probe_get_userdata(event->used.probe, (void**)&state1);
|
n_acd_probe_get_userdata(event->used.probe, (void**)&state1);
|
||||||
assert(state1 == TEST_ACD_STATE_UNKNOWN);
|
c_assert(state1 == TEST_ACD_STATE_UNKNOWN);
|
||||||
state1 = TEST_ACD_STATE_USED;
|
state1 = TEST_ACD_STATE_USED;
|
||||||
n_acd_probe_set_userdata(event->used.probe, (void*)state1);
|
n_acd_probe_set_userdata(event->used.probe, (void*)state1);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
c_assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
--n_running;
|
--n_running;
|
||||||
@@ -153,29 +157,29 @@ static void test_veth(int ifindex1, uint8_t *mac1, size_t n_mac1,
|
|||||||
|
|
||||||
if (pfds[1].revents & POLLIN) {
|
if (pfds[1].revents & POLLIN) {
|
||||||
r = n_acd_dispatch(acd2);
|
r = n_acd_dispatch(acd2);
|
||||||
assert(!r || r == N_ACD_E_PREEMPTED);
|
c_assert(!r || r == N_ACD_E_PREEMPTED);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
r = n_acd_pop_event(acd2, &event);
|
r = n_acd_pop_event(acd2, &event);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
if (event) {
|
if (event) {
|
||||||
switch (event->event) {
|
switch (event->event) {
|
||||||
case N_ACD_EVENT_READY:
|
case N_ACD_EVENT_READY:
|
||||||
n_acd_probe_get_userdata(event->ready.probe, (void**)&state2);
|
n_acd_probe_get_userdata(event->ready.probe, (void**)&state2);
|
||||||
assert(state2 == TEST_ACD_STATE_UNKNOWN);
|
c_assert(state2 == TEST_ACD_STATE_UNKNOWN);
|
||||||
state2 = TEST_ACD_STATE_READY;
|
state2 = TEST_ACD_STATE_READY;
|
||||||
n_acd_probe_set_userdata(event->ready.probe, (void*)state2);
|
n_acd_probe_set_userdata(event->ready.probe, (void*)state2);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case N_ACD_EVENT_USED:
|
case N_ACD_EVENT_USED:
|
||||||
n_acd_probe_get_userdata(event->used.probe, (void**)&state2);
|
n_acd_probe_get_userdata(event->used.probe, (void**)&state2);
|
||||||
assert(state2 == TEST_ACD_STATE_UNKNOWN);
|
c_assert(state2 == TEST_ACD_STATE_UNKNOWN);
|
||||||
state2 = TEST_ACD_STATE_USED;
|
state2 = TEST_ACD_STATE_USED;
|
||||||
n_acd_probe_set_userdata(event->used.probe, (void*)state2);
|
n_acd_probe_set_userdata(event->used.probe, (void*)state2);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(0);
|
c_assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
--n_running;
|
--n_running;
|
||||||
@@ -192,22 +196,22 @@ static void test_veth(int ifindex1, uint8_t *mac1, size_t n_mac1,
|
|||||||
switch (i % 3) {
|
switch (i % 3) {
|
||||||
case 0:
|
case 0:
|
||||||
n_acd_probe_get_userdata(probes1[i], (void **)&state1);
|
n_acd_probe_get_userdata(probes1[i], (void **)&state1);
|
||||||
assert(state1 == TEST_ACD_STATE_READY);
|
c_assert(state1 == TEST_ACD_STATE_READY);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
test_del_child_ip(&ip);
|
test_del_child_ip(&ip);
|
||||||
|
|
||||||
n_acd_probe_get_userdata(probes1[i], (void **)&state1);
|
n_acd_probe_get_userdata(probes1[i], (void **)&state1);
|
||||||
assert(state1 == TEST_ACD_STATE_USED);
|
c_assert(state1 == TEST_ACD_STATE_USED);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
n_acd_probe_get_userdata(probes1[i], (void **)&state1);
|
n_acd_probe_get_userdata(probes1[i], (void **)&state1);
|
||||||
n_acd_probe_get_userdata(probes2[i], (void **)&state2);
|
n_acd_probe_get_userdata(probes2[i], (void **)&state2);
|
||||||
assert(state1 != TEST_ACD_STATE_UNKNOWN);
|
c_assert(state1 != TEST_ACD_STATE_UNKNOWN);
|
||||||
assert(state2 != TEST_ACD_STATE_UNKNOWN);
|
c_assert(state2 != TEST_ACD_STATE_UNKNOWN);
|
||||||
assert(state1 == TEST_ACD_STATE_USED || state2 == TEST_ACD_STATE_USED);
|
c_assert(state1 == TEST_ACD_STATE_USED || state2 == TEST_ACD_STATE_USED);
|
||||||
n_acd_probe_free(probes2[i]);
|
n_acd_probe_free(probes2[i]);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -222,11 +226,9 @@ static void test_veth(int ifindex1, uint8_t *mac1, size_t n_mac1,
|
|||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
struct ether_addr mac1, mac2;
|
struct ether_addr mac1, mac2;
|
||||||
int r, ifindex1, ifindex2;
|
int ifindex1, ifindex2;
|
||||||
|
|
||||||
r = test_setup();
|
test_setup();
|
||||||
if (r)
|
|
||||||
return r;
|
|
||||||
|
|
||||||
test_veth_new(&ifindex1, &mac1, &ifindex2, &mac2);
|
test_veth_new(&ifindex1, &mac1, &ifindex2, &mac2);
|
||||||
for (unsigned int i = 0; i < 8; ++i) {
|
for (unsigned int i = 0; i < 8; ++i) {
|
||||||
|
123
src/test.h
123
src/test.h
@@ -6,9 +6,12 @@
|
|||||||
* includes net-namespace setups, veth setups, and more.
|
* includes net-namespace setups, veth setups, and more.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#undef NDEBUG
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <c-stdaux.h>
|
||||||
#include <endian.h>
|
#include <endian.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <net/ethernet.h>
|
#include <net/ethernet.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
@@ -21,6 +24,10 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/mount.h>
|
||||||
|
#include <sys/resource.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "n-acd.h"
|
#include "n-acd.h"
|
||||||
|
|
||||||
@@ -29,10 +36,10 @@ static inline void test_add_child_ip(const struct in_addr *addr) {
|
|||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = asprintf(&p, "ip addr add dev veth1 %s/8", inet_ntoa(*addr));
|
r = asprintf(&p, "ip addr add dev veth1 %s/8", inet_ntoa(*addr));
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
r = system(p);
|
r = system(p);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
@@ -42,10 +49,10 @@ static inline void test_del_child_ip(const struct in_addr *addr) {
|
|||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = asprintf(&p, "ip addr del dev veth1 %s/8", inet_ntoa(*addr));
|
r = asprintf(&p, "ip addr del dev veth1 %s/8", inet_ntoa(*addr));
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
r = system(p);
|
r = system(p);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
@@ -56,20 +63,20 @@ static inline void test_if_query(const char *name, int *indexp, struct ether_add
|
|||||||
int r, s;
|
int r, s;
|
||||||
|
|
||||||
l = strlen(name);
|
l = strlen(name);
|
||||||
assert(l <= IF_NAMESIZE);
|
c_assert(l <= IF_NAMESIZE);
|
||||||
|
|
||||||
if (indexp) {
|
if (indexp) {
|
||||||
*indexp = if_nametoindex(name);
|
*indexp = if_nametoindex(name);
|
||||||
assert(*indexp > 0);
|
c_assert(*indexp > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (macp) {
|
if (macp) {
|
||||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
assert(s >= 0);
|
c_assert(s >= 0);
|
||||||
|
|
||||||
strncpy(ifr.ifr_name, name, l + 1);
|
strncpy(ifr.ifr_name, name, l + 1);
|
||||||
r = ioctl(s, SIOCGIFHWADDR, &ifr);
|
r = ioctl(s, SIOCGIFHWADDR, &ifr);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
memcpy(macp->ether_addr_octet, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
|
memcpy(macp->ether_addr_octet, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
|
||||||
|
|
||||||
@@ -82,14 +89,14 @@ static inline void test_veth_cmd(int ifindex, const char *cmd) {
|
|||||||
int r;
|
int r;
|
||||||
|
|
||||||
p = if_indextoname(ifindex, name);
|
p = if_indextoname(ifindex, name);
|
||||||
assert(p);
|
c_assert(p);
|
||||||
|
|
||||||
r = asprintf(&p, "ip link set %s %s", name, cmd);
|
r = asprintf(&p, "ip link set %s %s", name, cmd);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
/* Again: Ewwww... */
|
/* Again: Ewwww... */
|
||||||
r = system(p);
|
r = system(p);
|
||||||
assert(r == 0);
|
c_assert(r == 0);
|
||||||
|
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
@@ -102,11 +109,11 @@ static inline void test_veth_new(int *parent_indexp,
|
|||||||
|
|
||||||
/* Eww... but it works. */
|
/* Eww... but it works. */
|
||||||
r = system("ip link add type veth");
|
r = system("ip link add type veth");
|
||||||
assert(r == 0);
|
c_assert(r == 0);
|
||||||
r = system("ip link set veth0 up");
|
r = system("ip link set veth0 up");
|
||||||
assert(r == 0);
|
c_assert(r == 0);
|
||||||
r = system("ip link set veth1 up");
|
r = system("ip link set veth1 up");
|
||||||
assert(r == 0);
|
c_assert(r == 0);
|
||||||
|
|
||||||
test_if_query("veth0", parent_indexp, parent_macp);
|
test_if_query("veth0", parent_indexp, parent_macp);
|
||||||
test_if_query("veth1", child_indexp, child_macp);
|
test_if_query("veth1", child_indexp, child_macp);
|
||||||
@@ -116,19 +123,91 @@ static inline void test_loopback_up(int *indexp, struct ether_addr *macp) {
|
|||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = system("ip link set lo up");
|
r = system("ip link set lo up");
|
||||||
assert(r == 0);
|
c_assert(r == 0);
|
||||||
|
|
||||||
test_if_query("lo", indexp, macp);
|
test_if_query("lo", indexp, macp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int test_setup(void) {
|
static inline void test_raise_memlock(void) {
|
||||||
|
const size_t wanted = 64 * 1024 * 1024;
|
||||||
|
struct rlimit get, set;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = unshare(CLONE_NEWNET);
|
r = getrlimit(RLIMIT_MEMLOCK, &get);
|
||||||
if (r < 0) {
|
c_assert(!r);
|
||||||
assert(errno == EPERM);
|
|
||||||
return 77;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
/* try raising limit to @wanted */
|
||||||
|
set.rlim_cur = wanted;
|
||||||
|
set.rlim_max = (wanted > get.rlim_max) ? wanted : get.rlim_max;
|
||||||
|
r = setrlimit(RLIMIT_MEMLOCK, &set);
|
||||||
|
if (r) {
|
||||||
|
c_assert(errno == EPERM);
|
||||||
|
|
||||||
|
/* not privileged to raise limit, so maximize soft limit */
|
||||||
|
set.rlim_cur = get.rlim_max;
|
||||||
|
set.rlim_max = get.rlim_max;
|
||||||
|
r = setrlimit(RLIMIT_MEMLOCK, &set);
|
||||||
|
c_assert(!r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void test_unshare_user_namespace(void) {
|
||||||
|
uid_t euid;
|
||||||
|
gid_t egid;
|
||||||
|
int r, fd;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Enter a new user namespace as root:root.
|
||||||
|
*/
|
||||||
|
|
||||||
|
euid = geteuid();
|
||||||
|
egid = getegid();
|
||||||
|
|
||||||
|
r = unshare(CLONE_NEWUSER);
|
||||||
|
c_assert(r >= 0);
|
||||||
|
|
||||||
|
fd = open("/proc/self/uid_map", O_WRONLY);
|
||||||
|
c_assert(fd >= 0);
|
||||||
|
r = dprintf(fd, "0 %d 1\n", euid);
|
||||||
|
c_assert(r >= 0);
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
fd = open("/proc/self/setgroups", O_WRONLY);
|
||||||
|
c_assert(fd >= 0);
|
||||||
|
r = dprintf(fd, "deny");
|
||||||
|
c_assert(r >= 0);
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
fd = open("/proc/self/gid_map", O_WRONLY);
|
||||||
|
c_assert(fd >= 0);
|
||||||
|
r = dprintf(fd, "0 %d 1\n", egid);
|
||||||
|
c_assert(r >= 0);
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void test_setup(void) {
|
||||||
|
int r;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Move into a new network and mount namespace both associated
|
||||||
|
* with a new user namespace where the current eUID is mapped to
|
||||||
|
* 0. Then create a a private instance of /run/netns. This ensures
|
||||||
|
* that any network devices or network namespaces are private to
|
||||||
|
* the test process.
|
||||||
|
*/
|
||||||
|
|
||||||
|
test_raise_memlock();
|
||||||
|
test_unshare_user_namespace();
|
||||||
|
|
||||||
|
r = unshare(CLONE_NEWNET | CLONE_NEWNS);
|
||||||
|
c_assert(r >= 0);
|
||||||
|
|
||||||
|
r = mount(NULL, "/", "", MS_PRIVATE | MS_REC, NULL);
|
||||||
|
c_assert(r >= 0);
|
||||||
|
|
||||||
|
r = mount(NULL, "/run", "tmpfs", 0, NULL);
|
||||||
|
c_assert(r >= 0);
|
||||||
|
|
||||||
|
r = mkdir("/run/netns", 0755);
|
||||||
|
c_assert(r >= 0);
|
||||||
}
|
}
|
||||||
|
@@ -2,11 +2,12 @@
|
|||||||
* Tests for timer utility library
|
* Tests for timer utility library
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#undef NDEBUG
|
||||||
|
#include <c-stdaux.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/timerfd.h>
|
#include <sys/timerfd.h>
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
@@ -19,20 +20,20 @@ static void test_api(void) {
|
|||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = timer_init(&timer);
|
r = timer_init(&timer);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
timeout_schedule(&t1, &timer, 1);
|
timeout_schedule(&t1, &timer, 1);
|
||||||
timeout_schedule(&t2, &timer, 2);
|
timeout_schedule(&t2, &timer, 2);
|
||||||
|
|
||||||
r = timer_pop_timeout(&timer, 10, &t);
|
r = timer_pop_timeout(&timer, 10, &t);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
assert(t == &t1);
|
c_assert(t == &t1);
|
||||||
|
|
||||||
timeout_unschedule(&t2);
|
timeout_unschedule(&t2);
|
||||||
|
|
||||||
r = timer_pop_timeout(&timer, 10, &t);
|
r = timer_pop_timeout(&timer, 10, &t);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
assert(!t);
|
c_assert(!t);
|
||||||
|
|
||||||
timer_deinit(&timer);
|
timer_deinit(&timer);
|
||||||
}
|
}
|
||||||
@@ -47,7 +48,7 @@ static void test_pop(void) {
|
|||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = timer_init(&timer);
|
r = timer_init(&timer);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
|
|
||||||
for(size_t i = 0; i < N_TIMEOUTS; ++i) {
|
for(size_t i = 0; i < N_TIMEOUTS; ++i) {
|
||||||
timeouts[i] = (Timeout)TIMEOUT_INIT(timeouts[i]);
|
timeouts[i] = (Timeout)TIMEOUT_INIT(timeouts[i]);
|
||||||
@@ -66,11 +67,11 @@ static void test_pop(void) {
|
|||||||
uint64_t count;
|
uint64_t count;
|
||||||
|
|
||||||
r = poll(&pfd, 1, -1);
|
r = poll(&pfd, 1, -1);
|
||||||
assert(r == 1);
|
c_assert(r == 1);
|
||||||
|
|
||||||
r = read(timer.fd, &count, sizeof(count));
|
r = read(timer.fd, &count, sizeof(count));
|
||||||
assert(r == sizeof(count));
|
c_assert(r == sizeof(count));
|
||||||
assert(count == 1);
|
c_assert(count == 1);
|
||||||
armed = false;
|
armed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,24 +79,24 @@ static void test_pop(void) {
|
|||||||
uint64_t current_time;
|
uint64_t current_time;
|
||||||
|
|
||||||
r = timer_pop_timeout(&timer, i, &t);
|
r = timer_pop_timeout(&timer, i, &t);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
if (!t) {
|
if (!t) {
|
||||||
timer_rearm(&timer);
|
timer_rearm(&timer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
current_time = times[t - timeouts];
|
current_time = times[t - timeouts];
|
||||||
assert(current_time == i);
|
c_assert(current_time == i);
|
||||||
++n_timeouts;
|
++n_timeouts;
|
||||||
armed = true;
|
armed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(n_timeouts == N_TIMEOUTS);
|
c_assert(n_timeouts == N_TIMEOUTS);
|
||||||
|
|
||||||
r = timer_pop_timeout(&timer, (uint64_t)-1, &t);
|
r = timer_pop_timeout(&timer, (uint64_t)-1, &t);
|
||||||
assert(!r);
|
c_assert(!r);
|
||||||
assert(!t);
|
c_assert(!t);
|
||||||
|
|
||||||
timer_deinit(&timer);
|
timer_deinit(&timer);
|
||||||
}
|
}
|
||||||
@@ -109,60 +110,60 @@ void test_arm(void) {
|
|||||||
int fd1, fd2, r;
|
int fd1, fd2, r;
|
||||||
|
|
||||||
fd1 = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
|
fd1 = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
|
||||||
assert(fd1 >= 0);
|
c_assert(fd1 >= 0);
|
||||||
|
|
||||||
fd2 = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
|
fd2 = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
|
||||||
assert(fd1 >= 0);
|
c_assert(fd1 >= 0);
|
||||||
|
|
||||||
r = timerfd_settime(fd1, 0, &spec, NULL);
|
r = timerfd_settime(fd1, 0, &spec, NULL);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
r = timerfd_settime(fd2, 0, &spec, NULL);
|
r = timerfd_settime(fd2, 0, &spec, NULL);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
r = timerfd_gettime(fd1, &spec);
|
r = timerfd_gettime(fd1, &spec);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
assert(spec.it_value.tv_sec);
|
c_assert(spec.it_value.tv_sec);
|
||||||
|
|
||||||
r = timerfd_gettime(fd2, &spec);
|
r = timerfd_gettime(fd2, &spec);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
assert(spec.it_value.tv_sec);
|
c_assert(spec.it_value.tv_sec);
|
||||||
|
|
||||||
spec = (struct itimerspec){};
|
spec = (struct itimerspec){};
|
||||||
|
|
||||||
r = timerfd_settime(fd1, 0, &spec, NULL);
|
r = timerfd_settime(fd1, 0, &spec, NULL);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
r = timerfd_gettime(fd1, &spec);
|
r = timerfd_gettime(fd1, &spec);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
assert(!spec.it_value.tv_sec);
|
c_assert(!spec.it_value.tv_sec);
|
||||||
assert(!spec.it_value.tv_nsec);
|
c_assert(!spec.it_value.tv_nsec);
|
||||||
|
|
||||||
r = timerfd_gettime(fd2, &spec);
|
r = timerfd_gettime(fd2, &spec);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
assert(spec.it_value.tv_sec);
|
c_assert(spec.it_value.tv_sec);
|
||||||
|
|
||||||
spec = (struct itimerspec){ .it_value = { .tv_nsec = 1, }, };
|
spec = (struct itimerspec){ .it_value = { .tv_nsec = 1, }, };
|
||||||
|
|
||||||
r = timerfd_settime(fd1, 0, &spec, NULL);
|
r = timerfd_settime(fd1, 0, &spec, NULL);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
r = poll(&(struct pollfd) { .fd = fd1, .events = POLLIN }, 1, -1);
|
r = poll(&(struct pollfd) { .fd = fd1, .events = POLLIN }, 1, -1);
|
||||||
assert(r == 1);
|
c_assert(r == 1);
|
||||||
|
|
||||||
r = timerfd_settime(fd2, 0, &spec, NULL);
|
r = timerfd_settime(fd2, 0, &spec, NULL);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
r = poll(&(struct pollfd) { .fd = fd2, .events = POLLIN }, 1, -1);
|
r = poll(&(struct pollfd) { .fd = fd2, .events = POLLIN }, 1, -1);
|
||||||
assert(r == 1);
|
c_assert(r == 1);
|
||||||
|
|
||||||
spec = (struct itimerspec){};
|
spec = (struct itimerspec){};
|
||||||
|
|
||||||
r = timerfd_settime(fd1, 0, &spec, NULL);
|
r = timerfd_settime(fd1, 0, &spec, NULL);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
r = poll(&(struct pollfd) { .fd = fd2, .events = POLLIN }, 1, -1);
|
r = poll(&(struct pollfd) { .fd = fd2, .events = POLLIN }, 1, -1);
|
||||||
assert(r == 1);
|
c_assert(r == 1);
|
||||||
|
|
||||||
close(fd2);
|
close(fd2);
|
||||||
close(fd1);
|
close(fd1);
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <c-rbtree.h>
|
#include <c-rbtree.h>
|
||||||
|
#include <c-stdaux.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/timerfd.h>
|
#include <sys/timerfd.h>
|
||||||
@@ -30,7 +31,7 @@ int timer_init(Timer *timer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void timer_deinit(Timer *timer) {
|
void timer_deinit(Timer *timer) {
|
||||||
assert(c_rbtree_is_empty(&timer->tree));
|
c_assert(c_rbtree_is_empty(&timer->tree));
|
||||||
|
|
||||||
if (timer->fd >= 0) {
|
if (timer->fd >= 0) {
|
||||||
close(timer->fd);
|
close(timer->fd);
|
||||||
@@ -43,7 +44,7 @@ void timer_now(Timer *timer, uint64_t *nowp) {
|
|||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = clock_gettime(timer->clock, &ts);
|
r = clock_gettime(timer->clock, &ts);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
*nowp = ts.tv_sec * UINT64_C(1000000000) + ts.tv_nsec;
|
*nowp = ts.tv_sec * UINT64_C(1000000000) + ts.tv_nsec;
|
||||||
}
|
}
|
||||||
@@ -59,7 +60,7 @@ void timer_rearm(Timer *timer) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
timeout = c_rbnode_entry(c_rbtree_first(&timer->tree), Timeout, node);
|
timeout = c_rbnode_entry(c_rbtree_first(&timer->tree), Timeout, node);
|
||||||
assert(!timeout || timeout->timeout);
|
c_assert(!timeout || timeout->timeout);
|
||||||
|
|
||||||
time = timeout ? timeout->timeout : 0;
|
time = timeout ? timeout->timeout : 0;
|
||||||
|
|
||||||
@@ -73,7 +74,7 @@ void timer_rearm(Timer *timer) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
NULL);
|
NULL);
|
||||||
assert(r >= 0);
|
c_assert(r >= 0);
|
||||||
|
|
||||||
timer->scheduled_timeout = time;
|
timer->scheduled_timeout = time;
|
||||||
}
|
}
|
||||||
@@ -132,8 +133,7 @@ int timer_pop_timeout(Timer *timer, uint64_t until, Timeout **timeoutp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void timeout_schedule(Timeout *timeout, Timer *timer, uint64_t time) {
|
void timeout_schedule(Timeout *timeout, Timer *timer, uint64_t time) {
|
||||||
|
c_assert(time);
|
||||||
assert(time);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* In case @timeout was already scheduled, remove it from the
|
* In case @timeout was already scheduled, remove it from the
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <c-rbtree.h>
|
#include <c-rbtree.h>
|
||||||
|
#include <c-stdaux.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
Submodule subprojects/c-list updated: dda36d30c7...2e4b605c62
Submodule subprojects/c-rbtree updated: bf627e0c32...b46392d25d
Submodule subprojects/c-siphash updated: b24d2e2048...7c42c59258
1
subprojects/c-stdaux
Submodule
1
subprojects/c-stdaux
Submodule
Submodule subprojects/c-stdaux added at 11930d2592
Reference in New Issue
Block a user