pax_global_header 0000666 0000000 0000000 00000000064 14326712445 0014522 g ustar 00root root 0000000 0000000 52 comment=5c45f5d51a832de9dbcf7b5153f2cde8fb9dc302
nftlb-1.0.7/ 0000775 0000000 0000000 00000000000 14326712445 0012634 5 ustar 00root root 0000000 0000000 nftlb-1.0.7/.gitignore 0000664 0000000 0000000 00000000273 14326712445 0014626 0 ustar 00root root 0000000 0000000 # Generated by autoconf/configure/automake
*.m4
Makefile
Makefile.in
stamp-h1
config.h.in
config.h.in~
config.log
config.status
configure
autom4te.cache
build-aux/
libnftables.pc
libtool
nftlb-1.0.7/LICENSE 0000664 0000000 0000000 00000103330 14326712445 0013641 0 ustar 00root root 0000000 0000000 GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.
When we speak of free software, we are referring to freedom, 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
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If 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 convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU Affero 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
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
.
nftlb-1.0.7/Make_global.am 0000664 0000000 0000000 00000000320 14326712445 0015343 0 ustar 00root root 0000000 0000000 AM_CPPFLAGS = -I$(top_srcdir)/include ${LIBNFTABLES_CFLAGS} \
${LIBJSON_CFLAGS} ${LIBMNL_CFLAGS}
AM_CFLAGS = -std=gnu99 -W -Wall -Wno-unused-parameter \
-Wmissing-prototypes -Wno-strict-aliasing -rdynamic
nftlb-1.0.7/Makefile.am 0000664 0000000 0000000 00000000305 14326712445 0014666 0 ustar 00root root 0000000 0000000 include Make_global.am
ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = include \
tests \
Make_global.am
SUBDIRS = src
DIST_SUBDIRS = src
LIBS = @LIBNFTABLES_LIBS@ @LIBJSON_LIBS@ @LIBMNL_LIBS@
nftlb-1.0.7/README.md 0000664 0000000 0000000 00000031412 14326712445 0014114 0 ustar 00root root 0000000 0000000 # [nftlb](https://www.zevenet.com/knowledge-base/nftlb)
**nftlb** stands for **nftables load balancer**, the next generation linux firewall that will replace iptables is adapted to behave as a complete load balancer and traffic distributor.
nftlb is provided with a JSON API, so you can use your preferred health checker to enable/disable backends or virtual services and automate processes with it.
More info: [What is nftlb?](https://www.zevenet.com/knowledge-base/nftlb/what-is-nftlb/)
## Repository Contents
In this repository is included:
- **src/**: main source code files.
- **include/**: include files.
- **tests/**: automated testbed suite with example configuration files and the script *exec_tests.sh* to run all of them.
- **tests/api**: automated testbed suite for API interactionand the script *api_tests.sh* to run all of them.
## Requirements
nftlb depends on:
- **linux-kernel**: Kernel version 4.19 or higher with nftables modules enabled (iptables, ebtables, etc not required).
- **nftables**: nftables package with **libnftables** included and its dependencies (**libgmp**, **libmnl** and **libnftnl**).
- **libev**: Events library for the web service.
- **libjansson**: JSON parser for the API.
## Installation
To build nftlb, just execute:
```
root# autoreconf -fi
root# ./configure
root# make
```
Finally, install it:
```
root# make install
```
Also, [deb packages](https://repology.org/project/nftlb/versions) are available.
## Usage
Check out the command help:
```
# ./nftlb -h
```
Here is the list of options:
**[ -h | --help ]**: Show the command help.
**[ -l <LEVEL> | --log <LEVEL> ]**: The logs will be shown in the syslog file and with this option you can change the loglevel from 0 to 7 (5 by default).
**[ -L <OUTPUT> | --log-output <OUTPUT> ]**: Set the daemon logs output (0: syslog - default, 1: stdout, 2: stderr, 3: syslog+stdout, 4: syslog+stderr).
**[ -c <FILE> | --config <FILE> ]**: Initial configuration file, this argument is optional.
**[ -k <KEY> | --key <KEY> ]**: The authentication key for the web service can be set by command line, or automatically generated. If it's automatically generated, it'll be shown by command line.
**[ -e | --exit ]**: This option executes the configuration file into nftables rules and then exit, so the web server won't be available.
**[ -d | --daemon ]**: Run nftlb as a daemon in background.
**[ -6 | --ipv6 ]**: Enable IPv6 support for the web service listening port.
**[ -H <HOST> | --host <HOST> ]**: Set the host for the web service (all interfaces by default).
**[ -P <PORT> | --port <PORT> ]**: Set the TCP port for the web service (5555 by default).
**[ -S | --serial ]**: Serialize nft commands.
**[ -m <MARK> | --masquerade-mark <MARK> ]**: Set masquerade mark in hex (80000000 by default).
Note: In order to use sNAT or dNAT modes, ensure you have activated the ip forwarding option in your system.
### Controlling the server behaviour using environment variables
You can also specify a custom server key via the `NFTLB_SERVER_KEY` environment variable. Zero length keys will be ignored.
```
root# NFTLB_SERVER_KEY="changeme" nftlb -d
```
### JSON configuration file
The configuration files have the following format:
```
{
"farms" : [
{ },
{ },
{ ... }
],
"addresses" : [
{ },
{ },
{ ... }
],
"policies" : [
{ },
{ },
{ ... }
]
}
```
Where every farm object has the following attributes:
```
{
"name" : "", *Name of the service (required)*
"family": "", *Family of the virtual service (ipv4 by default)*
"virtual-addr": "", *IP address for the virtual service (OBSOLETE)*
"virtual-ports": "", *Port list separated by commas or ranges separated by a hyphen*
"source-addr": "", *Source IP address instead of masquerading*
"mode": "", *Topology to be implemented (required)*
"protocol": "", *Protocol to be used by the virtual service (tcp by default)*
"scheduler": "", *Scheduler to be used (round robin by default)*
"sched-param": "", *Hash input parameters (none by default)*
"persistence": "", *Configured stickiness between client and backend (none by default)*
"persist-ttl": "", *Stickiness timeout in seconds (60 by default)*
"helper": "", *L7 helper to be used (none by default)*
"log": "", *Enable logging (none by default)*
"log-prefix": "", *Farm log prefix (default "TYPE-FNAME")*
"log-rtlimit": "[/]", *Security logs rate limit (0/second by default)*
"mark": "", *Set mark mask for the farm (none by default)*
"priority": "", *Priority availability for backends > 0 (1 by default)*
"limits-ttl": "", *Timeout of banned client due to limit protections (120 seconds by default)*
"new-rtlimit": "[/]", *Number of new connections per service (0/second by default)*
"new-rtlimit-burst": "", *Number of burst packets (disabled by default)*
"new-rtlimit-log-prefix": "", *Farm new rtlimit log prefix (default "KNAME-TYPE-FNAME")*
"rst-rtlimit": "[/]", *Number of tcp resets allowed (0/second by default)*
"rst-rtlimit-burst": "", *Number of burst RST packets (disabled by default)*
"rst-rtlimit-log-prefix": "", *Farm reset rtlimit log prefix (default "KNAME-TYPE-FNAME")*
"est-connlimit": "", *Number of established connections allowed (disabled by default)*
"est-connlimit-log-prefix": "", *Farm established connlimit log prefix (default "KNAME-TYPE-FNAME")*
"tcp-strict": "", *Option to avoid bogus TCP attacks (disabled by default)*
"tcp-strict-log-prefix": "", *Farm TCP strict log prefix (default "KNAME-TYPE-FNAME")*
"verdict": "", *Verdict to apply when a limit or blacklist/whitelist matches (log and default verdict per list type by default)*
"flow-offload": "", *Option to enable flow offload (disabled by default)*
"intra-connect": "", *Option to enable connectivity from the local machine (disabled by default)*
"queue": "", *Number of the queue to send the packets to userspace (disabled by default)*
"state": "", *Set the status of the virtual service (up by default)*
"addresses" : [ *List of addresses*
{},
{},
{...}
],
"backends" : [ *List of backends*
{},
{},
{...}
],
"sessions" : [ *List of static sessions. It requires persistence enabled.*
{
{},
{},
{...}
],
"policies" : [ *List of policies*
{
"name" : "",
},
{...}
]
}
```
Where every address object has the following attributes:
```
{
"name" : "", *Name of the address (required)*
"family": "", *Family of the address (ipv4 by default)*
"ip-addr": "", *IP address*
"ports": "", *Port list separated by commas or ranges separated by a hyphen*
"protocol": "", *Protocol to be used by the address (tcp by default)*
"verdict": "", *Verdict to apply when a limit or blacklist/whitelist matches (log and default verdict per list type by default)*
"log-prefix": "", *Address log prefix (default "TYPE-FNAME")*
"log-rtlimit": "[/]", *Security logs rate limit per second (0/second by default)*
}
```
Where every backend object has the following attributes:
```
{
"name" : "", *Name of the backend (required)*
"ip-addr": "", *IP address for the backend (required)*
"port": "", *Backend port to redirect the connections*
"source-addr": "", *Source IP address for a certain backend instead of masquerading or virtual service source address*
"weight": "", *Weight of the backend (1 by default)*
"priority": "", *Priority availability for the backend > 0 (1 by default)*
"mark": "", *Set mark mask for the backend (none by default)*
"est-connlimit": "", *Number of established connections allowed per backend (disabled by default)*
"est-connlimit-log-prefix": "", *Backend established connections log prefix (default "KNAME-FNAME-BNAME")*
"state": "", *Set the status of the backend (up by default)*
}
```
Where every session object has the following attributes:
```
{
"client" : "", *Client with the same format than persistence configuration*
"backend": "", *Backend ID to set a stickyness between client and backend*
"expiration": "" *Dynamic sessions timeout. Static sessions doesn't include this attribute*
}
```
Where every policy object has the following attributes:
```
{
"name" : "", *Name of the policy (required)*
"type": "", *Policy type*
"family": "", *Family of the policy (ipv4 by default)*
"log-prefix": "", *Policy established connections log prefix (default "KNAME-TYPE-PNAME-FNAME")*
"elements" : [ *List of IPs or networks*
{
"data" : ""
},
{...}
]
}
```
You can find some examples in the *tests/* folder.
### API examples
Once launched nftlb you can manage it through the API.
Virtual service listing.
```
curl -H "Key: " http://:5555/farms
```
Setup a new virtual service.
```
curl -H "Key: " -X POST http://:5555/farms -d "@tests/008_snat_ipv4_all_rr.json"
```
Add a new backend into a virtual service.
```
curl -H "Key: " -X POST http://:5555/farms -d '{"farms" : [ { "name" : "myfarm", "backends" : [ { "name" : "mynewbck", "ip-addr" : "192.168.0.150", "state" : "up" } ] } ] }'
```
Delete a virtual service.
```
curl -H "Key: " -X DELETE http://:5555/farms/lb01
```
Delete a backend of a virtual service.
```
curl -H "Key: " -X DELETE http://:5555/farms/lb01/backends/bck1
```
Get the static and dynamic sessions.
```
curl -H "Key: " -X GET http://:5555/farms/lb01/sessions
```
Addresses listing.
```
curl -H "Key: " http://:5555/addresses
```
Addresses listing.
```
curl -H "Key: " http://:5555/addresses
```
Create a new address.
```
curl -H "Key: " -X POST http://:5555/addresses -d '{ "addresses" : [ { "name" : "myaddr", "family": "ipv4", "ip-addr" : "192.168.0.150", "ports": "8080", "protocol": "tcp" } ] }'
```
Assign an address to a farm.
```
curl -H "Key: " -X POST http://:5555/farms -d '{ "farms" : [ { "name" : "myfarm", "addresses" : [ { "name" : "myaddr" } ] } ] }'
```
Delete an address.
```
curl -H "Key: " -X DELETE http://:5555/addresses/myaddr
```
Delete an assigned address.
```
curl -H "Key: " -X DELETE http://:5555/farms/myfarm/addresses/myaddr
```
Delete an address.
```
curl -H "Key: " -X DELETE http://:5555/addresses/myaddr
```
## How it works
nftlb uses the nftables infrastructure to build virtual services, from user to kernel side. In that regard, the expressions **numgen** (with its **random** and **inc** modes) and **hash** (say **jhash** and **symhash**) allows to distribute traffic among several backends among other properties. More information:
[https://wiki.nftables.org/wiki-nftables/index.php/Load_balancing](https://wiki.nftables.org/wiki-nftables/index.php/Load_balancing)
[https://www.netfilter.org/projects/nftables/manpage.html](https://www.netfilter.org/projects/nftables/manpage.html)
This software creates the required tables named **nftlb** which are exclusive to the nftlb service and should not be managed manually. Ex: ip nftlb, ip6 nftlb, netdev nftlb...
The integration of nftlb with custom firewall rules are possible creating separated tables and playing with chain priorities. More information:
[https://www.zevenet.com/knowledge-base_category/nftlb/](https://www.zevenet.com/knowledge-base_category/nftlb/)
## Support
Please refer to the [netfilter users mailing list](http://netfilter.org/mailinglists.html#ml-user)
nftlb-1.0.7/configure.ac 0000664 0000000 0000000 00000001375 14326712445 0015130 0 ustar 00root root 0000000 0000000 AC_INIT([nftlb], [1.0.7], [netfilter-devel@vger.kernel.org])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([-Wall foreign subdir-objects
tar-pax no-dist-gzip dist-bzip2 1.6])
dnl kernel style compile messages
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
AC_PROG_CC
AC_PROG_MKDIR_P
AM_PROG_AR
AM_PROG_LIBTOOL
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_SED
PKG_CHECK_MODULES([LIBNFTABLES], [libnftables >= 0.9])
PKG_CHECK_MODULES([LIBJSON], [jansson >= 2.3])
PKG_CHECK_MODULES([LIBMNL], [libmnl >= 1.0.4])
AC_CHECK_HEADER([ev.h], [EVENTINC="-include ev.h"],
[AC_CHECK_HEADER([libev/ev.h],
[EVENTINC="-include libev/ev.h"],
[AC_MSG_ERROR([ev.h not found])])])
AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT
nftlb-1.0.7/include/ 0000775 0000000 0000000 00000000000 14326712445 0014257 5 ustar 00root root 0000000 0000000 nftlb-1.0.7/include/addresses.h 0000664 0000000 0000000 00000005073 14326712445 0016412 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#ifndef _ADDRESSES_H_
#define _ADDRESSES_H_
#include "list.h"
#include "config.h"
struct address {
struct list_head list;
int action;
char *name;
char *fqdn;
char *iface;
char *iethaddr;
int ifidx;
char *ipaddr;
char *ports;
int family;
int protocol;
int verdict;
char *logprefix;
int logrtlimit;
int logrtlimit_unit;
struct list_head policies;
int policies_used;
int policies_action;
int used;
int nft_chains;
int port_list[NFTLB_MAX_PORTS];
int nports;
};
struct address * address_create(char *name);
int address_changed(struct config_pair *c);
void address_s_print(void);
void address_s_farm_print(struct farm *f);
struct address * address_lookup_by_name(const char *name);
int address_pre_actionable(struct config_pair *c);
int address_pos_actionable(struct config_pair *c);
int address_set_attribute(struct config_pair *c);
int address_set_action(struct address *a, int action);
int address_s_set_action(int action);
int address_s_lookup_policy_action(char *name, int action);
int address_no_port(struct address *a);
int address_no_ipaddr(struct address *a);
void address_print(struct address *a);
int address_set_netinfo(struct address *a);
int address_set_ports(struct address *a, char *new_value);
int address_rulerize(struct address *a);
int address_s_rulerize(void);
int address_needs_policies(struct address *a);
int address_set_protocol(struct address *a, int new_value);
int address_not_used(struct address *a);
int address_delete(struct address *paddress);
int address_search_array_port(struct address *a, int port);
int address_validate_iface(struct address *a);
int address_validate_iether(struct address *a);
int address_s_clean_nft_chains(void);
#endif /* _ADDRESSES_H_ */
nftlb-1.0.7/include/addresspolicy.h 0000664 0000000 0000000 00000003163 14326712445 0017300 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#ifndef _ADDRESSPOLICY_H_
#define _ADDRESSPOLICY_H_
#include "addresses.h"
#include "policies.h"
struct addresspolicy {
struct list_head list;
struct address *address;
struct policy *policy;
int action;
};
void addresspolicy_s_print(struct address *a);
struct addresspolicy * addresspolicy_lookup_by_name(struct address *a, const char *name);
int addresspolicy_set_attribute(struct config_pair *c);
int addresspolicy_set_action(struct addresspolicy *ap, int action);
int addresspolicy_s_set_action(struct address *a, int action);
int addresspolicy_s_delete(struct address *a);
int addresspolicy_s_lookup_policy_action(struct address *a, char *name, int action);
int addresspolicy_pre_actionable(struct config_pair *c);
int addresspolicy_pos_actionable(struct config_pair *c);
#endif /* _ADDRESSPOLICY_H_ */
nftlb-1.0.7/include/backends.h 0000664 0000000 0000000 00000004417 14326712445 0016210 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#ifndef _BACKENDS_H_
#define _BACKENDS_H_
#include "farms.h"
struct backend {
struct list_head list;
struct farm *parent;
int action;
char *name;
char *fqdn;
char *ipaddr;
char *ethaddr;
int ofidx;
char *oface;
char *port;
char *srcaddr;
int weight;
int priority;
int mark;
int estconnlimit;
char *estconnlimit_logprefix;
int state;
};
void backend_s_print(struct farm *f);
struct backend * backend_lookup_by_key(struct farm *f, int key, const char *name, int value);
int backend_validate(struct backend *b);
int backend_is_available(struct backend *b);
int backend_set_action(struct backend *b, int action);
int backend_s_set_action(struct farm *f, int action);
int backend_s_validate(struct farm *f);
int backend_s_delete(struct farm *f);
int backend_set_attribute(struct config_pair *c);
int backend_set_state(struct backend *b, int new_value);
int backend_s_set_ether_by_ipaddr(struct farm *f, const char *ip_bck, char *ether_bck);
int backend_s_set_netinfo(struct farm *f);
struct backend * backend_get_first(struct farm *f);
int backend_is_usable(struct backend *b);
int backend_no_port(struct backend *b);
int backend_changed(struct config_pair *c);
int bck_pre_actionable(struct config_pair *c);
int bck_pos_actionable(struct config_pair *c, int action);
int backend_s_gen_priority(struct farm *f, int action);
int backend_get_mark(struct backend *b);
int backend_s_check_have_iface(struct farm *f);
#endif /* _BACKENDS_H_ */
nftlb-1.0.7/include/checksum.h 0000664 0000000 0000000 00000002104 14326712445 0016227 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2011-2015 P.D. Buchan (pdbuchan@yahoo.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#ifndef _CHECKSUM_H_
#define _CHECKSUM_H_
#include
#define ETHER_HDRLEN 14
#define IP4_HDRLEN 20
#define IP6_HDRLEN 40
#define ICMP_HDRLEN 8
#define ICMP_DATALEN 4
uint16_t checksum(uint16_t *addr, int len);
uint16_t icmp6_checksum(struct ip6_hdr iphdr, struct icmp6_hdr icmp6hdr, uint8_t *payload, int payloadlen);
#endif /* _CHECKSUM_H_ */
nftlb-1.0.7/include/config.h 0000664 0000000 0000000 00000017042 14326712445 0015701 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#ifndef _CONFIG_H_
#define _CONFIG_H_
#include "objects.h"
#define CONFIG_KEY_FARMS "farms"
#define CONFIG_KEY_NAME "name"
#define CONFIG_KEY_NEWNAME "newname"
#define CONFIG_KEY_FQDN "fqdn"
#define CONFIG_KEY_IFACE "iface"
#define CONFIG_KEY_OFACE "oface"
#define CONFIG_KEY_FAMILY "family"
#define CONFIG_KEY_ETHADDR "ether-addr"
#define CONFIG_KEY_IETHADDR "iether-addr"
#define CONFIG_KEY_OETHADDR "oether-addr"
#define CONFIG_KEY_VIRTADDR "virtual-addr"
#define CONFIG_KEY_VIRTPORTS "virtual-ports"
#define CONFIG_KEY_IPADDR "ip-addr"
#define CONFIG_KEY_SRCADDR "source-addr"
#define CONFIG_KEY_PORT "port"
#define CONFIG_KEY_PORTS "ports"
#define CONFIG_KEY_MODE "mode"
#define CONFIG_KEY_RESPONSETTL "responsettl"
#define CONFIG_KEY_PROTO "protocol"
#define CONFIG_KEY_SCHED "scheduler"
#define CONFIG_KEY_SCHEDPARAM "sched-param"
#define CONFIG_KEY_PERSIST "persistence"
#define CONFIG_KEY_PERSISTTM "persist-ttl"
#define CONFIG_KEY_HELPER "helper"
#define CONFIG_KEY_LOG "log"
#define CONFIG_KEY_LOGPREFIX "log-prefix"
#define CONFIG_KEY_LOG_RTLIMIT "log-rtlimit"
#define CONFIG_KEY_MARK "mark"
#define CONFIG_KEY_STATE "state"
#define CONFIG_KEY_BCKS "backends"
#define CONFIG_KEY_WEIGHT "weight"
#define CONFIG_KEY_PRIORITY "priority"
#define CONFIG_KEY_ACTION "action"
#define CONFIG_KEY_LIMITSTTL "limits-ttl"
#define CONFIG_KEY_NEWRTLIMIT "new-rtlimit"
#define CONFIG_KEY_NEWRTLIMITBURST "new-rtlimit-burst"
#define CONFIG_KEY_NEWRTLIMIT_LOGPREFIX "new-rtlimit-log-prefix"
#define CONFIG_KEY_RSTRTLIMIT "rst-rtlimit"
#define CONFIG_KEY_RSTRTLIMITBURST "rst-rtlimit-burst"
#define CONFIG_KEY_RSTRTLIMIT_LOGPREFIX "rst-rtlimit-log-prefix"
#define CONFIG_KEY_ESTCONNLIMIT "est-connlimit"
#define CONFIG_KEY_ESTCONNLIMIT_LOGPREFIX "est-connlimit-log-prefix"
#define CONFIG_KEY_TCPSTRICT "tcp-strict"
#define CONFIG_KEY_TCPSTRICT_LOGPREFIX "tcp-strict-log-prefix"
#define CONFIG_KEY_QUEUE "queue"
#define CONFIG_KEY_FLOWOFFLOAD "flow-offload"
#define CONFIG_KEY_POLICIES "policies"
#define CONFIG_KEY_TYPE "type"
#define CONFIG_KEY_TIMEOUT "timeout"
#define CONFIG_KEY_ELEMENTS "elements"
#define CONFIG_KEY_DATA "data"
#define CONFIG_KEY_TIME "time"
#define CONFIG_KEY_SESSIONS "sessions"
#define CONFIG_KEY_CLIENT "client"
#define CONFIG_KEY_BACKEND "backend"
#define CONFIG_KEY_INTRACONNECT "intra-connect"
#define CONFIG_KEY_USED "used"
#define CONFIG_KEY_EXPIRATION "expiration"
#define CONFIG_KEY_ADDRESSES "addresses"
#define CONFIG_KEY_ROUTE "route"
#define CONFIG_KEY_VERDICT "verdict"
#define CONFIG_KEY_COUNTER_PACKETS "counter-packets"
#define CONFIG_KEY_COUNTER_BYTES "counter-bytes"
#define CONFIG_VALUE_FAMILY_IPV4 "ipv4"
#define CONFIG_VALUE_FAMILY_IPV6 "ipv6"
#define CONFIG_VALUE_FAMILY_INET "inet"
#define CONFIG_VALUE_MODE_SNAT "snat"
#define CONFIG_VALUE_MODE_DNAT "dnat"
#define CONFIG_VALUE_MODE_DSR "dsr"
#define CONFIG_VALUE_MODE_STLSDNAT "stlsdnat"
#define CONFIG_VALUE_MODE_LOCAL "local"
#define CONFIG_VALUE_PROTO_TCP "tcp"
#define CONFIG_VALUE_PROTO_UDP "udp"
#define CONFIG_VALUE_PROTO_SCTP "sctp"
#define CONFIG_VALUE_PROTO_ALL "all"
#define CONFIG_VALUE_SCHED_RR "rr"
#define CONFIG_VALUE_SCHED_WEIGHT "weight"
#define CONFIG_VALUE_SCHED_HASH "hash"
#define CONFIG_VALUE_SCHED_SYMHASH "symhash"
#define CONFIG_VALUE_META_NONE "none"
#define CONFIG_VALUE_META_SRCIP "srcip"
#define CONFIG_VALUE_META_DSTIP "dstip"
#define CONFIG_VALUE_META_SRCPORT "srcport"
#define CONFIG_VALUE_META_DSTPORT "dstport"
#define CONFIG_VALUE_META_SRCMAC "srcmac"
#define CONFIG_VALUE_META_DSTMAC "dstmac"
#define CONFIG_VALUE_HELPER_NONE "none"
#define CONFIG_VALUE_HELPER_FTP "ftp"
#define CONFIG_VALUE_HELPER_PPTP "pptp"
#define CONFIG_VALUE_HELPER_SIP "sip"
#define CONFIG_VALUE_HELPER_SNMP "snmp"
#define CONFIG_VALUE_HELPER_TFTP "tftp"
#define CONFIG_VALUE_LOG_NONE "none"
#define CONFIG_VALUE_LOG_INPUT "input"
#define CONFIG_VALUE_LOG_FORWARD "forward"
#define CONFIG_VALUE_LOG_OUTPUT "output"
#define CONFIG_VALUE_STATE_UP "up"
#define CONFIG_VALUE_STATE_AVAIL "available"
#define CONFIG_VALUE_STATE_DOWN "down"
#define CONFIG_VALUE_STATE_OFF "off"
#define CONFIG_VALUE_STATE_CONFERR "config_error"
#define CONFIG_VALUE_ACTION_DELETE "delete"
#define CONFIG_VALUE_ACTION_STOP "stop"
#define CONFIG_VALUE_ACTION_START "start"
#define CONFIG_VALUE_ACTION_RELOAD "reload"
#define CONFIG_VALUE_ACTION_NONE "none"
#define CONFIG_VALUE_ACTION_FLUSH "flush"
#define CONFIG_VALUE_SWITCH_ON "on"
#define CONFIG_VALUE_SWITCH_OFF "off"
#define CONFIG_VALUE_POLICIES_TYPE_BL "blacklist"
#define CONFIG_VALUE_POLICIES_TYPE_WL "whitelist"
#define CONFIG_VALUE_ROUTE_IN "in"
#define CONFIG_VALUE_ROUTE_OUT "out"
#define CONFIG_VALUE_VERDICT_NONE "none"
#define CONFIG_VALUE_VERDICT_LOG "log"
#define CONFIG_VALUE_VERDICT_DROP "drop"
#define CONFIG_VALUE_VERDICT_ACCEPT "accept"
#define CONFIG_VALUE_UNIT_SECOND "second"
#define CONFIG_VALUE_UNIT_MINUTE "minute"
#define CONFIG_VALUE_UNIT_HOUR "hour"
#define CONFIG_VALUE_UNIT_DAY "day"
#define CONFIG_VALUE_UNIT_WEEK "week"
enum config_parser_output {
PARSER_OK,
PARSER_FAILED,
PARSER_IGNORE,
PARSER_STRUCT_FAILED,
PARSER_VALID_FAILED,
PARSER_IDEM_VALUE,
PARSER_OBJ_UNKNOWN,
};
enum config_src {
CONFIG_SRC_FILE,
CONFIG_SRC_BUFFER,
};
struct config_pair {
enum levels level;
enum keys key;
char *str_value;
int int_value;
int int_value2;
int action;
};
void config_pair_init(struct config_pair *c);
char *config_get_output(void);
void config_delete_output(void);
void config_set_output(char *fmt, ...);
int config_file(const char *file);
int config_buffer(const char *buf, int apply_action);
int config_print_farms(char **buf, char *name);
int config_print_farm_sessions(char **buf, char *name);
int config_print_policies(char **buf, char *name);
int config_set_farm_action(const char *name, const char *value);
int config_set_session_backend_action(const char *fname, const char *bname, const char *value);
int config_set_backend_action(const char *fname, const char *bname, const char *value);
int config_set_session_action(const char *fname, const char *sname, const char *value);
int config_set_fpolicy_action(const char *fname, const char *fpname, const char *value);
int config_set_policy_action(const char *name, const char *value);
int config_set_element_action(const char *pname, const char *edata, const char *value);
int config_get_elements(const char *pname);
int config_delete_elements(const char *pname);
void config_print_response(char **buf, char *fmt, ...);
int config_set_address_action(const char *name, const char *value);
int config_set_farmaddress_action(const char *fname, const char *faname, const char *value);
int config_print_addresses(char **buf, char *name);
int config_check_policy(const char *name);
#endif /* _CONFIG_H_ */
nftlb-1.0.7/include/elements.h 0000664 0000000 0000000 00000003000 14326712445 0016235 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#ifndef _ELEMENTS_H_
#define _ELEMENTS_H_
#include "policies.h"
struct element {
struct list_head list;
struct policy *policy;
char *data;
char *time;
int action;
char *counter_pkts;
char *counter_bytes;
};
void element_s_print(struct policy *p);
struct element * element_lookup_by_name(struct policy *p, const char *data);
int element_set_action(struct element *e, int action);
int element_s_set_action(struct policy *p, int action);
int element_s_delete(struct policy *p);
int element_set_attribute(struct config_pair *c, int apply_action);
int element_pos_actionable(struct config_pair *c, int apply_action);
int element_get_list(struct policy *p);
#endif /* _ELEMENTS_H_ */
nftlb-1.0.7/include/events.h 0000664 0000000 0000000 00000002261 14326712445 0015735 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#ifndef _EVENTS_H_
#define _EVENTS_H_
#include
int loop_init(void);
int loop_run(void);
struct ev_loop *get_loop(void);
struct ev_io *events_get_ntlnk(void);
struct ev_io *events_create_ntlnk(void);
void events_delete_ntlnk(void);
struct ev_io *events_get_srv(void);
struct ev_io *events_create_srv(void);
void events_delete_srv(void);
#endif /* _EVENTS_H_ */
nftlb-1.0.7/include/farmaddress.h 0000664 0000000 0000000 00000003730 14326712445 0016726 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#ifndef _FARMADDRESS_H_
#define _FARMADDRESS_H_
#include "farms.h"
#include "addresses.h"
struct farmaddress {
struct list_head list;
struct farm *farm;
struct address *address;
int action;
};
void farmaddress_s_print(struct farm *f);
struct farmaddress * farmaddress_lookup_by_name(struct farm *f, const char *name);
int farmaddress_s_lookup_address_action(struct farm *f, char *name, int action);
int farmaddress_set_attribute(struct config_pair *c);
int farmaddress_set_action(struct farmaddress *fa, int action);
int farmaddress_s_set_action(struct farm *f, int action);
int farmaddress_s_delete(struct farm *f);
int farmaddress_pre_actionable(struct config_pair *c);
int farmaddress_pos_actionable(struct config_pair *c);
int farmaddress_s_validate_iface(struct farm *f);
int farmaddress_s_validate_oface(struct farm *f);
int farmaddress_s_set_attribute(struct farm *f, struct config_pair *c);
int farmaddress_create_default(struct config_pair *c);
struct farmaddress * farmaddress_get_first(struct farm *f);
int farmaddress_s_validate_helper(struct farm *f, int new_value);
int farmaddress_rename_default(struct config_pair *c);
#endif /* _FARMADDRESS_H_ */
nftlb-1.0.7/include/farmpolicy.h 0000664 0000000 0000000 00000003055 14326712445 0016600 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#ifndef _FARMPOLICY_H_
#define _FARMPOLICY_H_
#include "farms.h"
#include "policies.h"
struct farmpolicy {
struct list_head list;
struct farm *farm;
struct policy *policy;
int action;
};
void farmpolicy_s_print(struct farm *f);
struct farmpolicy * farmpolicy_lookup_by_name(struct farm *f, const char *name);
int farmpolicy_set_attribute(struct config_pair *c);
int farmpolicy_set_action(struct farmpolicy *fp, int action);
int farmpolicy_s_set_action(struct farm *f, int action);
int farmpolicy_s_delete(struct farm *f);
int farmpolicy_s_lookup_policy_action(struct farm *f, char *name, int action);
int farmpolicy_pre_actionable(struct config_pair *c);
int farmpolicy_pos_actionable(struct config_pair *c);
#endif /* _FARMPOLICY_H_ */
nftlb-1.0.7/include/farms.h 0000664 0000000 0000000 00000012732 14326712445 0015545 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#ifndef _FARMS_H_
#define _FARMS_H_
#include "list.h"
#include "config.h"
#include "nftst.h"
enum modes {
VALUE_MODE_SNAT,
VALUE_MODE_DNAT,
VALUE_MODE_DSR,
VALUE_MODE_STLSDNAT,
VALUE_MODE_LOCAL,
};
enum protocols {
VALUE_PROTO_ALL,
VALUE_PROTO_TCP,
VALUE_PROTO_UDP,
VALUE_PROTO_SCTP,
};
enum schedulers {
VALUE_SCHED_RR,
VALUE_SCHED_WEIGHT,
VALUE_SCHED_HASH,
VALUE_SCHED_SYMHASH,
};
enum helpers {
VALUE_HELPER_NONE,
VALUE_HELPER_FTP,
VALUE_HELPER_PPTP,
VALUE_HELPER_SIP,
VALUE_HELPER_SNMP,
VALUE_HELPER_TFTP,
};
enum states {
VALUE_STATE_UP, // available and enabled
VALUE_STATE_AVAIL, // available but not enabled due to priority
VALUE_STATE_DOWN, // temporary not available due to a problem
VALUE_STATE_OFF, // disabled manually due to maintenance
VALUE_STATE_CONFERR, // disabled due to a configuration error
};
enum switches {
VALUE_SWITCH_OFF,
VALUE_SWITCH_ON,
};
#define VALUE_META_NONE 0
#define VALUE_META_SRCIP (1 << 0)
#define VALUE_META_DSTIP (1 << 1)
#define VALUE_META_SRCPORT (1 << 2)
#define VALUE_META_DSTPORT (1 << 3)
#define VALUE_META_SRCMAC (1 << 4)
#define VALUE_META_DSTMAC (1 << 5)
#define VALUE_META_MARK (1 << 6)
#define VALUE_LOG_NONE 0
#define VALUE_LOG_INPUT (1 << 0)
#define VALUE_LOG_FORWARD (1 << 1)
#define VALUE_LOG_OUTPUT (1 << 2)
#define VALUE_RLD_NONE 0
#define VALUE_RLD_NEWRTLIMIT_START (1 << 0)
#define VALUE_RLD_RSTRTLIMIT_START (1 << 1)
#define VALUE_RLD_ESTCONNLIMIT_START (1 << 2)
#define VALUE_RLD_TCPSTRICT_START (1 << 3)
#define VALUE_RLD_QUEUE_START (1 << 4)
#define VALUE_RLD_NEWRTLIMIT_STOP (1 << 5)
#define VALUE_RLD_RSTRTLIMIT_STOP (1 << 6)
#define VALUE_RLD_ESTCONNLIMIT_STOP (1 << 7)
#define VALUE_RLD_TCPSTRICT_STOP (1 << 8)
#define VALUE_RLD_QUEUE_STOP (1 << 9)
#define STATEFUL_RLD_START(x) (x & VALUE_RLD_NEWRTLIMIT_START) || (x & VALUE_RLD_RSTRTLIMIT_START) || (x & VALUE_RLD_ESTCONNLIMIT_START) || (x & VALUE_RLD_TCPSTRICT_START)
#define STATEFUL_RLD_STOP(x) (x & VALUE_RLD_NEWRTLIMIT_STOP) || (x & VALUE_RLD_RSTRTLIMIT_STOP) || (x & VALUE_RLD_ESTCONNLIMIT_STOP) || (x & VALUE_RLD_TCPSTRICT_STOP)
struct farm {
struct list_head list;
int action;
int reload_action;
char *name;
char *fqdn;
char *oface;
char *oethaddr;
int ofidx;
char *srcaddr;
int mode;
int responsettl;
int scheduler;
int schedparam;
int persistence;
int persistttl;
int helper;
int log;
char *logprefix;
int logrtlimit;
int logrtlimit_unit;
int mark;
int state;
int priority;
int limitsttl;
int newrtlimit;
int newrtlimit_unit;
int newrtlimitbst;
char *newrtlimit_logprefix;
int rstrtlimit;
int rstrtlimit_unit;
int rstrtlimitbst;
char *rstrtlimit_logprefix;
int estconnlimit;
char *estconnlimit_logprefix;
int tcpstrict;
char *tcpstrict_logprefix;
int queue;
int verdict;
int flow_offload;
int intra_connect;
int total_weight;
int total_bcks;
int bcks_available;
int bcks_usable;
int bcks_have_port;
int bcks_have_srcaddr;
int bcks_have_if;
int policies_action;
int policies_used;
int nft_chains;
struct list_head backends;
struct list_head policies;
int total_timed_sessions;
struct list_head timed_sessions;
int total_static_sessions;
struct list_head static_sessions;
struct list_head addresses;
int addresses_used;
};
struct list_head * farm_s_get_head(void);
int farm_set_priority(struct farm *f, int new_value);
void farm_s_print(void);
int farm_is_ingress_mode(struct farm *f);
int farm_needs_policies(struct farm *f);
int farm_has_source_address(struct farm *f);
int farm_needs_flowtable(struct farm *f);
int farm_needs_intraconnect(struct farm *f);
struct farm * farm_get_first(void);
int farm_set_iface_info(struct farm *f);
int farm_set_oface_info(struct farm *f);
struct farm * farm_lookup_by_name(const char *name);
int farm_is_available(struct farm *f);
int farm_changed(struct config_pair *c);
int farm_actionable(struct config_pair *c);
int farm_pre_actionable(struct config_pair *c);
int farm_pos_actionable(struct config_pair *c);
int farm_set_attribute(struct config_pair *c);
int farm_set_action(struct farm *f, int action);
int farm_s_set_action(int action);
int farm_get_masquerade(struct farm *f);
void farm_s_set_backend_ether_by_oifidx(int interface_idx, const char * ip_bck, char * ether_bck);
int farm_s_lookup_policy_action(char *name, int action);
int farm_s_lookup_address_action(char *name, int action);
int farm_rulerize(struct farm *f);
int farm_s_rulerize(void);
int farm_get_mark(struct farm *f);
void farm_s_set_oface_info(struct address *a);
int farm_s_set_reload_start(int action);
int farm_s_clean_nft_chains(void);
#endif /* _FARMS_H_ */
nftlb-1.0.7/include/list.h 0000664 0000000 0000000 00000043571 14326712445 0015415 0 ustar 00root root 0000000 0000000 #ifndef _LINUX_LIST_H
#define _LINUX_LIST_H
#include
#define prefetch(x) ((void)0)
#define LIST_POISON1 ((void *)0x12345678)
#define LIST_POISON2 ((void *)0x87654321)
/*
* Simple doubly linked list implementation.
*
* Some of the internal functions ("__xxx") are useful when
* manipulating whole lists rather than single entries, as
* sometimes we already know the next/prev entries and we can
* generate better code by using them directly rather than
* using the generic single-entry routines.
*/
struct list_head {
struct list_head *next, *prev;
};
#define LIST_HEAD_INIT(name) { &(name), &(name) }
#define LIST_HEAD(name) \
struct list_head name = LIST_HEAD_INIT(name)
#define container_of(ptr, type, member) ({ \
typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (void *)__mptr - offsetof(type,member) );})
static inline void init_list_head(struct list_head *list)
{
list->next = list;
list->prev = list;
}
/*
* Insert a new entry between two known consecutive entries.
*
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
static inline void __list_add(struct list_head *new,
struct list_head *prev,
struct list_head *next)
{
next->prev = new;
new->next = next;
new->prev = prev;
prev->next = new;
}
/**
* list_add - add a new entry
* @new: new entry to be added
* @head: list head to add it after
*
* Insert a new entry after the specified head.
* This is good for implementing stacks.
*/
static inline void list_add(struct list_head *new, struct list_head *head)
{
__list_add(new, head, head->next);
}
/**
* list_add_tail - add a new entry
* @new: new entry to be added
* @head: list head to add it before
*
* Insert a new entry before the specified head.
* This is useful for implementing queues.
*/
static inline void list_add_tail(struct list_head *new, struct list_head *head)
{
__list_add(new, head->prev, head);
}
/*
* Delete a list entry by making the prev/next entries
* point to each other.
*
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
static inline void __list_del(struct list_head * prev, struct list_head * next)
{
next->prev = prev;
prev->next = next;
}
/**
* list_del - deletes entry from list.
* @entry: the element to delete from the list.
* Note: list_empty() on entry does not return true after this, the entry is
* in an undefined state.
*/
static inline void list_del(struct list_head *entry)
{
__list_del(entry->prev, entry->next);
entry->next = LIST_POISON1;
entry->prev = LIST_POISON2;
}
/**
* list_replace - replace old entry by new one
* @old : the element to be replaced
* @new : the new element to insert
*
* If @old was empty, it will be overwritten.
*/
static inline void list_replace(struct list_head *old,
struct list_head *new)
{
new->next = old->next;
new->next->prev = new;
new->prev = old->prev;
new->prev->next = new;
}
static inline void list_replace_init(struct list_head *old,
struct list_head *new)
{
list_replace(old, new);
init_list_head(old);
}
/**
* list_del_init - deletes entry from list and reinitialize it.
* @entry: the element to delete from the list.
*/
static inline void list_del_init(struct list_head *entry)
{
__list_del(entry->prev, entry->next);
init_list_head(entry);
}
/**
* list_move - delete from one list and add as another's head
* @list: the entry to move
* @head: the head that will precede our entry
*/
static inline void list_move(struct list_head *list, struct list_head *head)
{
__list_del(list->prev, list->next);
list_add(list, head);
}
/**
* list_move_tail - delete from one list and add as another's tail
* @list: the entry to move
* @head: the head that will follow our entry
*/
static inline void list_move_tail(struct list_head *list,
struct list_head *head)
{
__list_del(list->prev, list->next);
list_add_tail(list, head);
}
/**
* list_is_last - tests whether @list is the last entry in list @head
* @list: the entry to test
* @head: the head of the list
*/
static inline int list_is_last(const struct list_head *list,
const struct list_head *head)
{
return list->next == head;
}
/**
* list_empty - tests whether a list is empty
* @head: the list to test.
*/
static inline int list_empty(const struct list_head *head)
{
return head->next == head;
}
/**
* list_empty_careful - tests whether a list is empty and not being modified
* @head: the list to test
*
* Description:
* tests whether a list is empty _and_ checks that no other CPU might be
* in the process of modifying either member (next or prev)
*
* NOTE: using list_empty_careful() without synchronization
* can only be safe if the only activity that can happen
* to the list entry is list_del_init(). Eg. it cannot be used
* if another CPU could re-list_add() it.
*/
static inline int list_empty_careful(const struct list_head *head)
{
struct list_head *next = head->next;
return (next == head) && (next == head->prev);
}
/**
* list_is_singular - tests whether a list has just one entry.
* @head: the list to test.
*/
static inline int list_is_singular(const struct list_head *head)
{
return !list_empty(head) && (head->next == head->prev);
}
static inline void __list_cut_position(struct list_head *list,
struct list_head *head, struct list_head *entry)
{
struct list_head *new_first = entry->next;
list->next = head->next;
list->next->prev = list;
list->prev = entry;
entry->next = list;
head->next = new_first;
new_first->prev = head;
}
/**
* list_cut_position - cut a list into two
* @list: a new list to add all removed entries
* @head: a list with entries
* @entry: an entry within head, could be the head itself
* and if so we won't cut the list
*
* This helper moves the initial part of @head, up to and
* including @entry, from @head to @list. You should
* pass on @entry an element you know is on @head. @list
* should be an empty list or a list you do not care about
* losing its data.
*
*/
static inline void list_cut_position(struct list_head *list,
struct list_head *head, struct list_head *entry)
{
if (list_empty(head))
return;
if (list_is_singular(head) &&
(head->next != entry && head != entry))
return;
if (entry == head)
init_list_head(list);
else
__list_cut_position(list, head, entry);
}
static inline void __list_splice(const struct list_head *list,
struct list_head *prev,
struct list_head *next)
{
struct list_head *first = list->next;
struct list_head *last = list->prev;
first->prev = prev;
prev->next = first;
last->next = next;
next->prev = last;
}
/**
* list_splice - join two lists, this is designed for stacks
* @list: the new list to add.
* @head: the place to add it in the first list.
*/
static inline void list_splice(const struct list_head *list,
struct list_head *head)
{
if (!list_empty(list))
__list_splice(list, head, head->next);
}
/**
* list_splice_tail - join two lists, each list being a queue
* @list: the new list to add.
* @head: the place to add it in the first list.
*/
static inline void list_splice_tail(struct list_head *list,
struct list_head *head)
{
if (!list_empty(list))
__list_splice(list, head->prev, head);
}
/**
* list_splice_init - join two lists and reinitialise the emptied list.
* @list: the new list to add.
* @head: the place to add it in the first list.
*
* The list at @list is reinitialised
*/
static inline void list_splice_init(struct list_head *list,
struct list_head *head)
{
if (!list_empty(list)) {
__list_splice(list, head, head->next);
init_list_head(list);
}
}
/**
* list_splice_tail_init - join two lists and reinitialise the emptied list
* @list: the new list to add.
* @head: the place to add it in the first list.
*
* Each of the lists is a queue.
* The list at @list is reinitialised
*/
static inline void list_splice_tail_init(struct list_head *list,
struct list_head *head)
{
if (!list_empty(list)) {
__list_splice(list, head->prev, head);
init_list_head(list);
}
}
/**
* list_entry - get the struct for this entry
* @ptr: the &struct list_head pointer.
* @type: the type of the struct this is embedded in.
* @member: the name of the list_struct within the struct.
*/
#define list_entry(ptr, type, member) \
container_of(ptr, type, member)
/**
* list_first_entry - get the first element from a list
* @ptr: the list head to take the element from.
* @type: the type of the struct this is embedded in.
* @member: the name of the list_struct within the struct.
*
* Note, that list is expected to be not empty.
*/
#define list_first_entry(ptr, type, member) \
list_entry((ptr)->next, type, member)
/**
* list_for_each_entry - iterate over list of given type
* @pos: the type * to use as a loop cursor.
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry(pos, head, member) \
for (pos = list_entry((head)->next, typeof(*pos), member); \
prefetch(pos->member.next), &pos->member != (head); \
pos = list_entry(pos->member.next, typeof(*pos), member))
/**
* list_for_each_entry_reverse - iterate backwards over list of given type.
* @pos: the type * to use as a loop cursor.
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry_reverse(pos, head, member) \
for (pos = list_entry((head)->prev, typeof(*pos), member); \
prefetch(pos->member.prev), &pos->member != (head); \
pos = list_entry(pos->member.prev, typeof(*pos), member))
/**
* list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
* @pos: the type * to use as a start point
* @head: the head of the list
* @member: the name of the list_struct within the struct.
*
* Prepares a pos entry for use as a start point in list_for_each_entry_continue().
*/
#define list_prepare_entry(pos, head, member) \
((pos) ? : list_entry(head, typeof(*pos), member))
/**
* list_for_each_entry_continue - continue iteration over list of given type
* @pos: the type * to use as a loop cursor.
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*
* Continue to iterate over list of given type, continuing after
* the current position.
*/
#define list_for_each_entry_continue(pos, head, member) \
for (pos = list_entry(pos->member.next, typeof(*pos), member); \
prefetch(pos->member.next), &pos->member != (head); \
pos = list_entry(pos->member.next, typeof(*pos), member))
/**
* list_for_each_entry_continue_reverse - iterate backwards from the given point
* @pos: the type * to use as a loop cursor.
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*
* Start to iterate over list of given type backwards, continuing after
* the current position.
*/
#define list_for_each_entry_continue_reverse(pos, head, member) \
for (pos = list_entry(pos->member.prev, typeof(*pos), member); \
prefetch(pos->member.prev), &pos->member != (head); \
pos = list_entry(pos->member.prev, typeof(*pos), member))
/**
* list_for_each_entry_from - iterate over list of given type from the current point
* @pos: the type * to use as a loop cursor.
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*
* Iterate over list of given type, continuing from current position.
*/
#define list_for_each_entry_from(pos, head, member) \
for (; prefetch(pos->member.next), &pos->member != (head); \
pos = list_entry(pos->member.next, typeof(*pos), member))
/**
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
* @pos: the type * to use as a loop cursor.
* @n: another type * to use as temporary storage
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry_safe(pos, n, head, member) \
for (pos = list_entry((head)->next, typeof(*pos), member), \
n = list_entry(pos->member.next, typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, typeof(*n), member))
/**
* list_for_each_entry_safe_continue
* @pos: the type * to use as a loop cursor.
* @n: another type * to use as temporary storage
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*
* Iterate over list of given type, continuing after current point,
* safe against removal of list entry.
*/
#define list_for_each_entry_safe_continue(pos, n, head, member) \
for (pos = list_entry(pos->member.next, typeof(*pos), member), \
n = list_entry(pos->member.next, typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, typeof(*n), member))
/**
* list_for_each_entry_safe_from
* @pos: the type * to use as a loop cursor.
* @n: another type * to use as temporary storage
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*
* Iterate over list of given type from current point, safe against
* removal of list entry.
*/
#define list_for_each_entry_safe_from(pos, n, head, member) \
for (n = list_entry(pos->member.next, typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, typeof(*n), member))
/**
* list_for_each_entry_safe_reverse
* @pos: the type * to use as a loop cursor.
* @n: another type * to use as temporary storage
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*
* Iterate backwards over list of given type, safe against removal
* of list entry.
*/
#define list_for_each_entry_safe_reverse(pos, n, head, member) \
for (pos = list_entry((head)->prev, typeof(*pos), member), \
n = list_entry(pos->member.prev, typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.prev, typeof(*n), member))
/*
* Double linked lists with a single pointer list head.
* Mostly useful for hash tables where the two pointer list head is
* too wasteful.
* You lose the ability to access the tail in O(1).
*/
struct hlist_head {
struct hlist_node *first;
};
struct hlist_node {
struct hlist_node *next, **pprev;
};
#define HLIST_HEAD_INIT { .first = NULL }
#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
#define init_hlist_head(ptr) ((ptr)->first = NULL)
static inline void init_hlist_node(struct hlist_node *h)
{
h->next = NULL;
h->pprev = NULL;
}
static inline int hlist_unhashed(const struct hlist_node *h)
{
return !h->pprev;
}
static inline int hlist_empty(const struct hlist_head *h)
{
return !h->first;
}
static inline void __hlist_del(struct hlist_node *n)
{
struct hlist_node *next = n->next;
struct hlist_node **pprev = n->pprev;
*pprev = next;
if (next)
next->pprev = pprev;
}
static inline void hlist_del(struct hlist_node *n)
{
__hlist_del(n);
n->next = LIST_POISON1;
n->pprev = LIST_POISON2;
}
static inline void hlist_del_init(struct hlist_node *n)
{
if (!hlist_unhashed(n)) {
__hlist_del(n);
init_hlist_node(n);
}
}
static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
{
struct hlist_node *first = h->first;
n->next = first;
if (first)
first->pprev = &n->next;
h->first = n;
n->pprev = &h->first;
}
/* next must be != NULL */
static inline void hlist_add_before(struct hlist_node *n,
struct hlist_node *next)
{
n->pprev = next->pprev;
n->next = next;
next->pprev = &n->next;
*(n->pprev) = n;
}
static inline void hlist_add_after(struct hlist_node *n,
struct hlist_node *next)
{
next->next = n->next;
n->next = next;
next->pprev = &n->next;
if(next->next)
next->next->pprev = &next->next;
}
#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
#define hlist_for_each(pos, head) \
for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
pos = pos->next)
#define hlist_for_each_safe(pos, n, head) \
for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
pos = n)
/**
* hlist_for_each_entry - iterate over list of given type
* @tpos: the type * to use as a loop cursor.
* @pos: the &struct hlist_node to use as a loop cursor.
* @head: the head for your list.
* @member: the name of the hlist_node within the struct.
*/
#define hlist_for_each_entry(tpos, pos, head, member) \
for (pos = (head)->first; \
pos && ({ prefetch(pos->next); 1;}) && \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
pos = pos->next)
/**
* hlist_for_each_entry_continue - iterate over a hlist continuing after current point
* @tpos: the type * to use as a loop cursor.
* @pos: the &struct hlist_node to use as a loop cursor.
* @member: the name of the hlist_node within the struct.
*/
#define hlist_for_each_entry_continue(tpos, pos, member) \
for (pos = (pos)->next; \
pos && ({ prefetch(pos->next); 1;}) && \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
pos = pos->next)
/**
* hlist_for_each_entry_from - iterate over a hlist continuing from current point
* @tpos: the type * to use as a loop cursor.
* @pos: the &struct hlist_node to use as a loop cursor.
* @member: the name of the hlist_node within the struct.
*/
#define hlist_for_each_entry_from(tpos, pos, member) \
for (; pos && ({ prefetch(pos->next); 1;}) && \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
pos = pos->next)
/**
* hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
* @tpos: the type * to use as a loop cursor.
* @pos: the &struct hlist_node to use as a loop cursor.
* @n: another &struct hlist_node to use as temporary storage
* @head: the head for your list.
* @member: the name of the hlist_node within the struct.
*/
#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
for (pos = (head)->first; \
pos && ({ n = pos->next; 1; }) && \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
pos = n)
#endif
nftlb-1.0.7/include/network.h 0000664 0000000 0000000 00000002622 14326712445 0016123 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#ifndef _NETWORK_H_
#define _NETWORK_H_
#define ETH_HW_ADDR_LEN 6
#define ETH_HW_STR_LEN 18
int net_get_neigh_ether(unsigned char **dst_ethaddr, unsigned char *src_ethaddr, unsigned char family, char *src_ipaddr, char *dst_ipaddr, int outdev);
int net_get_local_ifidx_per_remote_host(char *dst_ipaddr, int *outdev);
int net_get_local_ifinfo(unsigned char **ether, const char *indev);
int net_get_local_ifname_per_vip(char *strvip, char *outdev);
int net_eventd_init(void);
int net_eventd_stop(void);
int net_get_event_enabled(void);
int net_strim_netface(char *name);
#endif /* _NETWORK_H_ */
nftlb-1.0.7/include/nft.h 0000664 0000000 0000000 00000002337 14326712445 0015224 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#ifndef _NFT_H_
#define _NFT_H_
#include "farms.h"
#define NFTLB_MASQUERADE_MARK_DEFAULT 0x80000000
int nft_reset(void);
int nft_check_tables(void);
int nft_rulerize_farms(struct farm *f);
int nft_rulerize_address(struct address *a);
int nft_rulerize_policies(struct policy *p);
int nft_get_rules_buffer(const char **buf, int key, struct nftst *n);
void nft_del_rules_buffer(const char *buf);
#endif /* _NFT_H_ */
nftlb-1.0.7/include/nftables/ 0000775 0000000 0000000 00000000000 14326712445 0016055 5 ustar 00root root 0000000 0000000 nftlb-1.0.7/include/nftables/libnftables.h 0000664 0000000 0000000 00000004676 14326712445 0020530 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2017 Eric Leblond
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/
#ifndef LIB_NFTABLES_H
#define LIB_NFTABLES_H
#define _GNU_SOURCE
#include
#include
#include
#ifdef __cplusplus
extern "C" {
#endif
struct nft_ctx;
enum nft_debug_level {
NFT_DEBUG_SCANNER = 0x1,
NFT_DEBUG_PARSER = 0x2,
NFT_DEBUG_EVALUATION = 0x4,
NFT_DEBUG_NETLINK = 0x8,
NFT_DEBUG_MNL = 0x10,
NFT_DEBUG_PROTO_CTX = 0x20,
NFT_DEBUG_SEGTREE = 0x40,
};
/**
* Possible flags to pass to nft_ctx_new()
*/
#define NFT_CTX_DEFAULT 0
struct nft_ctx *nft_ctx_new(uint32_t flags);
void nft_ctx_free(struct nft_ctx *ctx);
bool nft_ctx_get_dry_run(struct nft_ctx *ctx);
void nft_ctx_set_dry_run(struct nft_ctx *ctx, bool dry);
enum {
NFT_CTX_OUTPUT_REVERSEDNS = (1 << 0),
NFT_CTX_OUTPUT_SERVICE = (1 << 1),
NFT_CTX_OUTPUT_STATELESS = (1 << 2),
NFT_CTX_OUTPUT_HANDLE = (1 << 3),
NFT_CTX_OUTPUT_JSON = (1 << 4),
NFT_CTX_OUTPUT_ECHO = (1 << 5),
NFT_CTX_OUTPUT_GUID = (1 << 6),
NFT_CTX_OUTPUT_NUMERIC_PROTO = (1 << 7),
NFT_CTX_OUTPUT_NUMERIC_PRIO = (1 << 8),
NFT_CTX_OUTPUT_NUMERIC_SYMBOL = (1 << 9),
NFT_CTX_OUTPUT_NUMERIC_ALL = (NFT_CTX_OUTPUT_NUMERIC_PROTO |
NFT_CTX_OUTPUT_NUMERIC_PRIO |
NFT_CTX_OUTPUT_NUMERIC_SYMBOL),
};
unsigned int nft_ctx_output_get_flags(struct nft_ctx *ctx);
void nft_ctx_output_set_flags(struct nft_ctx *ctx, unsigned int flags);
unsigned int nft_ctx_output_get_debug(struct nft_ctx *ctx);
void nft_ctx_output_set_debug(struct nft_ctx *ctx, unsigned int mask);
FILE *nft_ctx_set_output(struct nft_ctx *ctx, FILE *fp);
int nft_ctx_buffer_output(struct nft_ctx *ctx);
int nft_ctx_unbuffer_output(struct nft_ctx *ctx);
const char *nft_ctx_get_output_buffer(struct nft_ctx *ctx);
FILE *nft_ctx_set_error(struct nft_ctx *ctx, FILE *fp);
int nft_ctx_buffer_error(struct nft_ctx *ctx);
int nft_ctx_unbuffer_error(struct nft_ctx *ctx);
const char *nft_ctx_get_error_buffer(struct nft_ctx *ctx);
int nft_ctx_add_include_path(struct nft_ctx *ctx, const char *path);
void nft_ctx_clear_include_paths(struct nft_ctx *ctx);
int nft_run_cmd_from_buffer(struct nft_ctx *nft, const char *buf);
int nft_run_cmd_from_filename(struct nft_ctx *nft, const char *filename);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* LIB_NFTABLES_H */
nftlb-1.0.7/include/nftst.h 0000664 0000000 0000000 00000004366 14326712445 0015577 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#ifndef _NFTST_H_
#define _NFTST_H_
#include "farms.h"
#include "addresses.h"
#include "farmaddress.h"
#include "backends.h"
#include "policies.h"
struct nftst {
struct farm *farm;
struct address *address;
struct backend *backend;
struct policy *policy;
int action;
};
struct nftst *nftst_create_from_farm(struct farm *f);
struct nftst *nftst_create_from_farmaddress(struct farmaddress *fa);
struct nftst *nftst_create_from_address(struct address *a);
struct nftst *nftst_create_from_policy(struct policy *p);
void nftst_delete(struct nftst *n);
void nftst_set_farm(struct nftst *n, struct farm *f);
struct farm *nftst_get_farm(struct nftst *n);
void nftst_set_address(struct nftst *n, struct address *a);
struct address *nftst_get_address(struct nftst *n);
void nftst_set_backend(struct nftst *n, struct backend *b);
struct backend *nftst_get_backend(struct nftst *n);
void nftst_set_action(struct nftst *n, int action);
int nftst_get_action(struct nftst *n);
void nftst_set_policy(struct nftst *n, struct policy *p);
struct policy *nftst_get_policy(struct nftst *n);
char *nftst_get_name(struct nftst *n);
int nftst_get_family(struct nftst *n);
int nftst_get_proto(struct nftst *n);
int nftst_get_chains(struct nftst *n);
void nftst_set_chains(struct nftst *n, int chains);
int nftst_actions_done(struct nftst *n);
int nftst_has_farm(struct nftst *n);
int nftst_has_address(struct nftst *n);
int nftst_has_backend(struct nftst *n);
#endif /* _NFTST_H_ */
nftlb-1.0.7/include/objects.h 0000664 0000000 0000000 00000015664 14326712445 0016075 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#ifndef _OBJECTS_H_
#define _OBJECTS_H_
#define NFTLB_MAX_PORTS 65535
#define DEFAULT_NAME ""
#define DEFAULT_FQDN ""
#define DEFAULT_IFNAME NULL
#define DEFAULT_IFIDX -1
#define DEFAULT_ETHADDR NULL
#define DEFAULT_VIRTADDR ""
#define DEFAULT_VIRTPORTS ""
#define DEFAULT_IPADDR NULL
#define DEFAULT_SRCADDR NULL
#define DEFAULT_PORT ""
#define DEFAULT_FAMILY VALUE_FAMILY_IPV4
#define DEFAULT_MODE VALUE_MODE_SNAT
#define DEFAULT_RESPONSETTL 60
#define DEFAULT_PROTO VALUE_PROTO_TCP
#define DEFAULT_SCHED VALUE_SCHED_RR
#define DEFAULT_SCHEDPARAM VALUE_META_NONE
#define DEFAULT_PERSIST VALUE_META_NONE
#define DEFAULT_PERSISTTM 60
#define DEFAULT_HELPER VALUE_HELPER_NONE
#define DEFAULT_LOG VALUE_LOG_NONE
#define DEFAULT_LOG_LOGPREFIX "TYPE-FNAME "
#define DEFAULT_LOG_LOGPREFIX_ADDRESS "TYPE-ANAME "
#define DEFAULT_LOGPREFIX "KNAME-FNAME "
#define DEFAULT_LOG_RTLIMIT 0
#define DEFAULT_RTLIMIT_UNIT VALUE_UNIT_SECOND
#define DEFAULT_MARK 0x0
#define DEFAULT_WEIGHT 1
#define DEFAULT_PRIORITY 1
#define DEFAULT_FARM_STATE VALUE_STATE_UP
#define DEFAULT_BACKEND_STATE VALUE_STATE_CONFERR
#define DEFAULT_ACTION ACTION_START
#define DEFAULT_LIMITSTTL 120
#define DEFAULT_NEWRTLIMIT 0
#define DEFAULT_RTLIMITBURST 0
#define DEFAULT_RSTRTLIMIT 0
#define DEFAULT_ESTCONNLIMIT 0
#define DEFAULT_B_ESTCONNLIMIT_LOGPREFIX "KNAME-FNAME-BNAME "
#define DEFAULT_TCPSTRICT VALUE_SWITCH_OFF
#define DEFAULT_QUEUE -1
#define DEFAULT_FLOWOFFLOAD 0
#define DEFAULT_INTRACONNECT 0
#define DEFAULT_POLICY_TYPE VALUE_TYPE_DENY
#define DEFAULT_VERDICT VALUE_VERDICT_LOG | VALUE_VERDICT_DROP | VALUE_VERDICT_ACCEPT
#define DEFAULT_POLICY_TIMEOUT 0
#define DEFAULT_POLICY_LOGPREFIX "KNAME-TYPE-PNAME-FNAME "
#define DEFAULT_ELEMENT_TIME NULL
#define DEFAULT_SESSION_EXPIRATION NULL
#define DEFAULT_POLICY_ROUTE VALUE_ROUTE_IN
#define DEFAULT_COUNTER "0"
#define UNDEFINED_VALUE "UNDEFINED"
#define IFACE_LOOPBACK "lo"
enum obj_start {
OBJ_START,
OBJ_START_INV
};
enum levels {
LEVEL_INIT,
LEVEL_FARMS,
LEVEL_BCKS,
LEVEL_FARMPOLICY,
LEVEL_POLICIES,
LEVEL_ELEMENTS,
LEVEL_SESSIONS,
LEVEL_ADDRESSES,
LEVEL_FARMADDRESS,
LEVEL_ADDRESSPOLICY,
};
enum actions {
ACTION_START,
ACTION_STOP,
ACTION_FLUSH,
ACTION_RELOAD,
ACTION_DELETE,
ACTION_NONE,
};
enum keys {
KEY_FARMS,
KEY_NAME,
KEY_NEWNAME,
KEY_FQDN,
KEY_IFACE,
KEY_OFACE,
KEY_FAMILY,
KEY_ETHADDR,
KEY_IETHADDR,
KEY_OETHADDR,
KEY_VIRTADDR,
KEY_VIRTPORTS,
KEY_IPADDR,
KEY_SRCADDR,
KEY_PORT,
KEY_PORTS,
KEY_MODE,
KEY_PROTO,
KEY_SCHED,
KEY_SCHEDPARAM,
KEY_PERSISTENCE,
KEY_PERSISTTM,
KEY_HELPER,
KEY_LOG,
KEY_MARK,
KEY_STATE,
KEY_BCKS,
KEY_WEIGHT,
KEY_PRIORITY,
KEY_ACTION,
KEY_LIMITSTTL,
KEY_NEWRTLIMIT,
KEY_NEWRTLIMITBURST,
KEY_RSTRTLIMIT,
KEY_RSTRTLIMITBURST,
KEY_ESTCONNLIMIT,
KEY_TCPSTRICT,
KEY_QUEUE,
KEY_POLICIES,
KEY_ELEMENTS,
KEY_TYPE,
KEY_TIMEOUT,
KEY_DATA,
KEY_TIME,
KEY_LOGPREFIX,
KEY_NEWRTLIMIT_LOGPREFIX,
KEY_RSTRTLIMIT_LOGPREFIX,
KEY_ESTCONNLIMIT_LOGPREFIX,
KEY_TCPSTRICT_LOGPREFIX,
KEY_RESPONSETTL,
KEY_FLOWOFFLOAD,
KEY_SESSIONS,
KEY_CLIENT,
KEY_BACKEND,
KEY_USED,
KEY_INTRACONNECT,
KEY_ADDRESSES,
KEY_ROUTE,
KEY_VERDICT,
KEY_LOG_RTLIMIT,
KEY_COUNTER_PACKETS,
KEY_COUNTER_BYTES,
};
enum families {
VALUE_FAMILY_IPV4,
VALUE_FAMILY_IPV6,
VALUE_FAMILY_INET,
VALUE_FAMILY_NETDEV,
};
enum units {
VALUE_UNIT_SECOND,
VALUE_UNIT_MINUTE,
VALUE_UNIT_HOUR,
VALUE_UNIT_DAY,
VALUE_UNIT_WEEK,
};
#define VALUE_VERDICT_NONE 0
#define VALUE_VERDICT_LOG (1 << 0)
#define VALUE_VERDICT_DROP (1 << 1)
#define VALUE_VERDICT_ACCEPT (1 << 2)
struct obj_config {
struct farm *fptr;
struct backend *bptr;
struct policy *pptr;
struct element *eptr;
struct farmpolicy *fpptr;
struct session *sptr;
struct address *aptr;
struct farmaddress *faptr;
struct addresspolicy *apptr;
struct config_pair *c;
};
void objects_init(void);
struct list_head * obj_get_farms(void);
int obj_get_total_farms(void);
void obj_set_total_farms(int new_value);
int obj_get_dsr_counter(void);
void obj_set_dsr_counter(int new_value);
struct obj_config * obj_get_current_object(void);
struct farm * obj_get_current_farm(void);
struct backend * obj_get_current_backend(void);
struct policy * obj_get_current_policy(void);
struct farmpolicy * obj_get_current_farmpolicy(void);
struct element * obj_get_current_element(void);
struct session * obj_get_current_session(void);
struct address * obj_get_current_address(void);
struct farmaddress * obj_get_current_farmaddress(void);
struct addresspolicy * obj_get_current_addresspolicy(void);
void obj_set_current_farm(struct farm *f);
void obj_set_current_backend(struct backend *b);
void obj_set_current_policy(struct policy *p);
void obj_set_current_farmpolicy(struct farmpolicy *fp);
void obj_set_current_element(struct element *e);
void obj_set_current_session(struct session *s);
void obj_set_current_address(struct address *a);
void obj_set_current_farmaddress(struct farmaddress *fa);
void obj_set_current_addresspolicy(struct addresspolicy *ap);
char * obj_print_key(int key);
char * obj_print_family(int family);
char * obj_print_mode(int mode);
char * obj_print_proto(int protocol);
int obj_print_rtlimit(char *buf, int value, int unit);
char * obj_print_sched(int scheduler);
void obj_print_meta(int param, char* buf);
char * obj_print_helper(int helper);
void obj_print_log(int log, char *buf);
char * obj_print_state(int state);
char * obj_print_switch(int value);
int obj_set_attribute(struct config_pair *c, int actionable, int apply_action);
int obj_set_attribute_string(char *src, char **dst);
int obj_equ_attribute_string(char *stra, char *strb);
void obj_set_attribute_int(int *src, int value);
int obj_equ_attribute_int(int valuea, int valueb);
void obj_print(void);
int obj_rulerize(int mode);
struct list_head * obj_get_policies(void);
int obj_get_total_policies(void);
void obj_set_total_policies(int new_value);
char * obj_print_policy_type(int type);
char * obj_print_policy_route(int route);
void obj_print_verdict(int verdict, char* buf);
int obj_get_total_addresses(void);
struct list_head * obj_get_addresses(void);
void obj_set_total_addresses(int new_value);
int obj_recovery(void);
#endif /* _OBJECTS_H_ */
nftlb-1.0.7/include/policies.h 0000664 0000000 0000000 00000003321 14326712445 0016236 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#ifndef _POLICIES_H_
#define _POLICIES_H_
#include "list.h"
#include "config.h"
enum type {
VALUE_TYPE_DENY,
VALUE_TYPE_ALLOW,
};
enum route {
VALUE_ROUTE_IN,
VALUE_ROUTE_OUT,
};
struct policy {
struct list_head list;
char *name;
int type;
int route;
int family;
int timeout;
int total_elem;
int used;
char *logprefix;
int action;
struct list_head elements;
};
void policy_print(struct policy *p);
void policies_s_print(void);
struct policy * policy_lookup_by_name(const char *name);
int policy_changed(struct config_pair *c);
int policy_set_attribute(struct config_pair *c);
int policy_set_action(struct policy *p, int action);
int policy_s_set_action(int action);
int policy_pre_actionable(struct config_pair *c);
int policy_pos_actionable(struct config_pair *c);
int policy_rulerize(struct policy *p);
int policy_s_rulerize(void);
#endif /* _POLICIES_H_ */
nftlb-1.0.7/include/sbuffer.h 0000664 0000000 0000000 00000002711 14326712445 0016065 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#ifndef _SBUFFER_H_
#define _SBUFFER_H_
#include
#define DEFAULT_BUFFER_SIZE 4096
#define EXTRA_SIZE 1024
struct sbuffer {
int size;
int next;
char *data;
};
int get_buf_size(struct sbuffer *buf);
char * get_buf_next(struct sbuffer *buf);
char * get_buf_data(struct sbuffer *buf);
int resize_buf(struct sbuffer *buf, int times);
int create_buf(struct sbuffer *buf);
int clean_buf(struct sbuffer *buf);
int reset_buf(struct sbuffer *buf);
int isempty_buf(struct sbuffer *buf);
int concat_buf_va(struct sbuffer *buf, int len, char *fmt, va_list args);
int concat_buf(struct sbuffer *buf, char *fmt, ...);
#endif /* _SBUFFER_H_ */
nftlb-1.0.7/include/server.h 0000664 0000000 0000000 00000002067 14326712445 0015743 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#ifndef _SERVER_H_
#define _SERVER_H_
int server_init(void);
void server_fini(void);
void server_set_host(const char *host);
void server_set_port(const char *port);
void server_set_key(char *key);
void server_set_ipv6(void);
#endif /* _SERVER_H_ */
nftlb-1.0.7/include/sessions.h 0000664 0000000 0000000 00000003421 14326712445 0016276 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#ifndef _SESSIONS_H_
#define _SESSIONS_H_
#include "farms.h"
#include "backends.h"
enum session_type {
SESSION_TYPE_STATIC,
SESSION_TYPE_TIMED,
};
struct session {
struct list_head list;
struct farm *f;
char *client;
struct backend *bck;
char *expiration;
int state;
int action;
};
int session_set_action(struct session *s, int type, int action);
struct session * session_lookup_by_key(struct farm *f, int type, int key, const char *name);
int session_s_set_action(struct farm *f, struct backend *b, int action);
void session_s_print(struct farm *f);
int session_get_timed(struct farm *f);
int session_get_client(struct session *s, char **parsed);
int session_backend_action(struct farm *f, struct backend *b, int action);
int session_s_delete(struct farm *f, int type);
int session_set_attribute(struct config_pair *c);
int session_pre_actionable(struct config_pair *c);
int session_pos_actionable(struct config_pair *c);
#endif /* _SESSIONS_H_ */
nftlb-1.0.7/include/tools.h 0000664 0000000 0000000 00000002754 14326712445 0015600 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#ifndef _TOOLS_H_
#define _TOOLS_H_
#include
#define NFTLB_LOG_LEVEL_DEFAULT LOG_NOTICE
#define NFTLB_LOG_OUTPUT_DEFAULT VALUE_LOG_OUTPUT_SYSLOG
#define NFTLB_LOG_OUTPUT_SYSLOG (1 << 0)
#define NFTLB_LOG_OUTPUT_STDOUT (1 << 1)
#define NFTLB_LOG_OUTPUT_STDERR (1 << 2)
enum log_output {
VALUE_LOG_OUTPUT_SYSLOG,
VALUE_LOG_OUTPUT_STDOUT,
VALUE_LOG_OUTPUT_STDERR,
VALUE_LOG_OUTPUT_SYSOUT,
VALUE_LOG_OUTPUT_SYSERR,
};
void tools_snprintf(char *strdst, int size, char *strsrc);
void tools_log_set_level(int loglevel);
void tools_log_set_output(int output);
int tools_printlog(int loglevel, char *fmt, ...);
int tools_log_get_level(void);
#endif /* _TOOLS_H_ */
nftlb-1.0.7/m4/ 0000775 0000000 0000000 00000000000 14326712445 0013154 5 ustar 00root root 0000000 0000000 nftlb-1.0.7/m4/.gitignore 0000664 0000000 0000000 00000000024 14326712445 0015140 0 ustar 00root root 0000000 0000000 /lt*.m4
/libtool.m4
nftlb-1.0.7/src/ 0000775 0000000 0000000 00000000000 14326712445 0013423 5 ustar 00root root 0000000 0000000 nftlb-1.0.7/src/.gitignore 0000664 0000000 0000000 00000000021 14326712445 0015404 0 ustar 00root root 0000000 0000000 *.o
nftlb
.deps/
nftlb-1.0.7/src/Makefile.am 0000664 0000000 0000000 00000000657 14326712445 0015467 0 ustar 00root root 0000000 0000000 include $(top_srcdir)/Make_global.am
sbin_PROGRAMS = nftlb
nftlb_SOURCES = config.c \
main.c \
sbuffer.c \
objects.c \
farms.c \
backends.c \
nft.c \
events.c \
network.c \
server.c \
policies.c \
elements.c \
farmpolicy.c \
sessions.c \
checksum.c \
tools.c \
addresses.c \
farmaddress.c \
addresspolicy.c \
nftst.c
nftlb_LDADD = ${LIBNFTABLES_LIBS} ${LIBJSON_LIBS} ${LIBMNL_LIBS} -lev
nftlb-1.0.7/src/addresses.c 0000664 0000000 0000000 00000035147 14326712445 0015556 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#include
#include
#include
#include
#include "addresses.h"
#include "farms.h"
#include "backends.h"
#include "policies.h"
#include "addresspolicy.h"
#include "objects.h"
#include "network.h"
#include "config.h"
#include "nft.h"
#include "tools.h"
struct address * address_create(char *name)
{
struct list_head *addresses = obj_get_addresses();
struct address *paddress = (struct address *)malloc(sizeof(struct address));
if (!paddress) {
tools_printlog(LOG_ERR, "Address memory allocation error");
return NULL;
}
obj_set_attribute_string(name, &paddress->name);
paddress->fqdn = DEFAULT_FQDN;
paddress->iface = DEFAULT_IFNAME;
paddress->iethaddr = DEFAULT_ETHADDR;
paddress->ifidx = DEFAULT_IFIDX;
paddress->ipaddr = DEFAULT_VIRTADDR;
paddress->ports = DEFAULT_VIRTPORTS;
paddress->family = DEFAULT_FAMILY;
paddress->protocol = DEFAULT_PROTO;
paddress->action = DEFAULT_ACTION;
paddress->verdict = DEFAULT_VERDICT;
paddress->logprefix = DEFAULT_LOG_LOGPREFIX_ADDRESS;
paddress->logrtlimit = DEFAULT_LOG_RTLIMIT;
paddress->logrtlimit_unit = DEFAULT_RTLIMIT_UNIT;
paddress->policies_action = ACTION_NONE;
init_list_head(&paddress->policies);
paddress->policies_used = 0;
paddress->used = 0;
paddress->nft_chains = 0;
paddress->nports = 0;
list_add_tail(&paddress->list, addresses);
obj_set_total_addresses(obj_get_total_addresses() + 1);
return paddress;
}
int address_delete(struct address *paddress)
{
if (!paddress)
return 0;
tools_printlog(LOG_DEBUG, "%s():%d: deleting address %s",
__FUNCTION__, __LINE__, paddress->name);
list_del(&paddress->list);
if (paddress->name && strcmp(paddress->name, "") != 0)
free(paddress->name);
if (paddress->fqdn && strcmp(paddress->fqdn, "") != 0)
free(paddress->fqdn);
if (paddress->iface && strcmp(paddress->iface, "") != 0)
free(paddress->iface);
if (paddress->iethaddr && strcmp(paddress->iethaddr, "") != 0)
free(paddress->iethaddr);
if (paddress->ipaddr && strcmp(paddress->ipaddr, "") != 0)
free(paddress->ipaddr);
if (paddress->ports && strcmp(paddress->ports, "") != 0)
free(paddress->ports);
if (paddress->logprefix && strcmp(paddress->logprefix, DEFAULT_LOG_LOGPREFIX_ADDRESS) != 0)
free(paddress->logprefix);
free(paddress);
obj_set_total_addresses(obj_get_total_addresses() - 1);
return 0;
}
static void address_get_range_ports(const char *ptr, int *first, int *last)
{
sscanf(ptr, "%d-%d[^,]", first, last);
}
int address_search_array_port(struct address *a, int port)
{
if (a->port_list[port-1])
return 1;
return 0;
}
static void address_add_array_port(struct address *a, int port)
{
if (!a->port_list[port-1]) {
a->nports++;
a->port_list[port-1] = 1;
}
}
static int address_get_array_ports(struct address *a)
{
int index = 0;
char *ptr;
int iport, new;
int last = 0;
a->nports = 0;
memset(a->port_list, 0, NFTLB_MAX_PORTS * sizeof(int));
ptr = a->ports;
while (ptr != NULL && *ptr != '\0') {
last = new = 0;
address_get_range_ports(ptr, &new, &last);
if (last == 0)
last = new;
if (new > last)
goto next;
for (iport = new; iport <= last; iport++)
address_add_array_port(a, iport);
next:
ptr = strchr(ptr, ',');
if (ptr != NULL)
ptr++;
}
return index;
}
int address_set_ports(struct address *a, char *new_value)
{
if (strcmp(new_value, "0") != 0) {
if (strcmp(a->ports, DEFAULT_VIRTPORTS) != 0)
free(a->ports);
obj_set_attribute_string(new_value, &a->ports);
}
if (strcmp(new_value, "") == 0)
a->protocol = VALUE_PROTO_ALL;
address_get_array_ports(a);
return 0;
}
void address_print(struct address *a)
{
char buf[100] = {};
tools_printlog(LOG_DEBUG," [address] ");
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_NAME, a->name);
if (a->fqdn)
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_FQDN, a->fqdn);
if (a->iface)
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_IFACE, a->iface);
if (a->iethaddr)
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_IETHADDR, a->iethaddr);
tools_printlog(LOG_DEBUG," *[ifidx] %d", a->ifidx);
if (a->ipaddr)
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_IPADDR, a->ipaddr);
if (a->ports)
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_PORTS, a->ports);
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_FAMILY, obj_print_family(a->family));
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_PROTO, obj_print_proto(a->protocol));
obj_print_verdict(a->verdict, (char *)buf);
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_VERDICT, buf);
if (a->logprefix)
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_LOGPREFIX, a->logprefix);
obj_print_rtlimit(buf, a->logrtlimit, a->logrtlimit_unit);
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_LOG_RTLIMIT, buf);
tools_printlog(LOG_DEBUG," *[used] %d", a->used);
tools_printlog(LOG_DEBUG," *[%s] %d", CONFIG_KEY_ACTION, a->action);
tools_printlog(LOG_DEBUG," *[policies_action] %d", a->policies_action);
tools_printlog(LOG_DEBUG," *[nft_chains] %x", a->nft_chains);
if (a->policies_used > 0)
addresspolicy_s_print(a);
}
static int address_set_iface_info(struct address *a)
{
unsigned char ether[ETH_HW_ADDR_LEN];
char streth[ETH_HW_STR_LEN] = {};
char if_str[IFNAMSIZ];
int if_index;
int ret = 0;
tools_printlog(LOG_DEBUG, "%s():%d: address %s set interface info for interface", __FUNCTION__, __LINE__, a->name);
if (a->iface && strcmp(a->iface, IFACE_LOOPBACK) == 0) {
tools_printlog(LOG_DEBUG, "%s():%d: address %s doesn't require input netinfo, loopback interface", __FUNCTION__, __LINE__, a->name);
a->ifidx = 0;
return 0;
}
ret = net_get_local_ifname_per_vip(a->ipaddr, if_str);
if (ret != 0) {
tools_printlog(LOG_ERR, "%s():%d: inbound interface not found with IP %s by address %s", __FUNCTION__, __LINE__, a->ipaddr, a->name);
return -1;
}
if (a->iface)
free(a->iface);
obj_set_attribute_string(if_str, &a->iface);
net_strim_netface(a->iface);
if_index = if_nametoindex(a->iface);
if (if_index == 0) {
tools_printlog(LOG_ERR, "%s():%d: index of the inbound interface %s in address %s not found", __FUNCTION__, __LINE__, a->iface, a->name);
return -1;
}
a->ifidx = if_index;
net_get_local_ifinfo((unsigned char **)ðer, a->iface);
net_strim_netface(a->iface);
sprintf(streth, "%02x:%02x:%02x:%02x:%02x:%02x", ether[0],
ether[1], ether[2], ether[3], ether[4], ether[5]);
if (a->iethaddr)
free(a->iethaddr);
obj_set_attribute_string(streth, &a->iethaddr);
return 0;
}
int address_set_protocol(struct address *a, int new_value)
{
int old_value = a->protocol;
syslog(LOG_DEBUG, "%s():%d: address %s old protocol %d new protocol %d", __FUNCTION__, __LINE__, a->name, old_value, new_value);
a->protocol = new_value;
return PARSER_OK;
}
static int address_set_verdict(struct address *a, int new_value)
{
int old_value = a->verdict;
tools_printlog(LOG_DEBUG, "%s():%d: address %s old verdict %d new verdict %d", __FUNCTION__, __LINE__, a->name, old_value, new_value);
if (new_value == VALUE_VERDICT_NONE)
return 1;
a->verdict = new_value;
return 0;
}
int address_set_netinfo(struct address *a)
{
tools_printlog(LOG_DEBUG, "%s():%d: address %s", __FUNCTION__, __LINE__, a->name);
address_set_iface_info(a);
farm_s_set_oface_info(a);
return 0;
}
int address_changed(struct config_pair *c)
{
struct address *a = obj_get_current_address();
if (!a)
return -1;
tools_printlog(LOG_DEBUG, "%s():%d: address %s with param %d", __FUNCTION__, __LINE__, a->name, c->key);
switch (c->key) {
case KEY_NAME:
return 1;
break;
case KEY_FQDN:
return !obj_equ_attribute_string(a->fqdn, c->str_value);
break;
case KEY_IFACE:
return !obj_equ_attribute_string(a->iface, c->str_value);
break;
case KEY_IETHADDR:
return !obj_equ_attribute_string(a->iethaddr, c->str_value);
break;
case KEY_FAMILY:
return !obj_equ_attribute_int(a->family, c->int_value);
break;
case KEY_IPADDR:
return !obj_equ_attribute_string(a->ipaddr, c->str_value);
break;
case KEY_PORTS:
return !obj_equ_attribute_string(a->ports, c->str_value);
break;
case KEY_PROTO:
return !obj_equ_attribute_int(a->protocol, c->int_value);
break;
case KEY_VERDICT:
return !obj_equ_attribute_int(a->verdict, c->int_value);
break;
case KEY_LOGPREFIX:
return !obj_equ_attribute_string(a->logprefix, c->str_value);
break;
case KEY_ACTION:
return !obj_equ_attribute_int(a->action, c->int_value);
break;
default:
break;
}
return 0;
}
void address_s_print(void)
{
struct list_head *addresses = obj_get_addresses();
struct address *a;
list_for_each_entry(a, addresses, list)
address_print(a);
}
struct address * address_lookup_by_name(const char *name)
{
struct list_head *addresses = obj_get_addresses();
struct address *a;
list_for_each_entry(a, addresses, list) {
if (strcmp(a->name, name) == 0)
return a;
}
return NULL;
}
int address_pre_actionable(struct config_pair *c)
{
struct address *a = obj_get_current_address();
if (!a)
return -1;
return ACTION_START;
}
int address_pos_actionable(struct config_pair *c)
{
struct address *a = obj_get_current_address();
if (!a)
return -1;
return 0;
}
int address_set_attribute(struct config_pair *c)
{
struct address *a = obj_get_current_address();
int ret = PARSER_FAILED;
if (c->key != KEY_NAME && !a) {
tools_printlog(LOG_INFO, "%s():%d: address UNKNOWN", __FUNCTION__, __LINE__);
return PARSER_OBJ_UNKNOWN;
}
switch (c->key) {
case KEY_NAME:
a = address_lookup_by_name(c->str_value);
if (!a) {
a = address_create(c->str_value);
if (!a)
return PARSER_FAILED;
}
obj_set_current_address(a);
ret = PARSER_OK;
break;
case KEY_FQDN:
if (strcmp(a->fqdn, DEFAULT_FQDN) != 0)
free(a->fqdn);
ret = obj_set_attribute_string(c->str_value, &a->fqdn);
break;
case KEY_IFACE:
if (a->iface)
free(a->iface);
ret = obj_set_attribute_string(c->str_value, &a->iface);
net_strim_netface(a->iface);
break;
case KEY_FAMILY:
a->family = c->int_value;
ret = PARSER_OK;
break;
case KEY_ETHADDR:
if (a->iethaddr)
free(a->iethaddr);
ret = obj_set_attribute_string(c->str_value, &a->iethaddr);
break;
case KEY_IETHADDR:
if (a->iethaddr)
free(a->iethaddr);
ret = obj_set_attribute_string(c->str_value, &a->iethaddr);
address_set_netinfo(a);
break;
case KEY_IPADDR:
if (strcmp(a->ipaddr, DEFAULT_VIRTADDR) != 0)
free(a->ipaddr);
ret = obj_set_attribute_string(c->str_value, &a->ipaddr);
address_set_netinfo(a);
break;
case KEY_PORTS:
ret = address_set_ports(a, c->str_value);
break;
case KEY_PROTO:
ret = address_set_protocol(a, c->int_value);
break;
case KEY_VERDICT:
if (!address_set_verdict(a, c->int_value))
return PARSER_OK;
break;
case KEY_LOGPREFIX:
if (strcmp(a->logprefix, DEFAULT_LOG_LOGPREFIX) != 0)
free(a->logprefix);
ret = obj_set_attribute_string(c->str_value, &a->logprefix);
break;
case KEY_ACTION:
ret = address_set_action(a, c->int_value);
break;
case KEY_USED:
ret = PARSER_OK;
break;
default:
return PARSER_STRUCT_FAILED;
}
return ret;
}
int address_not_used(struct address *a)
{
return (!a->policies_used && !a->used);
}
int address_set_action(struct address *a, int action)
{
tools_printlog(LOG_DEBUG, "%s():%d: address %s action is %d - new action %d", __FUNCTION__, __LINE__, a->name, a->action, action);
if (a->action == action)
return 0;
if (action == ACTION_DELETE) {
if (!farm_s_lookup_address_action(a->name, action))
address_delete(a);
return 1;
}
if (action == ACTION_STOP)
farm_s_lookup_address_action(a->name, action);
if (a->action > action)
a->action = action;
return 1;
}
int address_s_set_action(int action)
{
struct list_head *addresses = obj_get_addresses();
struct address *a, *next;
list_for_each_entry_safe(a, next, addresses, list)
address_set_action(a, action);
return 0;
}
int address_no_port(struct address *a)
{
if (obj_equ_attribute_string(a->ports, DEFAULT_VIRTPORTS))
return 1;
return 0;
}
int address_no_ipaddr(struct address *a)
{
if (obj_equ_attribute_string(a->ipaddr, DEFAULT_VIRTADDR))
return 1;
return 0;
}
int address_rulerize(struct address *a)
{
tools_printlog(LOG_DEBUG, "%s():%d: rulerize address %s", __FUNCTION__, __LINE__, a->name);
address_print(a);
if (a->used) {
tools_printlog(LOG_INFO, "%s():%d: address %s won't be rulerized", __FUNCTION__, __LINE__, a->name);
return 0;
}
return nft_rulerize_address(a);
}
int address_s_rulerize(void)
{
struct list_head *addresses = obj_get_addresses();
struct address *a, *next;
int ret = 0;
int output = 0;
tools_printlog(LOG_DEBUG, "%s():%d: rulerize addresses", __FUNCTION__, __LINE__);
list_for_each_entry_safe(a, next, addresses, list) {
ret = address_rulerize(a);
output = output || ret;
}
return output;
}
int address_needs_policies(struct address *a)
{
return (a->policies_used > 0) || (a->policies_action != ACTION_NONE);
}
int address_s_lookup_policy_action(char *name, int action)
{
struct list_head *addresses = obj_get_addresses();
struct address *a, *next;
tools_printlog(LOG_DEBUG, "%s():%d: name %s action %d", __FUNCTION__, __LINE__, name, action);
list_for_each_entry_safe(a, next, addresses, list)
addresspolicy_s_lookup_policy_action(a, name, action);
return 0;
}
int address_validate_iface(struct address *a)
{
tools_printlog(LOG_DEBUG, "%s():%d: validating inbound address interface of %s", __FUNCTION__, __LINE__, a->name);
if (!a || !a->iface || obj_equ_attribute_string(a->iface, ""))
return 1;
return 0;
}
int address_validate_iether(struct address *a)
{
tools_printlog(LOG_DEBUG, "%s():%d: validating inbound address ether of %s", __FUNCTION__, __LINE__, a->name);
if (!a || !a->iethaddr || obj_equ_attribute_string(a->iethaddr, ""))
return 1;
return 0;
}
int address_s_clean_nft_chains(void)
{
struct list_head *addresses = obj_get_addresses();
struct address *a, *next;
if (!addresses)
return 0;
list_for_each_entry_safe(a, next, addresses, list)
a->nft_chains = 0;
return 0;
}
nftlb-1.0.7/src/addresspolicy.c 0000664 0000000 0000000 00000011471 14326712445 0016440 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#include
#include
#include
#include "addresspolicy.h"
#include "objects.h"
#include "network.h"
#include "tools.h"
static struct addresspolicy * addresspolicy_create(struct address *a, struct policy *p)
{
struct addresspolicy *ap = (struct addresspolicy *)malloc(sizeof(struct addresspolicy));
if (!ap) {
tools_printlog(LOG_ERR, "address policy memory allocation error");
return NULL;
}
tools_printlog(LOG_DEBUG, "%s():%d: address %s", __FUNCTION__, __LINE__, a->name);
ap->address = a;
ap->policy = p;
ap->action = DEFAULT_ACTION;
p->used++;
a->policies_action = DEFAULT_ACTION;
if (a->policies_used > 0 && a->action == ACTION_RELOAD)
a->policies_action = ACTION_RELOAD;
a->policies_used++;
list_add_tail(&ap->list, &a->policies);
return ap;
}
static int addresspolicy_delete(struct addresspolicy *ap)
{
if (!ap)
return 0;
list_del(&ap->list);
if (ap->address->policies_used > 0)
ap->address->policies_used--;
if (ap->policy->used > 0)
ap->policy->used--;
ap->address->policies_action = ACTION_STOP;
free(ap);
return 0;
}
void addresspolicy_s_print(struct address *a)
{
struct addresspolicy *ap;
list_for_each_entry(ap, &a->policies, list) {
tools_printlog(LOG_DEBUG," [policy] ");
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_NAME, ap->policy->name);
tools_printlog(LOG_DEBUG," *[%s] %d", CONFIG_KEY_ACTION, ap->action);
}
}
struct addresspolicy * addresspolicy_lookup_by_name(struct address *a, const char *name)
{
struct addresspolicy *ap;
list_for_each_entry(ap, &a->policies, list) {
if (strcmp(ap->policy->name, name) == 0)
return ap;
}
return NULL;
}
int addresspolicy_set_action(struct addresspolicy *ap, int action)
{
if ((action == ACTION_DELETE) || (action == ACTION_STOP)) {
addresspolicy_delete(ap);
return 1;
}
if (ap->action > action) {
ap->action = action;
ap->address->policies_action = ACTION_RELOAD;
return 1;
}
return 0;
}
int addresspolicy_s_set_action(struct address *a, int action)
{
struct addresspolicy *ap, *next;
list_for_each_entry_safe(ap, next, &a->policies, list)
addresspolicy_set_action(ap, action);
return 0;
}
int addresspolicy_s_delete(struct address *a)
{
struct addresspolicy *ap, *next;
list_for_each_entry_safe(ap, next, &a->policies, list)
addresspolicy_delete(ap);
return 0;
}
int addresspolicy_s_lookup_policy_action(struct address *a, char *name, int action)
{
struct addresspolicy *ap;
int ret = 0;
tools_printlog(LOG_DEBUG, "%s():%d: address %s action is %d - new action %d", __FUNCTION__, __LINE__, a->name, a->action, action);
ap = addresspolicy_lookup_by_name(a, name);
if (ap)
ret = addresspolicy_set_action(ap, action);
if (ret)
address_set_action(a, ACTION_RELOAD);
return 0;
}
int addresspolicy_set_attribute(struct config_pair *c)
{
struct addresspolicy *ap = obj_get_current_addresspolicy();
struct address *a = obj_get_current_address();
struct policy *p;
if (!a)
return PARSER_OBJ_UNKNOWN;
switch (c->key) {
case KEY_NAME:
p = policy_lookup_by_name(c->str_value);
if (!p)
return -1;
ap = addresspolicy_lookup_by_name(a, c->str_value);
if (ap)
return 0;
ap = addresspolicy_create(a, p);
obj_set_current_addresspolicy(ap);
break;
default:
return PARSER_STRUCT_FAILED;
}
return PARSER_OK;
}
int addresspolicy_pre_actionable(struct config_pair *c)
{
struct address *a = obj_get_current_address();
if (!a)
return -1;
tools_printlog(LOG_DEBUG, "%s():%d: pre actionable address policy for address %s", __FUNCTION__, __LINE__, a->name);
address_set_action(a, ACTION_RELOAD);
address_rulerize(a);
return 0;
}
int addresspolicy_pos_actionable(struct config_pair *c)
{
struct addresspolicy *ap = obj_get_current_addresspolicy();
struct address *a = obj_get_current_address();
if (!ap || !a)
return -1;
tools_printlog(LOG_DEBUG, "%s():%d: pos actionable address policy %s for address %s with param %d", __FUNCTION__, __LINE__, ap->policy->name, a->name, c->key);
address_set_action(a, ACTION_RELOAD);
return 0;
}
nftlb-1.0.7/src/backends.c 0000664 0000000 0000000 00000063071 14326712445 0015350 0 ustar 00root root 0000000 0000000 /*
* This file is part of nftlb, nftables load balancer.
*
* Copyright (C) ZEVENET SL.
* Author: Laura Garcia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
*/
#include
#include
#include
#include
#include "backends.h"
#include "farms.h"
#include "farmaddress.h"
#include "objects.h"
#include "network.h"
#include "sessions.h"
#include "tools.h"
#define BACKEND_MARK_MIN 0x00000001
#define BACKEND_MARK_MAX 0x00000FFF
static int backend_gen_next_mark(void)
{
struct list_head *farms = obj_get_farms();
struct farm *f;
struct backend *b;
int mark = BACKEND_MARK_MIN;
int found = 0;
for (mark = BACKEND_MARK_MIN; mark <= BACKEND_MARK_MAX; mark++) {
found = 0;
list_for_each_entry(f, farms, list) {
list_for_each_entry(b, &f->backends, list) {
if (mark == b->mark) {
found = 1;
continue;
}
}
if (found)
continue;
}
if (!found)
return mark;
}
return DEFAULT_MARK;
}
static struct backend * backend_create(struct farm *f, char *name)
{
struct backend *b = (struct backend *)malloc(sizeof(struct backend));
if (!b) {
tools_printlog(LOG_ERR, "Backend memory allocation error");
return NULL;
}
b->parent = f;
obj_set_attribute_string(name, &b->name);
b->fqdn = DEFAULT_FQDN;
b->ethaddr = DEFAULT_ETHADDR;
b->oface = DEFAULT_IFNAME;
b->ofidx = DEFAULT_IFIDX;
b->ipaddr = DEFAULT_IPADDR;
b->port = DEFAULT_PORT;
b->srcaddr = DEFAULT_SRCADDR;
b->weight = DEFAULT_WEIGHT;
b->priority = DEFAULT_PRIORITY;
b->mark = backend_gen_next_mark();
b->estconnlimit = DEFAULT_ESTCONNLIMIT;
b->estconnlimit_logprefix = DEFAULT_B_ESTCONNLIMIT_LOGPREFIX;
b->state = DEFAULT_BACKEND_STATE;
b->action = DEFAULT_ACTION;
b->parent->bcks_have_port = 0;
list_add_tail(&b->list, &f->backends);
f->total_bcks++;
return b;
}
static int backend_delete_node(struct backend *b)
{
list_del(&b->list);
if (b->name)
free(b->name);
if (b->fqdn && strcmp(b->fqdn, "") != 0)
free(b->fqdn);
if (b->oface && strcmp(b->oface, "") != 0)
free(b->oface);
if (b->ipaddr && strcmp(b->ipaddr, "") != 0)
free(b->ipaddr);
if (b->ethaddr && strcmp(b->ethaddr, "") != 0)
free(b->ethaddr);
if (b->port && strcmp(b->port, "") != 0)
free(b->port);
if (b->srcaddr && strcmp(b->srcaddr, "") != 0)
free(b->srcaddr);
if (b->estconnlimit_logprefix && strcmp(b->estconnlimit_logprefix, DEFAULT_B_ESTCONNLIMIT_LOGPREFIX) != 0)
free(b->estconnlimit_logprefix);
free(b);
return 0;
}
static int backend_below_prio(struct backend *b)
{
struct farm *f = b->parent;
tools_printlog(LOG_DEBUG, "%s():%d: backend %s state is %s and priority %d <= farm prio %d",
__FUNCTION__, __LINE__, b->name, obj_print_state(b->state), b->priority, f->priority);
return (b->priority <= f->priority);
}
static int backend_s_set_ports(struct farm *f)
{
struct backend *b;
tools_printlog(LOG_DEBUG, "%s():%d: finding backends with port for %s", __FUNCTION__, __LINE__, f->name);
list_for_each_entry(b, &f->backends, list) {
if (strcmp(b->port, DEFAULT_PORT) == 0) {
f->bcks_have_port = 0;
return 0;
}
}
f->bcks_have_port = 1;
return 1;
}
static int backend_delete(struct backend *b)
{
if (!b)
return 0;
struct farm *f = b->parent;
backend_set_action(b, ACTION_STOP);
session_backend_action(f, b, ACTION_STOP);
if (backend_below_prio(b)) {
backend_s_gen_priority(f, ACTION_DELETE);
obj_rulerize(OBJ_START);
}
session_backend_action(f, b, ACTION_DELETE);
backend_delete_node(b);
backend_s_set_ports(f);
if (backend_s_gen_priority(f, ACTION_DELETE)) {
farm_set_action(f, ACTION_RELOAD);
farmaddress_s_set_action(f, ACTION_RELOAD);
obj_rulerize(OBJ_START);
}
return 0;
}
void backend_s_print(struct farm *f)
{
struct backend *b;
list_for_each_entry(b, &f->backends, list) {
tools_printlog(LOG_DEBUG," [backend] ");
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_NAME, b->name);
if (b->fqdn)
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_FQDN, b->fqdn);
if (b->oface)
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_OFACE, b->oface);
tools_printlog(LOG_DEBUG," *[ofidx] %d", b->ofidx);
if (b->ipaddr)
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_IPADDR, b->ipaddr);
if (b->ethaddr)
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_ETHADDR, b->ethaddr);
if (b->port)
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_PORT, b->port);
if (b->srcaddr)
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_SRCADDR, b->srcaddr);
tools_printlog(LOG_DEBUG," [%s] 0x%x", CONFIG_KEY_MARK, b->mark);
tools_printlog(LOG_DEBUG," [%s] %d", CONFIG_KEY_ESTCONNLIMIT, b->estconnlimit);
if (b->estconnlimit_logprefix && strcmp(b->estconnlimit_logprefix, DEFAULT_B_ESTCONNLIMIT_LOGPREFIX) != 0)
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_ESTCONNLIMIT_LOGPREFIX, b->estconnlimit_logprefix);
tools_printlog(LOG_DEBUG," [%s] %d", CONFIG_KEY_WEIGHT, b->weight);
tools_printlog(LOG_DEBUG," [%s] %d", CONFIG_KEY_PRIORITY, b->priority);
tools_printlog(LOG_DEBUG," [%s] %s", CONFIG_KEY_STATE, obj_print_state(b->state));
tools_printlog(LOG_DEBUG," *[%s] %d", CONFIG_KEY_ACTION, b->action);
}
}
struct backend * backend_lookup_by_key(struct farm *f, int key, const char *name, int value)
{
struct backend *b;
tools_printlog(LOG_DEBUG, "%s():%d: farm %s key %d name %s value %d", __FUNCTION__, __LINE__, f->name, key, name, value);
list_for_each_entry(b, &f->backends, list) {
switch (key) {
case KEY_NAME:
if (strcmp(b->name, name) == 0)
return b;
break;
case KEY_MARK:
if (value == backend_get_mark(b))
return b;
break;
case KEY_ETHADDR:
if (b->ethaddr && strcmp(b->ethaddr, name) == 0)
return b;
break;
case KEY_IPADDR:
if (b->ipaddr && strcmp(b->ipaddr, name) == 0)
return b;
break;
default:
return NULL;
}
}
return NULL;
}
static int backend_set_ipaddr_from_ether(struct backend *b)
{
struct farm *f = b->parent;
struct farmaddress *fa;
struct address *a;
int ret = -1;
unsigned char dst_ethaddr[ETH_HW_ADDR_LEN];
unsigned char src_ethaddr[ETH_HW_ADDR_LEN];
char streth[ETH_HW_STR_LEN] = {};
int *oface;
char **source_ip;
if (!farm_is_ingress_mode(f) || (f->state != VALUE_STATE_UP && f->state != VALUE_STATE_CONFERR))
return 0;
fa = farmaddress_get_first(f);
if (!fa) {
tools_printlog(LOG_INFO, "%s():%d: no farm address configured in %s", __FUNCTION__, __LINE__, f->name);
return -1;
}
a = fa->address;
if (a->iethaddr == DEFAULT_ETHADDR ||
b->ipaddr == DEFAULT_IPADDR ||
fa->farm->ofidx == DEFAULT_IFIDX)
return -1;
sscanf(a->iethaddr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &src_ethaddr[0], &src_ethaddr[1], &src_ethaddr[2], &src_ethaddr[3], &src_ethaddr[4], &src_ethaddr[5]);
oface = &a->ifidx;
source_ip = &(a->ipaddr);
if (f->srcaddr != DEFAULT_SRCADDR)
source_ip = &f->srcaddr;
ret = net_get_neigh_ether((unsigned char **) &dst_ethaddr, src_ethaddr, a->family, *source_ip, b->ipaddr, *oface);
if (ret != 0) {
oface = &f->ofidx;
if (b->ofidx != DEFAULT_IFIDX)
oface = &b->ofidx;
if (f->srcaddr != DEFAULT_SRCADDR)
source_ip = &f->srcaddr;
if (b->srcaddr != DEFAULT_SRCADDR)
source_ip = &b->srcaddr;
ret = net_get_neigh_ether((unsigned char **) &dst_ethaddr, src_ethaddr, a->family, *source_ip, b->ipaddr, *oface);
}
if (ret == 0) {
sprintf(streth, "%02x:%02x:%02x:%02x:%02x:%02x", dst_ethaddr[0],
dst_ethaddr[1], dst_ethaddr[2], dst_ethaddr[3], dst_ethaddr[4], dst_ethaddr[5]);
tools_printlog(LOG_DEBUG, "%s():%d: discovered ether address for %s is %s", __FUNCTION__, __LINE__, b->name, streth);
if (b->ethaddr)
free(b->ethaddr);
obj_set_attribute_string(streth, &b->ethaddr);
}
return ret;
}
static int backend_set_weight(struct backend *b, int new_value)
{
struct farm *f = b->parent;
int old_value = b->weight;
tools_printlog(LOG_DEBUG, "%s():%d: current value is %d, but new value will be %d",
__FUNCTION__, __LINE__, old_value, new_value);
b->weight = new_value;
if (backend_is_available(b))
f->total_weight += (b->weight-old_value);
return 0;
}
static int backend_set_estconnlimit(struct backend *b, int new_value)
{
int old_value = b->estconnlimit;
tools_printlog(LOG_DEBUG, "%s():%d: current value is %d, but new value will be %d",
__FUNCTION__, __LINE__, old_value, new_value);
if (new_value == old_value)
return 0;
b->estconnlimit = new_value;
return 0;
}
static void backend_s_update_counters(struct farm *f)
{
struct backend *bp, *next;
tools_printlog(LOG_DEBUG, "%s():%d: farm %s", __FUNCTION__, __LINE__, f->name);
f->bcks_available = 0;
f->bcks_usable = 0;
f->total_weight = 0;
list_for_each_entry_safe(bp, next, &f->backends, list) {
if (backend_is_available(bp)) {
f->bcks_available++;
f->total_weight += bp->weight;
}
if (backend_is_usable(bp))
f->bcks_usable++;
}
}
static int backend_set_priority(struct backend *b, int new_value)
{
int old_value = b->priority;
tools_printlog(LOG_DEBUG, "%s():%d: current value is %d, but new value will be %d",
__FUNCTION__, __LINE__, old_value, new_value);
if (new_value <= 0)
return -1;
b->priority = new_value;
backend_s_gen_priority(b->parent, ACTION_RELOAD);
return 0;
}
static int backend_s_set_srcaddr(struct farm *f)
{
struct backend *b;
tools_printlog(LOG_DEBUG, "%s():%d: finding backends with srouce address for %s", __FUNCTION__, __LINE__, f->name);
list_for_each_entry(b, &f->backends, list) {
if (b->srcaddr && strcmp(b->srcaddr, "") != 0) {
f->bcks_have_srcaddr = 1;
return 1;
}
}
f->bcks_have_srcaddr = 0;
return 0;
}
static int backend_set_mark(struct backend *b, int new_value)
{
int old_value = b->mark;
if (new_value < BACKEND_MARK_MIN || new_value > BACKEND_MARK_MAX)
return 0;
tools_printlog(LOG_DEBUG, "%s():%d: current value is %d, but new value will be %d",
__FUNCTION__, __LINE__, old_value, new_value);
b->mark = new_value;
return 0;
}
static int backend_set_port(struct backend *b, char *new_value)
{
char *old_value = b->port;
tools_printlog(LOG_DEBUG, "%s():%d: current value is %s, but new value will be %s",
__FUNCTION__, __LINE__, old_value, new_value);
if (strcmp(b->port, DEFAULT_PORT) != 0)
free(b->port);
obj_set_attribute_string(new_value, &b->port);
if (b->parent->bcks_have_port) {
if (strcmp(b->port, DEFAULT_PORT) == 0)
b->parent->bcks_have_port = 0;
} else
backend_s_set_ports(b->parent);
return 0;
}
static int backend_set_srcaddr(struct backend *b, char *new_value)
{
char *old_value = b->srcaddr;
tools_printlog(LOG_DEBUG, "%s():%d: current value is %s, but new value will be %s",
__FUNCTION__, __LINE__, old_value, new_value);
if (b->srcaddr)
free(b->srcaddr);
obj_set_attribute_string(new_value, &b->srcaddr);
if (b->srcaddr && strcmp(b->srcaddr, "") != 0)
b->parent->bcks_have_srcaddr = 1;
else
backend_s_set_srcaddr(b->parent);
return 0;
}
static int backend_set_ifinfo(struct backend *b)
{
struct farm *f = b->parent;
char if_str[IFNAMSIZ];
int if_index;
int ret = 0;
tools_printlog(LOG_DEBUG, "%s():%d: backend %s set interface info", __FUNCTION__, __LINE__, b->name);
if (!farm_is_ingress_mode(f) || (f->state != VALUE_STATE_UP && f->state != VALUE_STATE_CONFERR))
return 0;
if (f->oface && strcmp(f->oface, IFACE_LOOPBACK) == 0) {
tools_printlog(LOG_DEBUG, "%s():%d: backend %s in farm %s doesn't require output netinfo, loopback interface", __FUNCTION__, __LINE__, b->name, f->name);
f->ofidx = 0;
return 0;
}
if (!b || b->ipaddr == DEFAULT_IPADDR) {
tools_printlog(LOG_ERR, "%s():%d: there is no backend yet in the farm %s", __FUNCTION__, __LINE__, f->name);
return 0;
}
ret = net_get_local_ifidx_per_remote_host(b->ipaddr, &if_index);
if (ret == -1) {
tools_printlog(LOG_ERR, "%s():%d: unable to get the outbound interface to %s for the backend %s in farm %s", __FUNCTION__, __LINE__, b->ipaddr, b->name, f->name);
return -1;
}
if (f->ofidx == -1)
f->ofidx = if_index;
if (f->ofidx != if_index) {
f->bcks_have_if = 1;
b->ofidx = if_index;
}
if (if_indextoname(if_index, if_str) == NULL) {
tools_printlog(LOG_ERR, "%s():%d: unable to get the outbound interface name with index %d required by the backend %s in farm %s", __FUNCTION__, __LINE__, if_index, b->name, f->name);
return -1;
}
if (!f->oface) {
obj_set_attribute_string(if_str, &f->oface);
net_strim_netface(f->oface);
return 0;
}
if (f->oface && strcmp(f->oface, if_str) != 0) {
free(b->oface);
obj_set_attribute_string(if_str, &b->oface);
net_strim_netface(b->oface);
}
return 0;
}
static int backend_set_ipaddr(struct backend *b, char *new_value)
{
char *old_value = b->ipaddr;
int netconfig;
tools_printlog(LOG_DEBUG, "%s():%d: current value is %s, but new value will be %s",
__FUNCTION__, __LINE__, old_value, new_value);
if (b->ipaddr)
free(b->ipaddr);
if (b->ethaddr)
free(b->ethaddr);
obj_set_attribute_string(new_value, &b->ipaddr);
obj_set_attribute_string("", &b->ethaddr);
netconfig = (backend_set_ifinfo(b) == 0 && backend_set_ipaddr_from_ether(b) == 0);
if (old_value == DEFAULT_IPADDR)
return 0;
if (netconfig) {
if (b->state == VALUE_STATE_CONFERR)
backend_set_state(b, VALUE_STATE_UP);
} else
backend_set_state(b, VALUE_STATE_CONFERR);
return 0;
}
int backend_is_usable(struct backend *b)
{
tools_printlog(LOG_DEBUG, "%s():%d: backend %s state is %s and priority %d",
__FUNCTION__, __LINE__, b->name, obj_print_state(b->state), b->priority);
return ((b->state == VALUE_STATE_UP || b->state == VALUE_STATE_OFF) && backend_below_prio(b));
}
int backend_no_port(struct backend *b)
{
if (obj_equ_attribute_string(b->port, DEFAULT_PORT))
return 1;
return 0;
}
int backend_changed(struct config_pair *c)
{
struct farm *f = obj_get_current_farm();
struct backend *b = obj_get_current_backend();
if (!f || !b)
return -1;
tools_printlog(LOG_DEBUG, "%s():%d: farm %s backend %s with param %d", __FUNCTION__, __LINE__, f->name, b->name, c->key);
switch (c->key) {
case KEY_NAME:
return 1;
break;
case KEY_NEWNAME:
return !obj_equ_attribute_string(b->name, c->str_value);
break;
case KEY_FQDN:
return !obj_equ_attribute_string(b->fqdn, c->str_value);
break;
case KEY_IPADDR:
return !obj_equ_attribute_string(b->ipaddr, c->str_value);
break;
case KEY_ETHADDR:
return !obj_equ_attribute_string(b->ethaddr, c->str_value);
break;
case KEY_PORT:
return !obj_equ_attribute_string(b->port, c->str_value);
break;
case KEY_SRCADDR:
return !obj_equ_attribute_string(b->srcaddr, c->str_value);
break;
case KEY_WEIGHT:
return !obj_equ_attribute_int(b->weight, c->int_value);
break;
case KEY_PRIORITY:
return !obj_equ_attribute_int(b->priority, c->int_value);
break;
case KEY_MARK:
return !obj_equ_attribute_int(b->mark, c->int_value);
break;
case KEY_STATE:
return !obj_equ_attribute_int(b->state, c->int_value);
break;
case KEY_ACTION:
return !obj_equ_attribute_int(b->action, c->int_value);
break;
case KEY_ESTCONNLIMIT:
return !obj_equ_attribute_int(b->estconnlimit, c->int_value);
break;
case KEY_ESTCONNLIMIT_LOGPREFIX:
return !obj_equ_attribute_string(b->estconnlimit_logprefix, c->str_value);
break;
default:
break;
}
return 0;
}
int backend_validate(struct backend *b)
{
struct farm *f = b->parent;
tools_printlog(LOG_DEBUG, "%s():%d: validating backend %s of farm %s",
__FUNCTION__, __LINE__, b->name, f->name);
if (farm_is_ingress_mode(f) &&
(!b->ethaddr || strcmp(b->ethaddr, "") == 0))
return 0;
if (!b->ipaddr || strcmp(b->ipaddr, "") == 0)
return 0;
return 1;
}
int backend_is_available(struct backend *b)
{
tools_printlog(LOG_DEBUG, "%s():%d: backend %s state is %s and priority %d",
__FUNCTION__, __LINE__, b->name, obj_print_state(b->state), b->priority);
return (backend_validate(b) && (b->state == VALUE_STATE_UP) && backend_below_prio(b));
}
int backend_set_action(struct backend *b, int action)
{
int is_actionated = 0;
tools_printlog(LOG_DEBUG, "%s():%d: bck %s action %d state %d - new action %d",
__FUNCTION__, __LINE__, b->name, b->action, b->state, action);
if (action == ACTION_DELETE) {
backend_delete(b);
return 1;
}
if (action == ACTION_STOP) {
if (backend_is_available(b)) {
b->action = action;
is_actionated = 1;
}
backend_set_state(b, VALUE_STATE_DOWN);
return is_actionated;
}
if (action == ACTION_START) {
if (!backend_is_available(b)) {
b->action = action;
is_actionated = 1;
}
backend_set_state(b, VALUE_STATE_UP);
return is_actionated;
}
if (b->action > action) {
b->action = action;
return 1;
}
return is_actionated;
}
int backend_s_set_action(struct farm *f, int action)
{
struct backend *b, *next;
list_for_each_entry_safe(b, next, &f->backends, list)
backend_set_action(b, action);
return 0;
}
int backend_s_delete(struct farm *f)
{
struct backend *b, *next;
list_for_each_entry_safe(b, next, &f->backends, list)
backend_delete_node(b);
f->total_bcks = 0;
f->bcks_available = 0;
f->bcks_usable = 0;
f->total_weight = 0;
f->bcks_have_if = 0;
return 0;
}
int backend_s_validate(struct farm *f)
{
struct backend *b, *next;
int valid = 0;
list_for_each_entry_safe(b, next, &f->backends, list) {
valid = backend_validate(b);
if (b->state == VALUE_STATE_CONFERR && valid)
backend_set_state(b, VALUE_STATE_UP);
}
return 0;
}
int backend_set_attribute(struct config_pair *c)
{
struct farm *f = obj_get_current_farm();
struct backend *b = obj_get_current_backend();
if (!f || (c->key != KEY_NAME && !b))
return PARSER_OBJ_UNKNOWN;
switch (c->key) {
case KEY_NAME:
b = backend_lookup_by_key(f, KEY_NAME, c->str_value, 0);
if (!b) {
b = backend_create(f, c->str_value);
if (!b)
return -1;
}
obj_set_current_backend(b);
break;
case KEY_NEWNAME:
free(b->name);
obj_set_attribute_string(c->str_value, &b->name);
break;
case KEY_FQDN:
if (strcmp(b->fqdn, DEFAULT_FQDN) != 0)
free(b->fqdn);
obj_set_attribute_string(c->str_value, &b->fqdn);
break;
case KEY_IPADDR:
backend_set_ipaddr(b, c->str_value);
break;
case KEY_ETHADDR:
if (b->ethaddr)
free(b->ethaddr);
obj_set_attribute_string(c->str_value, &b->ethaddr);
break;
case KEY_PORT:
backend_set_port(b, c->str_value);
break;
case KEY_SRCADDR:
backend_set_srcaddr(b, c->str_value);
break;
case KEY_WEIGHT:
backend_set_weight(b, c->int_value);
break;
case KEY_PRIORITY:
backend_set_priority(b, c->int_value);
break;
case KEY_MARK:
backend_set_mark(b, c->int_value);
break;
case KEY_STATE:
if (c->int_value == VALUE_STATE_CONFERR)
backend_set_state(b, VALUE_STATE_UP);
else
backend_set_state(b, c->int_value);
break;
case KEY_ESTCONNLIMIT:
backend_set_estconnlimit(b, c->int_value);
break;
case KEY_ACTION:
backend_set_action(b, c->int_value);
break;
case KEY_ESTCONNLIMIT_LOGPREFIX:
if (strcmp(b->estconnlimit_logprefix, DEFAULT_B_ESTCONNLIMIT_LOGPREFIX) != 0)
free(b->estconnlimit_logprefix);
obj_set_attribute_string(c->str_value, &b->estconnlimit_logprefix);
break;
default:
return -1;
}
return PARSER_OK;
}
int backend_set_state(struct backend *b, int new_value)
{
int old_value = b->state;
struct farm *f = b->parent;
tools_printlog(LOG_DEBUG, "%s():%d: backend %s current value is %s, but new value will be %s",
__FUNCTION__, __LINE__, b->name, obj_print_state(old_value), obj_print_state(new_value));
if (new_value == VALUE_STATE_UP) {
if (!backend_validate(b)) {
new_value = VALUE_STATE_CONFERR;
}
if (!backend_below_prio(b))
new_value = VALUE_STATE_AVAIL;
}
if (old_value == new_value)
return 0;
b->state = new_value;
switch (new_value) {
case VALUE_STATE_CONFERR:
if (old_value == VALUE_STATE_UP)
b->action = ACTION_STOP;
break;
case VALUE_STATE_OFF:
if (old_value == VALUE_STATE_UP)
b->action = ACTION_STOP;
if (old_value == VALUE_STATE_DOWN)
b->action = ACTION_START;
break;
case VALUE_STATE_AVAIL:
if (old_value == VALUE_STATE_UP)
b->action = ACTION_STOP;
return 0;
case VALUE_STATE_UP:
if (f->persistence != VALUE_META_NONE)
session_backend_action(f, b, ACTION_START);
if (old_value == VALUE_STATE_OFF)
b->action = ACTION_RELOAD;
else
b->action = ACTION_START;
break;
case VALUE_STATE_DOWN:
if (old_value == VALUE_STATE_UP || old_value == VALUE_STATE_OFF)
b->action = ACTION_STOP;
break;
default:
break;
}
if (b->action != ACTION_NONE) {
farm_set_action(f, ACTION_RELOAD);
backend_s_gen_priority(f, ACTION_NONE);
}
return 0;
}
int backend_s_set_ether_by_ipaddr(struct farm *f, const char *ip_bck, char *ether_bck)
{
struct backend *b;
int changed = 0;
list_for_each_entry(b, &f->backends, list) {
if (strcmp(b->ipaddr, ip_bck) != 0)
continue;
tools_printlog(LOG_DEBUG, "%s():%d: backend with ip address %s found", __FUNCTION__, __LINE__, ip_bck);
if (!b->ethaddr || (b->ethaddr && strcmp(b->ethaddr, ether_bck) != 0)) {
if (f->persistence != VALUE_META_NONE)
session_get_timed(f);
if (b->ethaddr)
free(b->ethaddr);
obj_set_attribute_string(ether_bck, &b->ethaddr);
changed = 1;
if (f->persistence != VALUE_META_NONE) {
session_backend_action(f, b, ACTION_RELOAD);
farm_set_action(f, ACTION_RELOAD);
obj_rulerize(OBJ_START);
session_s_delete(f, SESSION_TYPE_TIMED);
}
tools_printlog(LOG_INFO, "%s():%d: ether address changed for backend %s with %s", __FUNCTION__, __LINE__, b->name, ether_bck);
}
}
return changed;
}
static void backend_set_netinfo(struct backend *b)
{
if (backend_set_ifinfo(b) == 0 && backend_set_ipaddr_from_ether(b) == 0) {
if (b->state == VALUE_STATE_CONFERR)
backend_set_state(b, VALUE_STATE_UP);
} else
backend_set_state(b, VALUE_STATE_CONFERR);
}
int backend_s_set_netinfo(struct farm *f)
{
struct backend *b;
int changed = 0;
tools_printlog(LOG_DEBUG, "%s():%d: finding backends for %s", __FUNCTION__, __LINE__, f->name);
list_for_each_entry(b, &f->backends, list) {
if (backend_validate(b))
continue;
backend_set_netinfo(b);
}
return changed;
}
struct backend * backend_get_first(struct farm *f)
{
if (list_empty(&f->backends))
return NULL;
return list_first_entry(&f->backends, struct backend, list);
}
int bck_pre_actionable(struct config_pair *c)
{
struct farm *f = obj_get_current_farm();
struct backend *b = obj_get_current_backend();
if (!f || !b)
return -1;
tools_printlog(LOG_DEBUG, "%s():%d: pre actionable backend %s of farm %s with param %d", __FUNCTION__, __LINE__, b->name, f->name, c->key);
// changing priority of a down backend could affect others, force a farm restart
if (b->state != VALUE_STATE_UP && b->state != VALUE_STATE_CONFERR && c->key == KEY_PRIORITY) {
farm_set_action(f, ACTION_STOP);
farmaddress_s_set_action(f, ACTION_STOP);
farm_rulerize(f);
return ACTION_FLUSH;
}
if (b->state != VALUE_STATE_UP && c->key != KEY_STATE)
return ACTION_NONE;
switch (c->key) {
case KEY_NAME:
break;
case KEY_ETHADDR:
case KEY_IPADDR:
case KEY_SRCADDR:
case KEY_MARK:
case KEY_PRIORITY:
case KEY_ESTCONNLIMIT:
if (backend_set_action(b, ACTION_STOP)) {
farm_set_action(f, ACTION_RELOAD);
farmaddress_s_set_action(f, ACTION_RELOAD);
farm_rulerize(f);
}
return ACTION_START;
break;
case KEY_PORT:
case KEY_STATE:
case KEY_WEIGHT:
case KEY_ESTCONNLIMIT_LOGPREFIX:
return ACTION_RELOAD;
break;
default:
break;
}
return ACTION_NONE;
}
int bck_pos_actionable(struct config_pair *c, int action)
{
struct farm *f = obj_get_current_farm();
struct backend *b = obj_get_current_backend();
if (!f || !b)
return -1;
tools_printlog(LOG_DEBUG, "%s():%d: pos actionable backend %s of farm %s with param %d action %d", __FUNCTION__, __LINE__, b->name, f->name, c->key, action);
switch (action) {
case ACTION_START:
if (backend_set_action(b, ACTION_START)) {
farm_set_action(f, ACTION_RELOAD);
farmaddress_s_set_action(f, ACTION_RELOAD);
farm_rulerize(f);
}
break;
case ACTION_RELOAD:
farm_set_action(f, ACTION_RELOAD);
break;
case ACTION_FLUSH:
farm_set_action(f, ACTION_START);
farm_rulerize(f);
break;
default:
break;
}
return 0;
}
int backend_s_gen_priority(struct farm *f, int action)
{
struct backend *b, *next;
int are_down;
int old_prio = f->priority;
int new_prio = DEFAULT_PRIORITY;
do {
are_down = 0;
list_for_each_entry_safe(b, next, &f->backends, list)
if (b->priority == new_prio && b->state != VALUE_STATE_UP && b->state != VALUE_STATE_AVAIL)
are_down++;
new_prio += are_down;
} while (are_down);
f->priority = new_prio;
list_for_each_entry_safe(b, next, &f->backends, list) {
if (b->state == VALUE_STATE_UP || b->state == VALUE_STATE_AVAIL)
backend_set_state(b, VALUE_STATE_UP);
}
backend_s_update_counters(f);
return f->priority != old_prio;
}
int backend_get_mark(struct backend *b)
{
int mark = b->mark;
if (b->srcaddr && strcmp(b->srcaddr, "") != 0)
mark |= b->parent->mark;
else
mark |= farm_get_mark(b->parent);
return mark;
}
int backend_s_check_have_iface(struct farm *f)
{
struct backend *b, *next;
list_for_each_entry_safe(b, next, &f->backends, list) {
if (b->ofidx == DEFAULT_IFIDX)
continue;
if (f->ofidx != b->ofidx)
return 1;
}
return 0;
}
nftlb-1.0.7/src/checksum.c 0000664 0000000 0000000 00000007640 14326712445 0015400 0 ustar 00root root 0000000 0000000 /* Copyright (C) 2011-2015 P.D. Buchan (pdbuchan@yahoo.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include
#include
#include
#include "checksum.h"
uint16_t checksum (uint16_t *addr, int len)
{
int count = len;
register uint32_t sum = 0;
uint16_t answer = 0;
// Sum up 2-byte values until none or only one byte left.
while (count > 1) {
sum += *(addr++);
count -= 2;
}
// Add left-over byte, if any.
if (count > 0) {
sum += *(uint8_t *) addr;
}
// Fold 32-bit sum into 16 bits; we lose information by doing this,
// increasing the chances of a collision.
// sum = (lower 16 bits) + (upper 16 bits shifted right 16 bits)
while (sum >> 16) {
sum = (sum & 0xffff) + (sum >> 16);
}
// Checksum is one's compliment of sum.
answer = ~sum;
return (answer);
}
// Build IPv6 ICMP pseudo-header and call checksum function (Section 8.1 of RFC 2460).
uint16_t icmp6_checksum (struct ip6_hdr iphdr, struct icmp6_hdr icmp6hdr, uint8_t *payload, int payloadlen)
{
char buf[IP_MAXPACKET];
char *ptr;
int chksumlen = 0;
int i;
ptr = &buf[0]; // ptr points to beginning of buffer buf
// Copy source IP address into buf (128 bits)
memcpy (ptr, &iphdr.ip6_src.s6_addr, sizeof (iphdr.ip6_src.s6_addr));
ptr += sizeof (iphdr.ip6_src);
chksumlen += sizeof (iphdr.ip6_src);
// Copy destination IP address into buf (128 bits)
memcpy (ptr, &iphdr.ip6_dst.s6_addr, sizeof (iphdr.ip6_dst.s6_addr));
ptr += sizeof (iphdr.ip6_dst.s6_addr);
chksumlen += sizeof (iphdr.ip6_dst.s6_addr);
// Copy Upper Layer Packet length into buf (32 bits).
// Should not be greater than 65535 (i.e., 2 bytes).
*ptr = 0; ptr++;
*ptr = 0; ptr++;
*ptr = (ICMP_HDRLEN + payloadlen) / 256;
ptr++;
*ptr = (ICMP_HDRLEN + payloadlen) % 256;
ptr++;
chksumlen += 4;
// Copy zero field to buf (24 bits)
*ptr = 0; ptr++;
*ptr = 0; ptr++;
*ptr = 0; ptr++;
chksumlen += 3;
// Copy next header field to buf (8 bits)
memcpy (ptr, &iphdr.ip6_nxt, sizeof (iphdr.ip6_nxt));
ptr += sizeof (iphdr.ip6_nxt);
chksumlen += sizeof (iphdr.ip6_nxt);
// Copy ICMPv6 type to buf (8 bits)
memcpy (ptr, &icmp6hdr.icmp6_type, sizeof (icmp6hdr.icmp6_type));
ptr += sizeof (icmp6hdr.icmp6_type);
chksumlen += sizeof (icmp6hdr.icmp6_type);
// Copy ICMPv6 code to buf (8 bits)
memcpy (ptr, &icmp6hdr.icmp6_code, sizeof (icmp6hdr.icmp6_code));
ptr += sizeof (icmp6hdr.icmp6_code);
chksumlen += sizeof (icmp6hdr.icmp6_code);
// Copy ICMPv6 ID to buf (16 bits)
memcpy (ptr, &icmp6hdr.icmp6_id, sizeof (icmp6hdr.icmp6_id));
ptr += sizeof (icmp6hdr.icmp6_id);
chksumlen += sizeof (icmp6hdr.icmp6_id);
// Copy ICMPv6 sequence number to buff (16 bits)
memcpy (ptr, &icmp6hdr.icmp6_seq, sizeof (icmp6hdr.icmp6_seq));
ptr += sizeof (icmp6hdr.icmp6_seq);
chksumlen += sizeof (icmp6hdr.icmp6_seq);
// Copy ICMPv6 checksum to buf (16 bits)
// Zero, since we don't know it yet.
*ptr = 0; ptr++;
*ptr = 0; ptr++;
chksumlen += 2;
// Copy ICMPv6 payload to buf
memcpy (ptr, payload, payloadlen * sizeof (uint8_t));
ptr += payloadlen;
chksumlen += payloadlen;
// Pad to the next 16-bit boundary
for (i=0; i