Move libnl headers to their own project
Change-Id: I322663ef963df79ef7016f3e8f9480358ce9b0c3
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Android.mk
diff --git a/CleanSpec.mk b/CleanSpec.mk
new file mode 100644
index 0000000..b84e1b6
--- /dev/null
+++ b/CleanSpec.mk
@@ -0,0 +1,49 @@
+# Copyright (C) 2007 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# If you don't need to do a full clean build but would like to touch
+# a file or delete some intermediate files, add a clean step to the end
+# of the list. These steps will only be run once, if they haven't been
+# run before.
+#
+# E.g.:
+# $(call add-clean-step, touch -c external/sqlite/sqlite3.h)
+# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates)
+#
+# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with
+# files that are missing or have been moved.
+#
+# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory.
+# Use $(OUT_DIR) to refer to the "out" directory.
+#
+# If you need to re-do something that's already mentioned, just copy
+# the command and add it to the bottom of the list. E.g., if a change
+# that you made last week required touching a file and a change you
+# made today requires touching the same file, just copy the old
+# touch step and add it to the end of the list.
+#
+# ************************************************
+# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
+# ************************************************
+
+# For example:
+#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates)
+#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates)
+#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
+#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
+
+# ************************************************
+# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
+# ************************************************
diff --git a/MODULE_LICENSE_LGPL b/MODULE_LICENSE_LGPL
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_LGPL
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..fab48ed
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,506 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
+
+
+
+
diff --git a/netlink-generic.h b/netlink-generic.h
new file mode 100644
index 0000000..10aa2f0
--- /dev/null
+++ b/netlink-generic.h
@@ -0,0 +1,20 @@
+/*
+ * netlink-generic.h Local Generic Netlink Interface
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_GENL_PRIV_H_
+#define NETLINK_GENL_PRIV_H_
+
+#include <netlink-local.h>
+#include <netlink/netlink.h>
+
+#define GENL_HDRSIZE(hdrlen) (GENL_HDRLEN + (hdrlen))
+
+#endif
diff --git a/netlink-local.h b/netlink-local.h
new file mode 100644
index 0000000..0d8c9ab
--- /dev/null
+++ b/netlink-local.h
@@ -0,0 +1,186 @@
+/*
+ * netlink-local.h Local Netlink Interface
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_LOCAL_H_
+#define NETLINK_LOCAL_H_
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <math.h>
+#include <time.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <inttypes.h>
+#include <assert.h>
+#include <limits.h>
+
+#include <arpa/inet.h>
+#include <netdb.h>
+
+#ifndef SOL_NETLINK
+#define SOL_NETLINK 270
+#endif
+
+#include <linux/types.h>
+
+/* local header copies */
+#include <linux/if.h>
+#include <linux/if_arp.h>
+#include <linux/if_ether.h>
+#include <linux/pkt_sched.h>
+#include <linux/pkt_cls.h>
+#include <linux/gen_stats.h>
+#include <linux/ip_mp_alg.h>
+
+#include <netlink/netlink.h>
+#include <netlink/handlers.h>
+#include <netlink/cache.h>
+#include <netlink/route/tc.h>
+#include <netlink/object-api.h>
+#include <netlink/cache-api.h>
+#include <netlink-types.h>
+
+struct trans_tbl {
+ int i;
+ const char *a;
+};
+
+#define __ADD(id, name) { .i = id, .a = #name },
+
+struct trans_list {
+ int i;
+ char *a;
+ struct nl_list_head list;
+};
+
+#define NL_DEBUG 1
+
+#define NL_DBG(LVL,FMT,ARG...) \
+ do { \
+ if (LVL <= nl_debug) \
+ fprintf(stderr, "DBG<" #LVL ">: " FMT, ##ARG); \
+ } while (0)
+
+#define BUG() \
+ do { \
+ fprintf(stderr, "BUG: %s:%d\n", \
+ __FILE__, __LINE__); \
+ assert(0); \
+ } while (0)
+
+extern int __nl_read_num_str_file(const char *path,
+ int (*cb)(long, const char *));
+
+extern int __trans_list_add(int, const char *, struct nl_list_head *);
+extern void __trans_list_clear(struct nl_list_head *);
+
+extern char *__type2str(int, char *, size_t, struct trans_tbl *, size_t);
+extern int __str2type(const char *, struct trans_tbl *, size_t);
+
+extern char *__list_type2str(int, char *, size_t, struct nl_list_head *);
+extern int __list_str2type(const char *, struct nl_list_head *);
+
+extern char *__flags2str(int, char *, size_t, struct trans_tbl *, size_t);
+extern int __str2flags(const char *, struct trans_tbl *, size_t);
+
+extern void dump_from_ops(struct nl_object *, struct nl_dump_params *);
+
+static inline struct nl_cache *dp_cache(struct nl_object *obj)
+{
+ if (obj->ce_cache == NULL)
+ return nl_cache_mngt_require(obj->ce_ops->oo_name);
+
+ return obj->ce_cache;
+}
+
+static inline int nl_cb_call(struct nl_cb *cb, int type, struct nl_msg *msg)
+{
+ return cb->cb_set[type](msg, cb->cb_args[type]);
+}
+
+#define ARRAY_SIZE(X) (sizeof(X) / sizeof((X)[0]))
+#ifndef offsetof
+#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+#endif
+
+#define __init __attribute__ ((constructor))
+#define __exit __attribute__ ((destructor))
+#undef __deprecated
+#define __deprecated __attribute__ ((deprecated))
+
+#define min(x,y) ({ \
+ typeof(x) _x = (x); \
+ typeof(y) _y = (y); \
+ (void) (&_x == &_y); \
+ _x < _y ? _x : _y; })
+
+#define max(x,y) ({ \
+ typeof(x) _x = (x); \
+ typeof(y) _y = (y); \
+ (void) (&_x == &_y); \
+ _x > _y ? _x : _y; })
+
+#define min_t(type,x,y) \
+ ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
+#define max_t(type,x,y) \
+ ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
+
+extern int nl_cache_parse(struct nl_cache_ops *, struct sockaddr_nl *,
+ struct nlmsghdr *, struct nl_parser_param *);
+
+
+static inline void rtnl_copy_ratespec(struct rtnl_ratespec *dst,
+ struct tc_ratespec *src)
+{
+ dst->rs_cell_log = src->cell_log;
+ dst->rs_feature = src->feature;
+ dst->rs_addend = src->addend;
+ dst->rs_mpu = src->mpu;
+ dst->rs_rate = src->rate;
+}
+
+static inline void rtnl_rcopy_ratespec(struct tc_ratespec *dst,
+ struct rtnl_ratespec *src)
+{
+ dst->cell_log = src->rs_cell_log;
+ dst->feature = src->rs_feature;
+ dst->addend = src->rs_addend;
+ dst->mpu = src->rs_mpu;
+ dst->rate = src->rs_rate;
+}
+
+static inline char *nl_cache_name(struct nl_cache *cache)
+{
+ return cache->c_ops ? cache->c_ops->co_name : "unknown";
+}
+
+#define GENL_FAMILY(id, name) \
+ { \
+ { id, NL_ACT_UNSPEC, name }, \
+ END_OF_MSGTYPES_LIST, \
+ }
+
+static inline int wait_for_ack(struct nl_sock *sk)
+{
+ if (sk->s_flags & NL_NO_AUTO_ACK)
+ return 0;
+ else
+ return nl_wait_for_ack(sk);
+}
+
+#endif
diff --git a/netlink-types.h b/netlink-types.h
new file mode 100644
index 0000000..92be87c
--- /dev/null
+++ b/netlink-types.h
@@ -0,0 +1,832 @@
+/*
+ * netlink-types.h Netlink Types (Private)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_LOCAL_TYPES_H_
+#define NETLINK_LOCAL_TYPES_H_
+
+#include <netlink/list.h>
+#include <netlink/route/link.h>
+#include <netlink/route/qdisc.h>
+#include <netlink/route/rtnl.h>
+#include <netlink/route/route.h>
+#include <netlink/object-api.h>
+#include <linux/socket.h>
+#include <linux/pkt_sched.h>
+
+#define NL_SOCK_BUFSIZE_SET (1<<0)
+#define NL_SOCK_PASSCRED (1<<1)
+#define NL_OWN_PORT (1<<2)
+#define NL_MSG_PEEK (1<<3)
+#define NL_NO_AUTO_ACK (1<<4)
+
+#define NL_MSG_CRED_PRESENT 1
+
+struct nl_cache_ops;
+struct nl_sock;
+struct nl_object;
+
+struct nl_cb
+{
+ nl_recvmsg_msg_cb_t cb_set[NL_CB_TYPE_MAX+1];
+ void * cb_args[NL_CB_TYPE_MAX+1];
+
+ nl_recvmsg_err_cb_t cb_err;
+ void * cb_err_arg;
+
+ /** May be used to replace nl_recvmsgs with your own implementation
+ * in all internal calls to nl_recvmsgs. */
+ int (*cb_recvmsgs_ow)(struct nl_sock *,
+ struct nl_cb *);
+
+ /** Overwrite internal calls to nl_recv, must return the number of
+ * octets read and allocate a buffer for the received data. */
+ int (*cb_recv_ow)(struct nl_sock *,
+ struct sockaddr_nl *,
+ unsigned char **,
+ struct ucred **);
+
+ /** Overwrites internal calls to nl_send, must send the netlink
+ * message. */
+ int (*cb_send_ow)(struct nl_sock *,
+ struct nl_msg *);
+
+ int cb_refcnt;
+};
+
+struct nl_sock
+{
+ struct sockaddr_nl s_local;
+ struct sockaddr_nl s_peer;
+ int s_fd;
+ int s_proto;
+ unsigned int s_seq_next;
+ unsigned int s_seq_expect;
+ int s_flags;
+ struct nl_cb * s_cb;
+};
+
+struct nl_cache
+{
+ struct nl_list_head c_items;
+ int c_nitems;
+ int c_iarg1;
+ int c_iarg2;
+ struct nl_cache_ops * c_ops;
+};
+
+struct nl_cache_assoc
+{
+ struct nl_cache * ca_cache;
+ change_func_t ca_change;
+ void * ca_change_data;
+};
+
+struct nl_cache_mngr
+{
+ int cm_protocol;
+ int cm_flags;
+ int cm_nassocs;
+ struct nl_sock * cm_handle;
+ struct nl_cache_assoc * cm_assocs;
+};
+
+struct nl_parser_param;
+
+#define LOOSE_COMPARISON 1
+
+#define NL_OBJ_MARK 1
+
+struct nl_object
+{
+ NLHDR_COMMON
+};
+
+struct nl_data
+{
+ size_t d_size;
+ void * d_data;
+};
+
+struct nl_addr
+{
+ int a_family;
+ unsigned int a_maxsize;
+ unsigned int a_len;
+ int a_prefixlen;
+ int a_refcnt;
+ char a_addr[0];
+};
+
+struct nl_msg
+{
+ int nm_protocol;
+ int nm_flags;
+ struct sockaddr_nl nm_src;
+ struct sockaddr_nl nm_dst;
+ struct ucred nm_creds;
+ struct nlmsghdr * nm_nlh;
+ size_t nm_size;
+ int nm_refcnt;
+};
+
+struct rtnl_link_map
+{
+ uint64_t lm_mem_start;
+ uint64_t lm_mem_end;
+ uint64_t lm_base_addr;
+ uint16_t lm_irq;
+ uint8_t lm_dma;
+ uint8_t lm_port;
+};
+
+#define IFQDISCSIZ 32
+
+struct rtnl_link
+{
+ NLHDR_COMMON
+
+ char l_name[IFNAMSIZ];
+
+ uint32_t l_family;
+ uint32_t l_arptype;
+ uint32_t l_index;
+ uint32_t l_flags;
+ uint32_t l_change;
+ uint32_t l_mtu;
+ uint32_t l_link;
+ uint32_t l_txqlen;
+ uint32_t l_weight;
+ uint32_t l_master;
+ struct nl_addr *l_addr;
+ struct nl_addr *l_bcast;
+ char l_qdisc[IFQDISCSIZ];
+ struct rtnl_link_map l_map;
+ uint64_t l_stats[RTNL_LINK_STATS_MAX+1];
+ uint32_t l_flag_mask;
+ uint8_t l_operstate;
+ uint8_t l_linkmode;
+ /* 2 byte hole */
+ struct rtnl_link_info_ops *l_info_ops;
+ void * l_info;
+};
+
+struct rtnl_ncacheinfo
+{
+ uint32_t nci_confirmed; /**< Time since neighbour validty was last confirmed */
+ uint32_t nci_used; /**< Time since neighbour entry was last ued */
+ uint32_t nci_updated; /**< Time since last update */
+ uint32_t nci_refcnt; /**< Reference counter */
+};
+
+
+struct rtnl_neigh
+{
+ NLHDR_COMMON
+ uint32_t n_family;
+ uint32_t n_ifindex;
+ uint16_t n_state;
+ uint8_t n_flags;
+ uint8_t n_type;
+ struct nl_addr *n_lladdr;
+ struct nl_addr *n_dst;
+ uint32_t n_probes;
+ struct rtnl_ncacheinfo n_cacheinfo;
+ uint32_t n_state_mask;
+ uint32_t n_flag_mask;
+};
+
+
+struct rtnl_addr_cacheinfo
+{
+ /* Preferred lifetime in seconds */
+ uint32_t aci_prefered;
+
+ /* Valid lifetime in seconds */
+ uint32_t aci_valid;
+
+ /* Timestamp of creation in 1/100s seince boottime */
+ uint32_t aci_cstamp;
+
+ /* Timestamp of last update in 1/100s since boottime */
+ uint32_t aci_tstamp;
+};
+
+struct rtnl_addr
+{
+ NLHDR_COMMON
+
+ uint8_t a_family;
+ uint8_t a_prefixlen;
+ uint8_t a_flags;
+ uint8_t a_scope;
+ uint32_t a_ifindex;
+
+ struct nl_addr *a_peer;
+ struct nl_addr *a_local;
+ struct nl_addr *a_bcast;
+ struct nl_addr *a_anycast;
+ struct nl_addr *a_multicast;
+
+ struct rtnl_addr_cacheinfo a_cacheinfo;
+
+ char a_label[IFNAMSIZ];
+ uint32_t a_flag_mask;
+};
+
+struct rtnl_nexthop
+{
+ uint8_t rtnh_flags;
+ uint8_t rtnh_flag_mask;
+ uint8_t rtnh_weight;
+ /* 1 byte spare */
+ uint32_t rtnh_ifindex;
+ struct nl_addr * rtnh_gateway;
+ uint32_t ce_mask; /* HACK to support attr macros */
+ struct nl_list_head rtnh_list;
+ uint32_t rtnh_realms;
+};
+
+struct rtnl_route
+{
+ NLHDR_COMMON
+
+ uint8_t rt_family;
+ uint8_t rt_dst_len;
+ uint8_t rt_src_len;
+ uint8_t rt_tos;
+ uint8_t rt_protocol;
+ uint8_t rt_scope;
+ uint8_t rt_type;
+ uint8_t rt_nmetrics;
+ uint32_t rt_flags;
+ struct nl_addr * rt_dst;
+ struct nl_addr * rt_src;
+ uint32_t rt_table;
+ uint32_t rt_iif;
+ uint32_t rt_prio;
+ uint32_t rt_metrics[RTAX_MAX];
+ uint32_t rt_metrics_mask;
+ uint32_t rt_nr_nh;
+ struct nl_addr * rt_pref_src;
+ struct nl_list_head rt_nexthops;
+ struct rtnl_rtcacheinfo rt_cacheinfo;
+ uint32_t rt_flag_mask;
+};
+
+struct rtnl_rule
+{
+ NLHDR_COMMON
+
+ uint64_t r_mark;
+ uint32_t r_prio;
+ uint32_t r_realms;
+ uint32_t r_table;
+ uint8_t r_dsfield;
+ uint8_t r_type;
+ uint8_t r_family;
+ uint8_t r_src_len;
+ uint8_t r_dst_len;
+ char r_iif[IFNAMSIZ];
+ struct nl_addr *r_src;
+ struct nl_addr *r_dst;
+ struct nl_addr *r_srcmap;
+};
+
+struct rtnl_neightbl_parms
+{
+ /**
+ * Interface index of the device this parameter set is assigned
+ * to or 0 for the default set.
+ */
+ uint32_t ntp_ifindex;
+
+ /**
+ * Number of references to this parameter set.
+ */
+ uint32_t ntp_refcnt;
+
+ /**
+ * Queue length for pending arp requests, i.e. the number of
+ * packets which are accepted from other layers while the
+ * neighbour address is still being resolved
+ */
+ uint32_t ntp_queue_len;
+
+ /**
+ * Number of requests to send to the user level ARP daemon.
+ * Specify 0 to disable.
+ */
+ uint32_t ntp_app_probes;
+
+ /**
+ * Maximum number of retries for unicast solicitation.
+ */
+ uint32_t ntp_ucast_probes;
+
+ /**
+ * Maximum number of retries for multicast solicitation.
+ */
+ uint32_t ntp_mcast_probes;
+
+ /**
+ * Base value in milliseconds to ompute reachable time, see RFC2461.
+ */
+ uint64_t ntp_base_reachable_time;
+
+ /**
+ * Actual reachable time (read-only)
+ */
+ uint64_t ntp_reachable_time; /* secs */
+
+ /**
+ * The time in milliseconds between retransmitted Neighbor
+ * Solicitation messages.
+ */
+ uint64_t ntp_retrans_time;
+
+ /**
+ * Interval in milliseconds to check for stale neighbour
+ * entries.
+ */
+ uint64_t ntp_gc_stale_time; /* secs */
+
+ /**
+ * Delay in milliseconds for the first time probe if
+ * the neighbour is reachable.
+ */
+ uint64_t ntp_probe_delay; /* secs */
+
+ /**
+ * Maximum delay in milliseconds of an answer to a neighbour
+ * solicitation message.
+ */
+ uint64_t ntp_anycast_delay;
+
+ /**
+ * Minimum age in milliseconds before a neighbour entry
+ * may be replaced.
+ */
+ uint64_t ntp_locktime;
+
+ /**
+ * Delay in milliseconds before answering to an ARP request
+ * for which a proxy ARP entry exists.
+ */
+ uint64_t ntp_proxy_delay;
+
+ /**
+ * Queue length for the delayed proxy arp requests.
+ */
+ uint32_t ntp_proxy_qlen;
+
+ /**
+ * Mask of available parameter attributes
+ */
+ uint32_t ntp_mask;
+};
+
+#define NTBLNAMSIZ 32
+
+/**
+ * Neighbour table
+ * @ingroup neightbl
+ */
+struct rtnl_neightbl
+{
+ NLHDR_COMMON
+
+ char nt_name[NTBLNAMSIZ];
+ uint32_t nt_family;
+ uint32_t nt_gc_thresh1;
+ uint32_t nt_gc_thresh2;
+ uint32_t nt_gc_thresh3;
+ uint64_t nt_gc_interval;
+ struct ndt_config nt_config;
+ struct rtnl_neightbl_parms nt_parms;
+ struct ndt_stats nt_stats;
+};
+
+struct rtnl_ratespec
+{
+ uint8_t rs_cell_log;
+ uint16_t rs_feature;
+ uint16_t rs_addend;
+ uint16_t rs_mpu;
+ uint32_t rs_rate;
+};
+
+struct rtnl_tstats
+{
+ struct {
+ uint64_t bytes;
+ uint64_t packets;
+ } tcs_basic;
+
+ struct {
+ uint32_t bps;
+ uint32_t pps;
+ } tcs_rate_est;
+
+ struct {
+ uint32_t qlen;
+ uint32_t backlog;
+ uint32_t drops;
+ uint32_t requeues;
+ uint32_t overlimits;
+ } tcs_queue;
+};
+
+#define TCKINDSIZ 32
+
+#define NL_TCA_GENERIC(pre) \
+ NLHDR_COMMON \
+ uint32_t pre ##_family; \
+ uint32_t pre ##_ifindex; \
+ uint32_t pre ##_handle; \
+ uint32_t pre ##_parent; \
+ uint32_t pre ##_info; \
+ char pre ##_kind[TCKINDSIZ]; \
+ struct nl_data * pre ##_opts; \
+ uint64_t pre ##_stats[RTNL_TC_STATS_MAX+1]; \
+ struct nl_data * pre ##_xstats; \
+ struct nl_data * pre ##_subdata; \
+
+
+struct rtnl_tca
+{
+ NL_TCA_GENERIC(tc);
+};
+
+struct rtnl_qdisc
+{
+ NL_TCA_GENERIC(q);
+ struct rtnl_qdisc_ops *q_ops;
+};
+
+struct rtnl_class
+{
+ NL_TCA_GENERIC(c);
+ struct rtnl_class_ops *c_ops;
+};
+
+struct rtnl_cls
+{
+ NL_TCA_GENERIC(c);
+ uint16_t c_prio;
+ uint16_t c_protocol;
+ struct rtnl_cls_ops *c_ops;
+};
+
+struct rtnl_u32
+{
+ uint32_t cu_divisor;
+ uint32_t cu_hash;
+ uint32_t cu_classid;
+ uint32_t cu_link;
+ struct nl_data * cu_pcnt;
+ struct nl_data * cu_selector;
+ struct nl_data * cu_act;
+ struct nl_data * cu_police;
+ char cu_indev[IFNAMSIZ];
+ int cu_mask;
+};
+
+struct rtnl_cgroup
+{
+ struct rtnl_ematch_tree *cg_ematch;
+ int cg_mask;
+};
+
+struct rtnl_fw
+{
+ uint32_t cf_classid;
+ struct nl_data * cf_act;
+ struct nl_data * cf_police;
+ char cf_indev[IFNAMSIZ];
+ int cf_mask;
+};
+
+struct rtnl_ematch
+{
+ uint16_t e_id;
+ uint16_t e_kind;
+ uint16_t e_flags;
+
+ struct nl_list_head e_childs;
+ struct nl_list_head e_list;
+ struct rtnl_ematch_ops *e_ops;
+
+ char e_data[0];
+};
+
+struct rtnl_ematch_tree
+{
+ uint16_t et_progid;
+ struct nl_list_head et_list;
+
+};
+
+struct rtnl_dsmark_qdisc
+{
+ uint16_t qdm_indices;
+ uint16_t qdm_default_index;
+ uint32_t qdm_set_tc_index;
+ uint32_t qdm_mask;
+};
+
+struct rtnl_dsmark_class
+{
+ uint8_t cdm_bmask;
+ uint8_t cdm_value;
+ uint32_t cdm_mask;
+};
+
+struct rtnl_fifo
+{
+ uint32_t qf_limit;
+ uint32_t qf_mask;
+};
+
+struct rtnl_prio
+{
+ uint32_t qp_bands;
+ uint8_t qp_priomap[TC_PRIO_MAX+1];
+ uint32_t qp_mask;
+};
+
+struct rtnl_tbf
+{
+ uint32_t qt_limit;
+ uint32_t qt_mpu;
+ struct rtnl_ratespec qt_rate;
+ uint32_t qt_rate_bucket;
+ uint32_t qt_rate_txtime;
+ struct rtnl_ratespec qt_peakrate;
+ uint32_t qt_peakrate_bucket;
+ uint32_t qt_peakrate_txtime;
+ uint32_t qt_mask;
+};
+
+struct rtnl_sfq
+{
+ uint32_t qs_quantum;
+ uint32_t qs_perturb;
+ uint32_t qs_limit;
+ uint32_t qs_divisor;
+ uint32_t qs_flows;
+ uint32_t qs_mask;
+};
+
+struct rtnl_netem_corr
+{
+ uint32_t nmc_delay;
+ uint32_t nmc_loss;
+ uint32_t nmc_duplicate;
+};
+
+struct rtnl_netem_reo
+{
+ uint32_t nmro_probability;
+ uint32_t nmro_correlation;
+};
+
+struct rtnl_netem_crpt
+{
+ uint32_t nmcr_probability;
+ uint32_t nmcr_correlation;
+};
+
+struct rtnl_netem_dist
+{
+ int16_t * dist_data;
+ size_t dist_size;
+};
+
+struct rtnl_netem
+{
+ uint32_t qnm_latency;
+ uint32_t qnm_limit;
+ uint32_t qnm_loss;
+ uint32_t qnm_gap;
+ uint32_t qnm_duplicate;
+ uint32_t qnm_jitter;
+ uint32_t qnm_mask;
+ struct rtnl_netem_corr qnm_corr;
+ struct rtnl_netem_reo qnm_ro;
+ struct rtnl_netem_crpt qnm_crpt;
+ struct rtnl_netem_dist qnm_dist;
+};
+
+struct rtnl_htb_qdisc
+{
+ uint32_t qh_rate2quantum;
+ uint32_t qh_defcls;
+ uint32_t qh_mask;
+};
+
+struct rtnl_htb_class
+{
+ uint32_t ch_prio;
+ uint32_t ch_mtu;
+ struct rtnl_ratespec ch_rate;
+ struct rtnl_ratespec ch_ceil;
+ uint32_t ch_rbuffer;
+ uint32_t ch_cbuffer;
+ uint32_t ch_quantum;
+ uint8_t ch_overhead;
+ uint8_t ch_mpu;
+ uint32_t ch_mask;
+};
+
+struct rtnl_cbq
+{
+ struct tc_cbq_lssopt cbq_lss;
+ struct tc_ratespec cbq_rate;
+ struct tc_cbq_wrropt cbq_wrr;
+ struct tc_cbq_ovl cbq_ovl;
+ struct tc_cbq_fopt cbq_fopt;
+ struct tc_cbq_police cbq_police;
+};
+
+struct rtnl_red
+{
+ uint32_t qr_limit;
+ uint32_t qr_qth_min;
+ uint32_t qr_qth_max;
+ uint8_t qr_flags;
+ uint8_t qr_wlog;
+ uint8_t qr_plog;
+ uint8_t qr_scell_log;
+ uint32_t qr_mask;
+};
+
+struct flnl_request
+{
+ NLHDR_COMMON
+
+ struct nl_addr * lr_addr;
+ uint32_t lr_fwmark;
+ uint8_t lr_tos;
+ uint8_t lr_scope;
+ uint8_t lr_table;
+};
+
+
+struct flnl_result
+{
+ NLHDR_COMMON
+
+ struct flnl_request * fr_req;
+ uint8_t fr_table_id;
+ uint8_t fr_prefixlen;
+ uint8_t fr_nh_sel;
+ uint8_t fr_type;
+ uint8_t fr_scope;
+ uint32_t fr_error;
+};
+
+#define GENL_OP_HAS_POLICY 1
+#define GENL_OP_HAS_DOIT 2
+#define GENL_OP_HAS_DUMPIT 4
+
+struct genl_family_op
+{
+ uint32_t o_id;
+ uint32_t o_flags;
+
+ struct nl_list_head o_list;
+};
+
+struct genl_family
+{
+ NLHDR_COMMON
+
+ uint16_t gf_id;
+ char gf_name[GENL_NAMSIZ];
+ uint32_t gf_version;
+ uint32_t gf_hdrsize;
+ uint32_t gf_maxattr;
+
+ struct nl_list_head gf_ops;
+};
+
+union nfnl_ct_proto
+{
+ struct {
+ uint16_t src;
+ uint16_t dst;
+ } port;
+ struct {
+ uint16_t id;
+ uint8_t type;
+ uint8_t code;
+ } icmp;
+};
+
+struct nfnl_ct_dir {
+ struct nl_addr * src;
+ struct nl_addr * dst;
+ union nfnl_ct_proto proto;
+ uint64_t packets;
+ uint64_t bytes;
+};
+
+union nfnl_ct_protoinfo {
+ struct {
+ uint8_t state;
+ } tcp;
+};
+
+struct nfnl_ct {
+ NLHDR_COMMON
+
+ uint8_t ct_family;
+ uint8_t ct_proto;
+ union nfnl_ct_protoinfo ct_protoinfo;
+
+ uint32_t ct_status;
+ uint32_t ct_status_mask;
+ uint32_t ct_timeout;
+ uint32_t ct_mark;
+ uint32_t ct_use;
+ uint32_t ct_id;
+
+ struct nfnl_ct_dir ct_orig;
+ struct nfnl_ct_dir ct_repl;
+};
+
+struct nfnl_log {
+ NLHDR_COMMON
+
+ uint16_t log_group;
+ uint8_t log_copy_mode;
+ uint32_t log_copy_range;
+ uint32_t log_flush_timeout;
+ uint32_t log_alloc_size;
+ uint32_t log_queue_threshold;
+ uint32_t log_flags;
+ uint32_t log_flag_mask;
+};
+
+struct nfnl_log_msg {
+ NLHDR_COMMON
+
+ uint8_t log_msg_family;
+ uint8_t log_msg_hook;
+ uint16_t log_msg_hwproto;
+ uint32_t log_msg_mark;
+ struct timeval log_msg_timestamp;
+ uint32_t log_msg_indev;
+ uint32_t log_msg_outdev;
+ uint32_t log_msg_physindev;
+ uint32_t log_msg_physoutdev;
+ uint8_t log_msg_hwaddr[8];
+ int log_msg_hwaddr_len;
+ void * log_msg_payload;
+ int log_msg_payload_len;
+ char * log_msg_prefix;
+ uint32_t log_msg_uid;
+ uint32_t log_msg_gid;
+ uint32_t log_msg_seq;
+ uint32_t log_msg_seq_global;
+};
+
+struct nfnl_queue {
+ NLHDR_COMMON
+
+ uint16_t queue_group;
+ uint32_t queue_maxlen;
+ uint32_t queue_copy_range;
+ uint8_t queue_copy_mode;
+};
+
+struct nfnl_queue_msg {
+ NLHDR_COMMON
+
+ uint16_t queue_msg_group;
+ uint8_t queue_msg_family;
+ uint8_t queue_msg_hook;
+ uint16_t queue_msg_hwproto;
+ uint32_t queue_msg_packetid;
+ uint32_t queue_msg_mark;
+ struct timeval queue_msg_timestamp;
+ uint32_t queue_msg_indev;
+ uint32_t queue_msg_outdev;
+ uint32_t queue_msg_physindev;
+ uint32_t queue_msg_physoutdev;
+ uint8_t queue_msg_hwaddr[8];
+ int queue_msg_hwaddr_len;
+ void * queue_msg_payload;
+ int queue_msg_payload_len;
+ uint32_t queue_msg_verdict;
+};
+
+#endif
diff --git a/netlink/addr.h b/netlink/addr.h
new file mode 100644
index 0000000..cc3d201
--- /dev/null
+++ b/netlink/addr.h
@@ -0,0 +1,69 @@
+/*
+ * netlink/addr.h Abstract Address
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_ADDR_H_
+#define NETLINK_ADDR_H_
+
+#include <netlink/netlink.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct nl_addr;
+
+/* Creation */
+extern struct nl_addr * nl_addr_alloc(size_t);
+extern struct nl_addr * nl_addr_alloc_attr(struct nlattr *, int);
+extern struct nl_addr * nl_addr_build(int, void *, size_t);
+extern int nl_addr_parse(const char *, int, struct nl_addr **);
+extern struct nl_addr * nl_addr_clone(struct nl_addr *);
+
+/* Destroyage */
+extern void nl_addr_destroy(struct nl_addr *);
+
+/* Usage Management */
+extern struct nl_addr * nl_addr_get(struct nl_addr *);
+extern void nl_addr_put(struct nl_addr *);
+extern int nl_addr_shared(struct nl_addr *);
+
+extern int nl_addr_cmp(struct nl_addr *, struct nl_addr *);
+extern int nl_addr_cmp_prefix(struct nl_addr *, struct nl_addr *);
+extern int nl_addr_iszero(struct nl_addr *);
+extern int nl_addr_valid(char *, int);
+extern int nl_addr_guess_family(struct nl_addr *);
+extern int nl_addr_fill_sockaddr(struct nl_addr *,
+ struct sockaddr *, socklen_t *);
+extern int nl_addr_info(struct nl_addr *, struct addrinfo **);
+extern int nl_addr_resolve(struct nl_addr *addr, char *host, size_t hostlen);
+
+/* Access Functions */
+extern void nl_addr_set_family(struct nl_addr *, int);
+extern int nl_addr_get_family(struct nl_addr *);
+extern int nl_addr_set_binary_addr(struct nl_addr *, void *,
+ size_t);
+extern void * nl_addr_get_binary_addr(struct nl_addr *);
+extern unsigned int nl_addr_get_len(struct nl_addr *);
+extern void nl_addr_set_prefixlen(struct nl_addr *, int);
+extern unsigned int nl_addr_get_prefixlen(struct nl_addr *);
+
+/* Address Family Translations */
+extern char * nl_af2str(int, char *, size_t);
+extern int nl_str2af(const char *);
+
+/* Translations to Strings */
+extern char * nl_addr2str(struct nl_addr *, char *, size_t);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/attr.h b/netlink/attr.h
new file mode 100644
index 0000000..8479c23
--- /dev/null
+++ b/netlink/attr.h
@@ -0,0 +1,283 @@
+/*
+ * netlink/attr.h Netlink Attributes
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_ATTR_H_
+#define NETLINK_ATTR_H_
+
+#include <netlink/netlink.h>
+#include <netlink/object.h>
+#include <netlink/addr.h>
+#include <netlink/data.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct nl_msg;
+
+/**
+ * @name Basic Attribute Data Types
+ * @{
+ */
+
+ /**
+ * @ingroup attr
+ * Basic attribute data types
+ *
+ * See \ref attr_datatypes for more details.
+ */
+enum {
+ NLA_UNSPEC, /**< Unspecified type, binary data chunk */
+ NLA_U8, /**< 8 bit integer */
+ NLA_U16, /**< 16 bit integer */
+ NLA_U32, /**< 32 bit integer */
+ NLA_U64, /**< 64 bit integer */
+ NLA_STRING, /**< NUL terminated character string */
+ NLA_FLAG, /**< Flag */
+ NLA_MSECS, /**< Micro seconds (64bit) */
+ NLA_NESTED, /**< Nested attributes */
+ __NLA_TYPE_MAX,
+};
+
+#define NLA_TYPE_MAX (__NLA_TYPE_MAX - 1)
+
+/** @} */
+
+/**
+ * @ingroup attr
+ * Attribute validation policy.
+ *
+ * See \ref attr_datatypes for more details.
+ */
+struct nla_policy {
+ /** Type of attribute or NLA_UNSPEC */
+ uint16_t type;
+
+ /** Minimal length of payload required */
+ uint16_t minlen;
+
+ /** Maximal length of payload allowed */
+ uint16_t maxlen;
+};
+
+/* Size calculations */
+extern int nla_attr_size(int payload);
+extern int nla_total_size(int payload);
+extern int nla_padlen(int payload);
+
+/* Attribute parsing */
+extern int nla_type(const struct nlattr *);
+extern void * nla_data(const struct nlattr *);
+extern int nla_len(const struct nlattr *);
+extern int nla_ok(const struct nlattr *, int);
+extern struct nlattr * nla_next(const struct nlattr *, int *);
+extern int nla_parse(struct nlattr **, int, struct nlattr *,
+ int, struct nla_policy *);
+extern int nla_validate(struct nlattr *, int, int,
+ struct nla_policy *);
+extern struct nlattr * nla_find(struct nlattr *, int, int);
+
+/* Helper Functions */
+extern int nla_memcpy(void *, struct nlattr *, int);
+extern size_t nla_strlcpy(char *, const struct nlattr *, size_t);
+extern int nla_memcmp(const struct nlattr *, const void *, size_t);
+extern int nla_strcmp(const struct nlattr *, const char *);
+
+/* Unspecific attribute */
+extern struct nlattr * nla_reserve(struct nl_msg *, int, int);
+extern int nla_put(struct nl_msg *, int, int, const void *);
+extern int nla_put_data(struct nl_msg *, int, struct nl_data *);
+extern int nla_put_addr(struct nl_msg *, int, struct nl_addr *);
+
+/* Integer attribute */
+extern uint8_t nla_get_u8(struct nlattr *);
+extern int nla_put_u8(struct nl_msg *, int, uint8_t);
+extern uint16_t nla_get_u16(struct nlattr *);
+extern int nla_put_u16(struct nl_msg *, int, uint16_t);
+extern uint32_t nla_get_u32(struct nlattr *);
+extern int nla_put_u32(struct nl_msg *, int, uint32_t);
+extern uint64_t nla_get_u64(struct nlattr *);
+extern int nla_put_u64(struct nl_msg *, int, uint64_t);
+
+/* String attribute */
+extern char * nla_get_string(struct nlattr *);
+extern char * nla_strdup(struct nlattr *);
+extern int nla_put_string(struct nl_msg *, int, const char *);
+
+/* Flag attribute */
+extern int nla_get_flag(struct nlattr *);
+extern int nla_put_flag(struct nl_msg *, int);
+
+/* Msec attribute */
+extern unsigned long nla_get_msecs(struct nlattr *);
+extern int nla_put_msecs(struct nl_msg *, int, unsigned long);
+
+/* Attribute nesting */
+extern int nla_put_nested(struct nl_msg *, int, struct nl_msg *);
+extern struct nlattr * nla_nest_start(struct nl_msg *, int);
+extern int nla_nest_end(struct nl_msg *, struct nlattr *);
+extern int nla_parse_nested(struct nlattr **, int, struct nlattr *,
+ struct nla_policy *);
+
+/**
+ * @name Attribute Construction (Exception Based)
+ * @{
+ */
+
+/**
+ * @ingroup attr
+ * Add unspecific attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg attrtype Attribute type.
+ * @arg attrlen Length of attribute payload.
+ * @arg data Head of attribute payload.
+ */
+#define NLA_PUT(msg, attrtype, attrlen, data) \
+ do { \
+ if (nla_put(msg, attrtype, attrlen, data) < 0) \
+ goto nla_put_failure; \
+ } while(0)
+
+/**
+ * @ingroup attr
+ * Add atomic type attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg type Atomic type.
+ * @arg attrtype Attribute type.
+ * @arg value Head of attribute payload.
+ */
+#define NLA_PUT_TYPE(msg, type, attrtype, value) \
+ do { \
+ type __tmp = value; \
+ NLA_PUT(msg, attrtype, sizeof(type), &__tmp); \
+ } while(0)
+
+/**
+ * Add 8 bit integer attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg attrtype Attribute type.
+ * @arg value Numeric value.
+ */
+#define NLA_PUT_U8(msg, attrtype, value) \
+ NLA_PUT_TYPE(msg, uint8_t, attrtype, value)
+
+/**
+ * Add 16 bit integer attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg attrtype Attribute type.
+ * @arg value Numeric value.
+ */
+#define NLA_PUT_U16(msg, attrtype, value) \
+ NLA_PUT_TYPE(msg, uint16_t, attrtype, value)
+
+/**
+ * Add 32 bit integer attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg attrtype Attribute type.
+ * @arg value Numeric value.
+ */
+#define NLA_PUT_U32(msg, attrtype, value) \
+ NLA_PUT_TYPE(msg, uint32_t, attrtype, value)
+
+/**
+ * Add 64 bit integer attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg attrtype Attribute type.
+ * @arg value Numeric value.
+ */
+#define NLA_PUT_U64(msg, attrtype, value) \
+ NLA_PUT_TYPE(msg, uint64_t, attrtype, value)
+
+/**
+ * Add string attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg attrtype Attribute type.
+ * @arg value NUL terminated character string.
+ */
+#define NLA_PUT_STRING(msg, attrtype, value) \
+ NLA_PUT(msg, attrtype, strlen(value) + 1, value)
+
+/**
+ * Add flag attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg attrtype Attribute type.
+ */
+#define NLA_PUT_FLAG(msg, attrtype) \
+ NLA_PUT(msg, attrtype, 0, NULL)
+
+/**
+ * Add msecs attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg attrtype Attribute type.
+ * @arg msecs Numeric value in micro seconds.
+ */
+#define NLA_PUT_MSECS(msg, attrtype, msecs) \
+ NLA_PUT_U64(msg, attrtype, msecs)
+
+/**
+ * Add address attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg attrtype Attribute type.
+ * @arg addr Abstract address object.
+ */
+#define NLA_PUT_ADDR(msg, attrtype, addr) \
+ NLA_PUT(msg, attrtype, nl_addr_get_len(addr), \
+ nl_addr_get_binary_addr(addr))
+
+/**
+ * Add abstract data attribute to netlink message.
+ * @arg msg Netlink message.
+ * @arg attrtype Attribute type.
+ * @arg data Abstract data object.
+ */
+#define NLA_PUT_DATA(msg, attrtype, data) \
+ NLA_PUT(msg, attrtype, nl_data_get_size(data), \
+ nl_data_get(data))
+
+/** @} */
+
+/**
+ * @name Iterators
+ * @{
+ */
+
+/**
+ * @ingroup attr
+ * Iterate over a stream of attributes
+ * @arg pos loop counter, set to current attribute
+ * @arg head head of attribute stream
+ * @arg len length of attribute stream
+ * @arg rem initialized to len, holds bytes currently remaining in stream
+ */
+#define nla_for_each_attr(pos, head, len, rem) \
+ for (pos = head, rem = len; \
+ nla_ok(pos, rem); \
+ pos = nla_next(pos, &(rem)))
+
+/**
+ * @ingroup attr
+ * Iterate over a stream of nested attributes
+ * @arg pos loop counter, set to current attribute
+ * @arg nla attribute containing the nested attributes
+ * @arg rem initialized to len, holds bytes currently remaining in stream
+ */
+#define nla_for_each_nested(pos, nla, rem) \
+ for (pos = nla_data(nla), rem = nla_len(nla); \
+ nla_ok(pos, rem); \
+ pos = nla_next(pos, &(rem)))
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/cache-api.h b/netlink/cache-api.h
new file mode 100644
index 0000000..22fc449
--- /dev/null
+++ b/netlink/cache-api.h
@@ -0,0 +1,199 @@
+/*
+ * netlink/cache-api.h Caching API
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_CACHE_API_H_
+#define NETLINK_CACHE_API_H_
+
+#include <netlink/netlink.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @ingroup cache
+ * @defgroup cache_api Cache Implementation
+ * @brief
+ *
+ * @par 1) Cache Definition
+ * @code
+ * struct nl_cache_ops my_cache_ops = {
+ * .co_name = "route/link",
+ * .co_protocol = NETLINK_ROUTE,
+ * .co_hdrsize = sizeof(struct ifinfomsg),
+ * .co_obj_ops = &my_obj_ops,
+ * };
+ * @endcode
+ *
+ * @par 2)
+ * @code
+ * // The simplest way to fill a cache is by providing a request-update
+ * // function which must trigger a complete dump on the kernel-side of
+ * // whatever the cache covers.
+ * static int my_request_update(struct nl_cache *cache,
+ * struct nl_sock *socket)
+ * {
+ * // In this example, we request a full dump of the interface table
+ * return nl_rtgen_request(socket, RTM_GETLINK, AF_UNSPEC, NLM_F_DUMP);
+ * }
+ *
+ * // The resulting netlink messages sent back will be fed into a message
+ * // parser one at a time. The message parser has to extract all relevant
+ * // information from the message and create an object reflecting the
+ * // contents of the message and pass it on to the parser callback function
+ * // provide which will add the object to the cache.
+ * static int my_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who,
+ * struct nlmsghdr *nlh, struct nl_parser_param *pp)
+ * {
+ * struct my_obj *obj;
+ *
+ * obj = my_obj_alloc();
+ * obj->ce_msgtype = nlh->nlmsg_type;
+ *
+ * // Parse the netlink message and continue creating the object.
+ *
+ * err = pp->pp_cb((struct nl_object *) obj, pp);
+ * if (err < 0)
+ * goto errout;
+ * }
+ *
+ * struct nl_cache_ops my_cache_ops = {
+ * ...
+ * .co_request_update = my_request_update,
+ * .co_msg_parser = my_msg_parser,
+ * };
+ * @endcode
+ *
+ * @par 3) Notification based Updates
+ * @code
+ * // Caches can be kept up-to-date based on notifications if the kernel
+ * // sends out notifications whenever an object is added/removed/changed.
+ * //
+ * // It is trivial to support this, first a list of groups needs to be
+ * // defined which are required to join in order to receive all necessary
+ * // notifications. The groups are separated by address family to support
+ * // the common situation where a separate group is used for each address
+ * // family. If there is only one group, simply specify AF_UNSPEC.
+ * static struct nl_af_group addr_groups[] = {
+ * { AF_INET, RTNLGRP_IPV4_IFADDR },
+ * { AF_INET6, RTNLGRP_IPV6_IFADDR },
+ * { END_OF_GROUP_LIST },
+ * };
+ *
+ * // In order for the caching system to know the meaning of each message
+ * // type it requires a table which maps each supported message type to
+ * // a cache action, e.g. RTM_NEWADDR means address has been added or
+ * // updated, RTM_DELADDR means address has been removed.
+ * static struct nl_cache_ops rtnl_addr_ops = {
+ * ...
+ * .co_msgtypes = {
+ * { RTM_NEWADDR, NL_ACT_NEW, "new" },
+ * { RTM_DELADDR, NL_ACT_DEL, "del" },
+ * { RTM_GETADDR, NL_ACT_GET, "get" },
+ * END_OF_MSGTYPES_LIST,
+ * },
+ * .co_groups = addr_groups,
+ * };
+ *
+ * // It is now possible to keep the cache up-to-date using the cache manager.
+ * @endcode
+ * @{
+ */
+
+enum {
+ NL_ACT_UNSPEC,
+ NL_ACT_NEW,
+ NL_ACT_DEL,
+ NL_ACT_GET,
+ NL_ACT_SET,
+ NL_ACT_CHANGE,
+ __NL_ACT_MAX,
+};
+
+#define NL_ACT_MAX (__NL_ACT_MAX - 1)
+
+#define END_OF_MSGTYPES_LIST { -1, -1, NULL }
+
+/**
+ * Message type to cache action association
+ */
+struct nl_msgtype
+{
+ /** Netlink message type */
+ int mt_id;
+
+ /** Cache action to take */
+ int mt_act;
+
+ /** Name of operation for human-readable printing */
+ char * mt_name;
+};
+
+/**
+ * Address family to netlink group association
+ */
+struct nl_af_group
+{
+ /** Address family */
+ int ag_family;
+
+ /** Netlink group identifier */
+ int ag_group;
+};
+
+#define END_OF_GROUP_LIST AF_UNSPEC, 0
+
+struct nl_parser_param
+{
+ int (*pp_cb)(struct nl_object *, struct nl_parser_param *);
+ void * pp_arg;
+};
+
+/**
+ * Cache Operations
+ */
+struct nl_cache_ops
+{
+ char * co_name;
+
+ int co_hdrsize;
+ int co_protocol;
+ struct nl_af_group * co_groups;
+
+ /**
+ * Called whenever an update of the cache is required. Must send
+ * a request message to the kernel requesting a complete dump.
+ */
+ int (*co_request_update)(struct nl_cache *, struct nl_sock *);
+
+ /**
+ * Called whenever a message was received that needs to be parsed.
+ * Must parse the message and call the paser callback function
+ * (nl_parser_param) provided via the argument.
+ */
+ int (*co_msg_parser)(struct nl_cache_ops *, struct sockaddr_nl *,
+ struct nlmsghdr *, struct nl_parser_param *);
+
+ struct nl_object_ops * co_obj_ops;
+
+ struct nl_cache_ops *co_next;
+ struct nl_cache *co_major_cache;
+ struct genl_ops * co_genl;
+ struct nl_msgtype co_msgtypes[];
+};
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/cache.h b/netlink/cache.h
new file mode 100644
index 0000000..c752920
--- /dev/null
+++ b/netlink/cache.h
@@ -0,0 +1,129 @@
+/*
+ * netlink/cache.h Caching Module
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_CACHE_H_
+#define NETLINK_CACHE_H_
+
+#include <netlink/netlink.h>
+#include <netlink/msg.h>
+#include <netlink/utils.h>
+#include <netlink/object.h>
+#include <netlink/cache-api.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct nl_cache;
+
+typedef void (*change_func_t)(struct nl_cache *, struct nl_object *, int, void *);
+
+/* Access Functions */
+extern int nl_cache_nitems(struct nl_cache *);
+extern int nl_cache_nitems_filter(struct nl_cache *,
+ struct nl_object *);
+extern struct nl_cache_ops * nl_cache_get_ops(struct nl_cache *);
+extern struct nl_object * nl_cache_get_first(struct nl_cache *);
+extern struct nl_object * nl_cache_get_last(struct nl_cache *);
+extern struct nl_object * nl_cache_get_next(struct nl_object *);
+extern struct nl_object * nl_cache_get_prev(struct nl_object *);
+
+extern struct nl_cache * nl_cache_alloc(struct nl_cache_ops *);
+extern int nl_cache_alloc_and_fill(struct nl_cache_ops *,
+ struct nl_sock *,
+ struct nl_cache **);
+extern int nl_cache_alloc_name(const char *,
+ struct nl_cache **);
+extern struct nl_cache * nl_cache_subset(struct nl_cache *,
+ struct nl_object *);
+extern void nl_cache_clear(struct nl_cache *);
+extern void nl_cache_free(struct nl_cache *);
+
+/* Cache modification */
+extern int nl_cache_add(struct nl_cache *,
+ struct nl_object *);
+extern int nl_cache_parse_and_add(struct nl_cache *,
+ struct nl_msg *);
+extern void nl_cache_remove(struct nl_object *);
+extern int nl_cache_refill(struct nl_sock *,
+ struct nl_cache *);
+extern int nl_cache_pickup(struct nl_sock *,
+ struct nl_cache *);
+extern int nl_cache_resync(struct nl_sock *,
+ struct nl_cache *,
+ change_func_t,
+ void *);
+extern int nl_cache_include(struct nl_cache *,
+ struct nl_object *,
+ change_func_t,
+ void *);
+
+/* General */
+extern int nl_cache_is_empty(struct nl_cache *);
+extern void nl_cache_mark_all(struct nl_cache *);
+
+/* Dumping */
+extern void nl_cache_dump(struct nl_cache *,
+ struct nl_dump_params *);
+extern void nl_cache_dump_filter(struct nl_cache *,
+ struct nl_dump_params *,
+ struct nl_object *);
+
+/* Iterators */
+extern void nl_cache_foreach(struct nl_cache *,
+ void (*cb)(struct nl_object *,
+ void *),
+ void *arg);
+extern void nl_cache_foreach_filter(struct nl_cache *,
+ struct nl_object *,
+ void (*cb)(struct
+ nl_object *,
+ void *),
+ void *arg);
+
+/* --- cache management --- */
+
+/* Cache type management */
+extern struct nl_cache_ops * nl_cache_ops_lookup(const char *);
+extern struct nl_cache_ops * nl_cache_ops_associate(int, int);
+extern struct nl_msgtype * nl_msgtype_lookup(struct nl_cache_ops *, int);
+extern void nl_cache_ops_foreach(void (*cb)(struct nl_cache_ops *, void *), void *);
+extern int nl_cache_mngt_register(struct nl_cache_ops *);
+extern int nl_cache_mngt_unregister(struct nl_cache_ops *);
+
+/* Global cache provisioning/requiring */
+extern void nl_cache_mngt_provide(struct nl_cache *);
+extern void nl_cache_mngt_unprovide(struct nl_cache *);
+extern struct nl_cache * nl_cache_mngt_require(const char *);
+
+struct nl_cache_mngr;
+
+#define NL_AUTO_PROVIDE 1
+
+extern int nl_cache_mngr_alloc(struct nl_sock *,
+ int, int,
+ struct nl_cache_mngr **);
+extern int nl_cache_mngr_add(struct nl_cache_mngr *,
+ const char *,
+ change_func_t,
+ void *,
+ struct nl_cache **);
+extern int nl_cache_mngr_get_fd(struct nl_cache_mngr *);
+extern int nl_cache_mngr_poll(struct nl_cache_mngr *,
+ int);
+extern int nl_cache_mngr_data_ready(struct nl_cache_mngr *);
+extern void nl_cache_mngr_free(struct nl_cache_mngr *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/cli/utils.h b/netlink/cli/utils.h
new file mode 100644
index 0000000..2a23208
--- /dev/null
+++ b/netlink/cli/utils.h
@@ -0,0 +1,80 @@
+/*
+ * src/utils.h Utilities
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef __NETLINK_CLI_UTILS_H_
+#define __NETLINK_CLI_UTILS_H_
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <limits.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <stdint.h>
+#include <ctype.h>
+#include <getopt.h>
+#include <dlfcn.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <netlink/netlink.h>
+#include <netlink/utils.h>
+#include <netlink/addr.h>
+#include <netlink/list.h>
+#include <netlink/route/rtnl.h>
+#include <netlink/route/link.h>
+#include <netlink/route/addr.h>
+#include <netlink/route/neighbour.h>
+#include <netlink/route/neightbl.h>
+#include <netlink/route/route.h>
+#include <netlink/route/rule.h>
+#include <netlink/route/qdisc.h>
+#include <netlink/route/class.h>
+#include <netlink/route/classifier.h>
+#include <netlink/route/cls/ematch.h>
+#include <netlink/fib_lookup/lookup.h>
+#include <netlink/fib_lookup/request.h>
+#include <netlink/genl/genl.h>
+#include <netlink/genl/ctrl.h>
+#include <netlink/genl/mngt.h>
+#include <netlink/netfilter/ct.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef __init
+#define __init __attribute__((constructor))
+#endif
+
+#ifndef __exit
+#define __exit __attribute__((destructor))
+#endif
+
+extern uint32_t nl_cli_parse_u32(const char *);
+extern void nl_cli_print_version(void);
+extern void nl_cli_fatal(int, const char *, ...);
+extern struct nl_addr * nl_cli_addr_parse(const char *, int);
+extern int nl_cli_connect(struct nl_sock *, int);
+extern struct nl_sock * nl_cli_alloc_socket(void);
+extern int nl_cli_parse_dumptype(const char *);
+extern int nl_cli_confirm(struct nl_object *,
+ struct nl_dump_params *, int);
+
+extern struct nl_cache *nl_cli_alloc_cache(struct nl_sock *, const char *,
+ int (*ac)(struct nl_sock *, struct nl_cache **));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/data.h b/netlink/data.h
new file mode 100644
index 0000000..071159e
--- /dev/null
+++ b/netlink/data.h
@@ -0,0 +1,41 @@
+/*
+ * netlink/data.h Abstract Data
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_DATA_H_
+#define NETLINK_DATA_H_
+
+#include <netlink/netlink.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct nl_data;
+
+/* General */
+extern struct nl_data * nl_data_alloc(void *, size_t);
+extern struct nl_data * nl_data_alloc_attr(struct nlattr *);
+extern struct nl_data * nl_data_clone(struct nl_data *);
+extern int nl_data_append(struct nl_data *, void *, size_t);
+extern void nl_data_free(struct nl_data *);
+
+/* Access Functions */
+extern void * nl_data_get(struct nl_data *);
+extern size_t nl_data_get_size(struct nl_data *);
+
+/* Misc */
+extern int nl_data_cmp(struct nl_data *, struct nl_data *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/errno.h b/netlink/errno.h
new file mode 100644
index 0000000..c8a376e
--- /dev/null
+++ b/netlink/errno.h
@@ -0,0 +1,60 @@
+/*
+ * netlink/errno.h Error Numbers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_ERRNO_H_
+#define NETLINK_ERRNO_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NLE_SUCCESS 0
+#define NLE_FAILURE 1
+#define NLE_INTR 2
+#define NLE_BAD_SOCK 3
+#define NLE_AGAIN 4
+#define NLE_NOMEM 5
+#define NLE_EXIST 6
+#define NLE_INVAL 7
+#define NLE_RANGE 8
+#define NLE_MSGSIZE 9
+#define NLE_OPNOTSUPP 10
+#define NLE_AF_NOSUPPORT 11
+#define NLE_OBJ_NOTFOUND 12
+#define NLE_NOATTR 13
+#define NLE_MISSING_ATTR 14
+#define NLE_AF_MISMATCH 15
+#define NLE_SEQ_MISMATCH 16
+#define NLE_MSG_OVERFLOW 17
+#define NLE_MSG_TRUNC 18
+#define NLE_NOADDR 19
+#define NLE_SRCRT_NOSUPPORT 20
+#define NLE_MSG_TOOSHORT 21
+#define NLE_MSGTYPE_NOSUPPORT 22
+#define NLE_OBJ_MISMATCH 23
+#define NLE_NOCACHE 24
+#define NLE_BUSY 25
+#define NLE_PROTO_MISMATCH 26
+#define NLE_NOACCESS 27
+#define NLE_PERM 28
+#define NLE_PKTLOC_FILE 29
+
+#define NLE_MAX NLE_PKTLOC_FILE
+
+extern const char * nl_geterror(int);
+extern void nl_perror(int, const char *);
+extern int nl_syserr2nlerr(int);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/fib_lookup/lookup.h b/netlink/fib_lookup/lookup.h
new file mode 100644
index 0000000..8bf27b8
--- /dev/null
+++ b/netlink/fib_lookup/lookup.h
@@ -0,0 +1,42 @@
+/*
+ * netlink/fib_lookup/fib_lookup.h FIB Lookup
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_FIB_LOOKUP_H_
+#define NETLINK_FIB_LOOKUP_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/addr.h>
+#include <netlink/fib_lookup/request.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct flnl_result;
+
+extern struct flnl_result * flnl_result_alloc(void);
+extern void flnl_result_put(struct flnl_result *);
+
+extern struct nl_cache * flnl_result_alloc_cache(void);
+
+extern int flnl_lookup_build_request(struct flnl_request *,
+ int,
+ struct nl_msg **);
+extern int flnl_lookup(struct nl_sock *,
+ struct flnl_request *,
+ struct nl_cache *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/fib_lookup/request.h b/netlink/fib_lookup/request.h
new file mode 100644
index 0000000..60e8820
--- /dev/null
+++ b/netlink/fib_lookup/request.h
@@ -0,0 +1,51 @@
+/*
+ * netlink/fib_lookup/request.h FIB Lookup Request
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_FIB_LOOKUP_REQUEST_H_
+#define NETLINK_FIB_LOOKUP_REQUEST_H_
+
+#include <netlink/netlink.h>
+#include <netlink/addr.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct flnl_request;
+
+#define REQUEST_CAST(ptr) ((struct flnl_request *) (ptr))
+
+extern struct flnl_request * flnl_request_alloc(void);
+
+extern void flnl_request_set_fwmark(struct flnl_request *,
+ uint64_t);
+extern uint64_t flnl_request_get_fwmark(struct flnl_request *);
+extern void flnl_request_set_tos(struct flnl_request *,
+ int);
+extern int flnl_request_get_tos(struct flnl_request *);
+extern void flnl_request_set_scope(struct flnl_request *,
+ int);
+extern int flnl_request_get_scope(struct flnl_request *);
+extern void flnl_request_set_table(struct flnl_request *,
+ int);
+extern int flnl_request_get_table(struct flnl_request *);
+extern int flnl_request_set_addr(struct flnl_request *,
+ struct nl_addr *);
+extern struct nl_addr * flnl_request_get_addr(struct flnl_request *);
+
+extern int flnl_request_cmp(struct flnl_request *,
+ struct flnl_request *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/genl/ctrl.h b/netlink/genl/ctrl.h
new file mode 100644
index 0000000..1ae62f4
--- /dev/null
+++ b/netlink/genl/ctrl.h
@@ -0,0 +1,37 @@
+/*
+ * netlink/genl/ctrl.h Generic Netlink Controller
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_GENL_CTRL_H_
+#define NETLINK_GENL_CTRL_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/addr.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct genl_family;
+
+extern int genl_ctrl_alloc_cache(struct nl_sock *,
+ struct nl_cache **);
+extern struct genl_family * genl_ctrl_search(struct nl_cache *, int);
+extern struct genl_family * genl_ctrl_search_by_name(struct nl_cache *,
+ const char *);
+extern int genl_ctrl_resolve(struct nl_sock *,
+ const char *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/genl/family.h b/netlink/genl/family.h
new file mode 100644
index 0000000..74319e5
--- /dev/null
+++ b/netlink/genl/family.h
@@ -0,0 +1,50 @@
+/*
+ * netlink/genl/family.h Generic Netlink Family
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_GENL_FAMILY_H_
+#define NETLINK_GENL_FAMILY_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct genl_family;
+
+extern struct genl_family * genl_family_alloc(void);
+extern void genl_family_put(struct genl_family *);
+
+extern unsigned int genl_family_get_id(struct genl_family *);
+extern void genl_family_set_id(struct genl_family *,
+ unsigned int);
+extern char * genl_family_get_name(struct genl_family *);
+extern void genl_family_set_name(struct genl_family *,
+ const char *name);
+extern uint8_t genl_family_get_version(struct genl_family *);
+extern void genl_family_set_version(struct genl_family *,
+ uint8_t);
+extern uint32_t genl_family_get_hdrsize(struct genl_family *);
+extern void genl_family_set_hdrsize(struct genl_family *,
+ uint32_t);
+extern uint32_t genl_family_get_maxattr(struct genl_family *);
+extern void genl_family_set_maxattr(struct genl_family *,
+ uint32_t);
+
+extern int genl_family_add_op(struct genl_family *,
+ int, int);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/genl/genl.h b/netlink/genl/genl.h
new file mode 100644
index 0000000..3f3340c
--- /dev/null
+++ b/netlink/genl/genl.h
@@ -0,0 +1,47 @@
+/*
+ * netlink/genl/genl.h Generic Netlink
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_GENL_H_
+#define NETLINK_GENL_H_
+
+#include <netlink/netlink.h>
+#include <netlink/msg.h>
+#include <netlink/attr.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int genl_connect(struct nl_sock *);
+
+extern int genl_send_simple(struct nl_sock *, int, int,
+ int, int);
+
+extern void * genlmsg_put(struct nl_msg *, uint32_t, uint32_t,
+ int, int, int, uint8_t, uint8_t);
+
+extern int genlmsg_valid_hdr(struct nlmsghdr *, int);
+extern int genlmsg_validate(struct nlmsghdr *, int, int,
+ struct nla_policy *);
+extern int genlmsg_parse(struct nlmsghdr *, int, struct nlattr **,
+ int, struct nla_policy *);
+extern void * genlmsg_data(const struct genlmsghdr *);
+extern int genlmsg_len(const struct genlmsghdr *);
+extern struct nlattr * genlmsg_attrdata(const struct genlmsghdr *, int);
+extern int genlmsg_attrlen(const struct genlmsghdr *, int);
+
+extern char * genl_op2name(int, int, char *, size_t);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/genl/mngt.h b/netlink/genl/mngt.h
new file mode 100644
index 0000000..8b0244f
--- /dev/null
+++ b/netlink/genl/mngt.h
@@ -0,0 +1,87 @@
+/*
+ * netlink/genl/mngt.h Generic Netlink Management
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_GENL_MNGT_H_
+#define NETLINK_GENL_MNGT_H_
+
+#include <netlink/netlink.h>
+#include <netlink/attr.h>
+#include <netlink/list.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct nl_cache_ops;
+
+struct genl_info
+{
+ struct sockaddr_nl * who;
+ struct nlmsghdr * nlh;
+ struct genlmsghdr * genlhdr;
+ void * userhdr;
+ struct nlattr ** attrs;
+};
+
+/**
+ * @ingroup genl_mngt
+ * Generic Netlink Command
+ */
+struct genl_cmd
+{
+ /** Unique command identifier */
+ int c_id;
+
+ /** Name/description of command */
+ char * c_name;
+
+ /**
+ * Maximum attribute identifier, must be provided if
+ * a message parser is available.
+ */
+ int c_maxattr;
+
+ int (*c_msg_parser)(struct nl_cache_ops *,
+ struct genl_cmd *,
+ struct genl_info *, void *);
+
+ /**
+ * Attribute validation policy (optional)
+ */
+ struct nla_policy * c_attr_policy;
+};
+
+/**
+ * @ingroup genl_mngt
+ * Generic Netlink Operations
+ */
+struct genl_ops
+{
+ int o_family;
+ int o_id;
+ char * o_name;
+ struct nl_cache_ops * o_cache_ops;
+ struct genl_cmd * o_cmds;
+ int o_ncmds;
+
+ /* linked list of all genl cache operations */
+ struct nl_list_head o_list;
+};
+
+
+extern int genl_register(struct nl_cache_ops *);
+extern void genl_unregister(struct nl_cache_ops *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/handlers.h b/netlink/handlers.h
new file mode 100644
index 0000000..f373f58
--- /dev/null
+++ b/netlink/handlers.h
@@ -0,0 +1,144 @@
+/*
+ * netlink/handlers.c default netlink message handlers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_HANDLERS_H_
+#define NETLINK_HANDLERS_H_
+
+#include <stdio.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <netlink/netlink-compat.h>
+#include <netlink/netlink-kernel.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct nl_cb;
+struct nl_sock;
+struct nl_msg;
+struct ucred;
+
+/**
+ * @name Callback Typedefs
+ * @{
+ */
+
+/**
+ * nl_recvmsgs() callback for message processing customization
+ * @ingroup cb
+ * @arg msg netlink message being processed
+ * @arg arg argument passwd on through caller
+ */
+typedef int (*nl_recvmsg_msg_cb_t)(struct nl_msg *msg, void *arg);
+
+/**
+ * nl_recvmsgs() callback for error message processing customization
+ * @ingroup cb
+ * @arg nla netlink address of the peer
+ * @arg nlerr netlink error message being processed
+ * @arg arg argument passed on through caller
+ */
+typedef int (*nl_recvmsg_err_cb_t)(struct sockaddr_nl *nla,
+ struct nlmsgerr *nlerr, void *arg);
+
+/** @} */
+
+/**
+ * Callback actions
+ * @ingroup cb
+ */
+enum nl_cb_action {
+ /** Proceed with wathever would come next */
+ NL_OK,
+ /** Skip this message */
+ NL_SKIP,
+ /** Stop parsing altogether and discard remaining messages */
+ NL_STOP,
+};
+
+/**
+ * Callback kinds
+ * @ingroup cb
+ */
+enum nl_cb_kind {
+ /** Default handlers (quiet) */
+ NL_CB_DEFAULT,
+ /** Verbose default handlers (error messages printed) */
+ NL_CB_VERBOSE,
+ /** Debug handlers for debugging */
+ NL_CB_DEBUG,
+ /** Customized handler specified by the user */
+ NL_CB_CUSTOM,
+ __NL_CB_KIND_MAX,
+};
+
+#define NL_CB_KIND_MAX (__NL_CB_KIND_MAX - 1)
+
+/**
+ * Callback types
+ * @ingroup cb
+ */
+enum nl_cb_type {
+ /** Message is valid */
+ NL_CB_VALID,
+ /** Last message in a series of multi part messages received */
+ NL_CB_FINISH,
+ /** Report received that data was lost */
+ NL_CB_OVERRUN,
+ /** Message wants to be skipped */
+ NL_CB_SKIPPED,
+ /** Message is an acknowledge */
+ NL_CB_ACK,
+ /** Called for every message received */
+ NL_CB_MSG_IN,
+ /** Called for every message sent out except for nl_sendto() */
+ NL_CB_MSG_OUT,
+ /** Message is malformed and invalid */
+ NL_CB_INVALID,
+ /** Called instead of internal sequence number checking */
+ NL_CB_SEQ_CHECK,
+ /** Sending of an acknowledge message has been requested */
+ NL_CB_SEND_ACK,
+ __NL_CB_TYPE_MAX,
+};
+
+#define NL_CB_TYPE_MAX (__NL_CB_TYPE_MAX - 1)
+
+extern struct nl_cb * nl_cb_alloc(enum nl_cb_kind);
+extern struct nl_cb * nl_cb_clone(struct nl_cb *);
+extern struct nl_cb * nl_cb_get(struct nl_cb *);
+extern void nl_cb_put(struct nl_cb *);
+
+extern int nl_cb_set(struct nl_cb *, enum nl_cb_type, enum nl_cb_kind,
+ nl_recvmsg_msg_cb_t, void *);
+extern int nl_cb_set_all(struct nl_cb *, enum nl_cb_kind,
+ nl_recvmsg_msg_cb_t, void *);
+extern int nl_cb_err(struct nl_cb *, enum nl_cb_kind, nl_recvmsg_err_cb_t,
+ void *);
+
+extern void nl_cb_overwrite_recvmsgs(struct nl_cb *,
+ int (*func)(struct nl_sock *,
+ struct nl_cb *));
+extern void nl_cb_overwrite_recv(struct nl_cb *,
+ int (*func)(struct nl_sock *,
+ struct sockaddr_nl *,
+ unsigned char **,
+ struct ucred **));
+extern void nl_cb_overwrite_send(struct nl_cb *,
+ int (*func)(struct nl_sock *,
+ struct nl_msg *));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/list.h b/netlink/list.h
new file mode 100644
index 0000000..28712ed
--- /dev/null
+++ b/netlink/list.h
@@ -0,0 +1,93 @@
+/*
+ * netlink/list.h Netlink List Utilities
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_LIST_H_
+#define NETLINK_LIST_H_
+
+struct nl_list_head
+{
+ struct nl_list_head * next;
+ struct nl_list_head * prev;
+};
+
+static inline void NL_INIT_LIST_HEAD(struct nl_list_head *list)
+{
+ list->next = list;
+ list->prev = list;
+}
+
+static inline void __nl_list_add(struct nl_list_head *obj,
+ struct nl_list_head *prev,
+ struct nl_list_head *next)
+{
+ prev->next = obj;
+ obj->prev = prev;
+ next->prev = obj;
+ obj->next = next;
+}
+
+static inline void nl_list_add_tail(struct nl_list_head *obj,
+ struct nl_list_head *head)
+{
+ __nl_list_add(obj, head->prev, head);
+}
+
+static inline void nl_list_add_head(struct nl_list_head *obj,
+ struct nl_list_head *head)
+{
+ __nl_list_add(obj, head, head->next);
+}
+
+static inline void nl_list_del(struct nl_list_head *obj)
+{
+ obj->next->prev = obj->prev;
+ obj->prev->next = obj->next;
+}
+
+static inline int nl_list_empty(struct nl_list_head *head)
+{
+ return head->next == head;
+}
+
+#define nl_container_of(ptr, type, member) ({ \
+ const typeof( ((type *)0)->member ) *__mptr = (ptr); \
+ (type *)( (char *)__mptr - ((size_t) &((type *)0)->member));})
+
+#define nl_list_entry(ptr, type, member) \
+ nl_container_of(ptr, type, member)
+
+#define nl_list_at_tail(pos, head, member) \
+ ((pos)->member.next == (head))
+
+#define nl_list_at_head(pos, head, member) \
+ ((pos)->member.prev == (head))
+
+#define NL_LIST_HEAD(name) \
+ struct nl_list_head name = { &(name), &(name) }
+
+#define nl_list_first_entry(head, type, member) \
+ nl_list_entry((head)->next, type, member)
+
+#define nl_list_for_each_entry(pos, head, member) \
+ for (pos = nl_list_entry((head)->next, typeof(*pos), member); \
+ &(pos)->member != (head); \
+ (pos) = nl_list_entry((pos)->member.next, typeof(*(pos)), member))
+
+#define nl_list_for_each_entry_safe(pos, n, head, member) \
+ for (pos = nl_list_entry((head)->next, typeof(*pos), member), \
+ n = nl_list_entry(pos->member.next, typeof(*pos), member); \
+ &(pos)->member != (head); \
+ pos = n, n = nl_list_entry(n->member.next, typeof(*n), member))
+
+#define nl_init_list_head(head) \
+ do { (head)->next = (head); (head)->prev = (head); } while (0)
+
+#endif
diff --git a/netlink/msg.h b/netlink/msg.h
new file mode 100644
index 0000000..e9be456
--- /dev/null
+++ b/netlink/msg.h
@@ -0,0 +1,145 @@
+/*
+ * netlink/msg.c Netlink Messages Interface
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_MSG_H_
+#define NETLINK_MSG_H_
+
+#include <netlink/netlink.h>
+#include <netlink/object.h>
+#include <netlink/attr.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define NL_DONTPAD 0
+
+/**
+ * @ingroup msg
+ * @brief
+ * Will cause the netlink pid to be set to the pid assigned to
+ * the netlink handle (socket) just before sending the message off.
+ * @note Requires the use of nl_send_auto_complete()!
+ */
+#define NL_AUTO_PID 0
+
+/**
+ * @ingroup msg
+ * @brief
+ * May be used to refer to a sequence number which should be
+ * automatically set just before sending the message off.
+ * @note Requires the use of nl_send_auto_complete()!
+ */
+#define NL_AUTO_SEQ 0
+
+struct nl_msg;
+struct nl_tree;
+struct ucred;
+
+/* size calculations */
+extern int nlmsg_msg_size(int);
+extern int nlmsg_total_size(int);
+extern int nlmsg_padlen(int);
+
+/* payload access */
+extern void * nlmsg_data(const struct nlmsghdr *);
+extern int nlmsg_datalen(const struct nlmsghdr *);
+extern int nlmsg_len(const struct nlmsghdr *);
+extern void * nlmsg_tail(const struct nlmsghdr *);
+
+/* attribute access */
+extern struct nlattr * nlmsg_attrdata(const struct nlmsghdr *, int);
+extern int nlmsg_attrlen(const struct nlmsghdr *, int);
+
+/* message parsing */
+extern int nlmsg_valid_hdr(const struct nlmsghdr *, int);
+extern int nlmsg_ok(const struct nlmsghdr *, int);
+extern struct nlmsghdr * nlmsg_next(struct nlmsghdr *, int *);
+extern int nlmsg_parse(struct nlmsghdr *, int, struct nlattr **,
+ int, struct nla_policy *);
+extern struct nlattr * nlmsg_find_attr(struct nlmsghdr *, int, int);
+extern int nlmsg_validate(struct nlmsghdr *, int, int,
+ struct nla_policy *);
+
+extern struct nl_msg * nlmsg_alloc(void);
+extern struct nl_msg * nlmsg_alloc_size(size_t);
+extern struct nl_msg * nlmsg_alloc_simple(int, int);
+extern void nlmsg_set_default_size(size_t);
+extern struct nl_msg * nlmsg_inherit(struct nlmsghdr *);
+extern struct nl_msg * nlmsg_convert(struct nlmsghdr *);
+extern void * nlmsg_reserve(struct nl_msg *, size_t, int);
+extern int nlmsg_append(struct nl_msg *, void *, size_t, int);
+extern int nlmsg_expand(struct nl_msg *, size_t);
+
+extern struct nlmsghdr * nlmsg_put(struct nl_msg *, uint32_t, uint32_t,
+ int, int, int);
+extern struct nlmsghdr * nlmsg_hdr(struct nl_msg *);
+extern void nlmsg_get(struct nl_msg *);
+extern void nlmsg_free(struct nl_msg *);
+
+/* attribute modification */
+extern void nlmsg_set_proto(struct nl_msg *, int);
+extern int nlmsg_get_proto(struct nl_msg *);
+extern size_t nlmsg_get_max_size(struct nl_msg *);
+extern void nlmsg_set_src(struct nl_msg *, struct sockaddr_nl *);
+extern struct sockaddr_nl *nlmsg_get_src(struct nl_msg *);
+extern void nlmsg_set_dst(struct nl_msg *, struct sockaddr_nl *);
+extern struct sockaddr_nl *nlmsg_get_dst(struct nl_msg *);
+extern void nlmsg_set_creds(struct nl_msg *, struct ucred *);
+extern struct ucred * nlmsg_get_creds(struct nl_msg *);
+
+extern char * nl_nlmsgtype2str(int, char *, size_t);
+extern int nl_str2nlmsgtype(const char *);
+
+extern char * nl_nlmsg_flags2str(int, char *, size_t);
+
+extern int nl_msg_parse(struct nl_msg *,
+ void (*cb)(struct nl_object *, void *),
+ void *);
+
+extern void nl_msg_dump(struct nl_msg *, FILE *);
+
+/**
+ * @name Iterators
+ * @{
+ */
+
+/**
+ * @ingroup msg
+ * Iterate over a stream of attributes in a message
+ * @arg pos loop counter, set to current attribute
+ * @arg nlh netlink message header
+ * @arg hdrlen length of family header
+ * @arg rem initialized to len, holds bytes currently remaining in stream
+ */
+#define nlmsg_for_each_attr(pos, nlh, hdrlen, rem) \
+ nla_for_each_attr(pos, nlmsg_attrdata(nlh, hdrlen), \
+ nlmsg_attrlen(nlh, hdrlen), rem)
+
+/**
+ * Iterate over a stream of messages
+ * @arg pos loop counter, set to current message
+ * @arg head head of message stream
+ * @arg len length of message stream
+ * @arg rem initialized to len, holds bytes currently remaining in stream
+ */
+#define nlmsg_for_each_msg(pos, head, len, rem) \
+ for (pos = head, rem = len; \
+ nlmsg_ok(pos, rem); \
+ pos = nlmsg_next(pos, &(rem)))
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/netfilter/ct.h b/netlink/netfilter/ct.h
new file mode 100644
index 0000000..c4402b3
--- /dev/null
+++ b/netlink/netfilter/ct.h
@@ -0,0 +1,126 @@
+/*
+ * netlink/netfilter/ct.h Conntrack
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2007 Philip Craig <philipc@snapgear.com>
+ * Copyright (c) 2007 Secure Computing Corporation
+ */
+
+#ifndef NETLINK_CT_H_
+#define NETLINK_CT_H_
+
+#include <netlink/netlink.h>
+#include <netlink/addr.h>
+#include <netlink/cache.h>
+#include <netlink/msg.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct nfnl_ct;
+
+extern struct nl_object_ops ct_obj_ops;
+
+extern struct nfnl_ct * nfnl_ct_alloc(void);
+extern int nfnl_ct_alloc_cache(struct nl_sock *, struct nl_cache **);
+
+extern int nfnlmsg_ct_group(struct nlmsghdr *);
+extern int nfnlmsg_ct_parse(struct nlmsghdr *, struct nfnl_ct **);
+
+extern void nfnl_ct_get(struct nfnl_ct *);
+extern void nfnl_ct_put(struct nfnl_ct *);
+
+extern int nfnl_ct_dump_request(struct nl_sock *);
+
+extern int nfnl_ct_build_add_request(const struct nfnl_ct *, int,
+ struct nl_msg **);
+extern int nfnl_ct_add(struct nl_sock *, const struct nfnl_ct *, int);
+
+extern int nfnl_ct_build_delete_request(const struct nfnl_ct *, int,
+ struct nl_msg **);
+extern int nfnl_ct_delete(struct nl_sock *, const struct nfnl_ct *, int);
+
+extern int nfnl_ct_build_query_request(const struct nfnl_ct *, int,
+ struct nl_msg **);
+extern int nfnl_ct_query(struct nl_sock *, const struct nfnl_ct *, int);
+
+extern void nfnl_ct_set_family(struct nfnl_ct *, uint8_t);
+extern uint8_t nfnl_ct_get_family(const struct nfnl_ct *);
+
+extern void nfnl_ct_set_proto(struct nfnl_ct *, uint8_t);
+extern int nfnl_ct_test_proto(const struct nfnl_ct *);
+extern uint8_t nfnl_ct_get_proto(const struct nfnl_ct *);
+
+extern void nfnl_ct_set_tcp_state(struct nfnl_ct *, uint8_t);
+extern int nfnl_ct_test_tcp_state(const struct nfnl_ct *);
+extern uint8_t nfnl_ct_get_tcp_state(const struct nfnl_ct *);
+extern char * nfnl_ct_tcp_state2str(uint8_t, char *, size_t);
+extern int nfnl_ct_str2tcp_state(const char *name);
+
+extern void nfnl_ct_set_status(struct nfnl_ct *, uint32_t);
+extern void nfnl_ct_unset_status(struct nfnl_ct *, uint32_t);
+extern uint32_t nfnl_ct_get_status(const struct nfnl_ct *);
+extern char * nfnl_ct_status2str(int, char *, size_t);
+extern int nfnl_ct_str2status(const char *);
+
+extern void nfnl_ct_set_timeout(struct nfnl_ct *, uint32_t);
+extern int nfnl_ct_test_timeout(const struct nfnl_ct *);
+extern uint32_t nfnl_ct_get_timeout(const struct nfnl_ct *);
+
+extern void nfnl_ct_set_mark(struct nfnl_ct *, uint32_t);
+extern int nfnl_ct_test_mark(const struct nfnl_ct *);
+extern uint32_t nfnl_ct_get_mark(const struct nfnl_ct *);
+
+extern void nfnl_ct_set_use(struct nfnl_ct *, uint32_t);
+extern int nfnl_ct_test_use(const struct nfnl_ct *);
+extern uint32_t nfnl_ct_get_use(const struct nfnl_ct *);
+
+extern void nfnl_ct_set_id(struct nfnl_ct *, uint32_t);
+extern int nfnl_ct_test_id(const struct nfnl_ct *);
+extern uint32_t nfnl_ct_get_id(const struct nfnl_ct *);
+
+extern int nfnl_ct_set_src(struct nfnl_ct *, int, struct nl_addr *);
+extern struct nl_addr * nfnl_ct_get_src(const struct nfnl_ct *, int);
+
+extern int nfnl_ct_set_dst(struct nfnl_ct *, int, struct nl_addr *);
+extern struct nl_addr * nfnl_ct_get_dst(const struct nfnl_ct *, int);
+
+extern void nfnl_ct_set_src_port(struct nfnl_ct *, int, uint16_t);
+extern int nfnl_ct_test_src_port(const struct nfnl_ct *, int);
+extern uint16_t nfnl_ct_get_src_port(const struct nfnl_ct *, int);
+
+extern void nfnl_ct_set_dst_port(struct nfnl_ct *, int, uint16_t);
+extern int nfnl_ct_test_dst_port(const struct nfnl_ct *, int);
+extern uint16_t nfnl_ct_get_dst_port(const struct nfnl_ct *, int);
+
+extern void nfnl_ct_set_icmp_id(struct nfnl_ct *, int, uint16_t);
+extern int nfnl_ct_test_icmp_id(const struct nfnl_ct *, int);
+extern uint16_t nfnl_ct_get_icmp_id(const struct nfnl_ct *, int);
+
+extern void nfnl_ct_set_icmp_type(struct nfnl_ct *, int, uint8_t);
+extern int nfnl_ct_test_icmp_type(const struct nfnl_ct *, int);
+extern uint8_t nfnl_ct_get_icmp_type(const struct nfnl_ct *, int);
+
+extern void nfnl_ct_set_icmp_code(struct nfnl_ct *, int, uint8_t);
+extern int nfnl_ct_test_icmp_code(const struct nfnl_ct *, int);
+extern uint8_t nfnl_ct_get_icmp_code(const struct nfnl_ct *, int);
+
+extern void nfnl_ct_set_packets(struct nfnl_ct *, int, uint64_t);
+extern int nfnl_ct_test_packets(const struct nfnl_ct *, int);
+extern uint64_t nfnl_ct_get_packets(const struct nfnl_ct *,int);
+
+extern void nfnl_ct_set_bytes(struct nfnl_ct *, int, uint64_t);
+extern int nfnl_ct_test_bytes(const struct nfnl_ct *, int);
+extern uint64_t nfnl_ct_get_bytes(const struct nfnl_ct *, int);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/netlink-compat.h b/netlink/netlink-compat.h
new file mode 100644
index 0000000..17ec9fc
--- /dev/null
+++ b/netlink/netlink-compat.h
@@ -0,0 +1,50 @@
+/*
+ * netlink/netlink-compat.h Netlink Compatability
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_COMPAT_H_
+#define NETLINK_COMPAT_H_
+
+#if !defined _LINUX_SOCKET_H && !defined _BITS_SOCKADDR_H
+typedef unsigned short sa_family_t;
+#endif
+
+#ifndef IFNAMSIZ
+/** Maximum length of a interface name */
+#define IFNAMSIZ 16
+#endif
+
+/* patch 2.4.x if_arp */
+#ifndef ARPHRD_INFINIBAND
+#define ARPHRD_INFINIBAND 32
+#endif
+
+/* patch 2.4.x eth header file */
+#ifndef ETH_P_MPLS_UC
+#define ETH_P_MPLS_UC 0x8847
+#endif
+
+#ifndef ETH_P_MPLS_MC
+#define ETH_P_MPLS_MC 0x8848
+#endif
+
+#ifndef ETH_P_EDP2
+#define ETH_P_EDP2 0x88A2
+#endif
+
+#ifndef ETH_P_HDLC
+#define ETH_P_HDLC 0x0019
+#endif
+
+#ifndef AF_LLC
+#define AF_LLC 26
+#endif
+
+#endif
diff --git a/netlink/netlink-kernel.h b/netlink/netlink-kernel.h
new file mode 100644
index 0000000..a0f5535
--- /dev/null
+++ b/netlink/netlink-kernel.h
@@ -0,0 +1,196 @@
+#ifndef __LINUX_NETLINK_H
+#define __LINUX_NETLINK_H
+
+/**
+ * Netlink socket address
+ * @ingroup nl
+ */
+struct sockaddr_nl
+{
+ /** socket family (AF_NETLINK) */
+ sa_family_t nl_family;
+
+ /** Padding (unused) */
+ unsigned short nl_pad;
+
+ /** Unique process ID */
+ uint32_t nl_pid;
+
+ /** Multicast group subscriptions */
+ uint32_t nl_groups;
+};
+
+/**
+ * Netlink message header
+ * @ingroup msg
+ */
+struct nlmsghdr
+{
+ /**
+ * Length of message including header.
+ */
+ uint32_t nlmsg_len;
+
+ /**
+ * Message type (content type)
+ */
+ uint16_t nlmsg_type;
+
+ /**
+ * Message flags
+ */
+ uint16_t nlmsg_flags;
+
+ /**
+ * Sequence number
+ */
+ uint32_t nlmsg_seq;
+
+ /**
+ * Netlink PID of the proccess sending the message.
+ */
+ uint32_t nlmsg_pid;
+};
+
+/**
+ * @name Standard message flags
+ * @{
+ */
+
+/**
+ * Must be set on all request messages (typically from user space to
+ * kernel space).
+ * @ingroup msg
+ */
+#define NLM_F_REQUEST 1
+
+/**
+ * Indicates the message is part of a multipart message terminated
+ * by NLMSG_DONE.
+ */
+#define NLM_F_MULTI 2
+
+/**
+ * Request for an acknowledgment on success.
+ */
+#define NLM_F_ACK 4
+
+/**
+ * Echo this request
+ */
+#define NLM_F_ECHO 8
+
+/** @} */
+
+/**
+ * @name Additional message flags for GET requests
+ * @{
+ */
+
+/**
+ * Return the complete table instead of a single entry.
+ * @ingroup msg
+ */
+#define NLM_F_ROOT 0x100
+
+/**
+ * Return all entries matching criteria passed in message content.
+ */
+#define NLM_F_MATCH 0x200
+
+/**
+ * Return an atomic snapshot of the table being referenced. This
+ * may require special privileges because it has the potential to
+ * interrupt service in the FE for a longer time.
+ */
+#define NLM_F_ATOMIC 0x400
+
+/**
+ * Dump all entries
+ */
+#define NLM_F_DUMP (NLM_F_ROOT|NLM_F_MATCH)
+
+/** @} */
+
+/**
+ * @name Additional messsage flags for NEW requests
+ * @{
+ */
+
+/**
+ * Replace existing matching config object with this request.
+ * @ingroup msg
+ */
+#define NLM_F_REPLACE 0x100
+
+/**
+ * Don't replace the config object if it already exists.
+ */
+#define NLM_F_EXCL 0x200
+
+/**
+ * Create config object if it doesn't already exist.
+ */
+#define NLM_F_CREATE 0x400
+
+/**
+ * Add to the end of the object list.
+ */
+#define NLM_F_APPEND 0x800
+
+/** @} */
+
+/**
+ * @name Standard Message types
+ * @{
+ */
+
+/**
+ * No operation, message must be ignored
+ * @ingroup msg
+ */
+#define NLMSG_NOOP 0x1
+
+/**
+ * The message signals an error and the payload contains a nlmsgerr
+ * structure. This can be looked at as a NACK and typically it is
+ * from FEC to CPC.
+ */
+#define NLMSG_ERROR 0x2
+
+/**
+ * Message terminates a multipart message.
+ */
+#define NLMSG_DONE 0x3
+
+/**
+ * The message signals that data got lost
+ */
+#define NLMSG_OVERRUN 0x4
+
+/**
+ * Lower limit of reserved message types
+ */
+#define NLMSG_MIN_TYPE 0x10
+
+/** @} */
+
+/**
+ * Netlink error message
+ * @ingroup msg
+ */
+struct nlmsgerr
+{
+ /** Error code (errno number) */
+ int error;
+
+ /** Original netlink message causing the error */
+ struct nlmsghdr msg;
+};
+
+struct nl_pktinfo
+{
+ __u32 group;
+};
+
+#endif /* __LINUX_NETLINK_H */
diff --git a/netlink/netlink.h b/netlink/netlink.h
new file mode 100644
index 0000000..1cfe220
--- /dev/null
+++ b/netlink/netlink.h
@@ -0,0 +1,81 @@
+/*
+ * netlink/netlink.h Netlink Interface
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_NETLINK_H_
+#define NETLINK_NETLINK_H_
+
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/poll.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <netdb.h>
+#include <netlink/netlink-compat.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+#include <linux/genetlink.h>
+#include <linux/netfilter/nfnetlink.h>
+#include <netlink/version.h>
+#include <netlink/errno.h>
+#include <netlink/types.h>
+#include <netlink/handlers.h>
+#include <netlink/socket.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct ucred;
+
+extern int nl_debug;
+extern struct nl_dump_params nl_debug_dp;
+
+/* Connection Management */
+extern int nl_connect(struct nl_sock *, int);
+extern void nl_close(struct nl_sock *);
+
+/* Send */
+extern int nl_sendto(struct nl_sock *, void *, size_t);
+extern int nl_sendmsg(struct nl_sock *, struct nl_msg *,
+ struct msghdr *);
+extern int nl_send(struct nl_sock *, struct nl_msg *);
+extern int nl_send_iovec(struct nl_sock *, struct nl_msg *,
+ struct iovec *, unsigned);
+extern void nl_auto_complete(struct nl_sock *,
+ struct nl_msg *);
+extern int nl_send_auto_complete(struct nl_sock *,
+ struct nl_msg *);
+extern int nl_send_simple(struct nl_sock *, int, int,
+ void *, size_t);
+
+/* Receive */
+extern int nl_recv(struct nl_sock *,
+ struct sockaddr_nl *, unsigned char **,
+ struct ucred **);
+
+extern int nl_recvmsgs(struct nl_sock *, struct nl_cb *);
+
+extern int nl_recvmsgs_default(struct nl_sock *);
+
+extern int nl_wait_for_ack(struct nl_sock *);
+
+/* Netlink Family Translations */
+extern char * nl_nlfamily2str(int, char *, size_t);
+extern int nl_str2nlfamily(const char *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/object-api.h b/netlink/object-api.h
new file mode 100644
index 0000000..b3337f0
--- /dev/null
+++ b/netlink/object-api.h
@@ -0,0 +1,342 @@
+/*
+ * netlink/object-api.c Object API
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2007 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_OBJECT_API_H_
+#define NETLINK_OBJECT_API_H_
+
+#include <netlink/netlink.h>
+#include <netlink/utils.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @ingroup object
+ * @defgroup object_api Object API
+ * @brief
+ *
+ * @par 1) Object Definition
+ * @code
+ * // Define your object starting with the common object header
+ * struct my_obj {
+ * NLHDR_COMMON
+ * int my_data;
+ * };
+ *
+ * // Fill out the object operations structure
+ * struct nl_object_ops my_ops = {
+ * .oo_name = "my_obj",
+ * .oo_size = sizeof(struct my_obj),
+ * };
+ *
+ * // At this point the object can be allocated, you may want to provide a
+ * // separate _alloc() function to ease allocting objects of this kind.
+ * struct nl_object *obj = nl_object_alloc(&my_ops);
+ *
+ * // And release it again...
+ * nl_object_put(obj);
+ * @endcode
+ *
+ * @par 2) Allocating additional data
+ * @code
+ * // You may require to allocate additional data and store it inside
+ * // object, f.e. assuming there is a field `ptr'.
+ * struct my_obj {
+ * NLHDR_COMMON
+ * void * ptr;
+ * };
+ *
+ * // And at some point you may assign allocated data to this field:
+ * my_obj->ptr = calloc(1, ...);
+ *
+ * // In order to not introduce any memory leaks you have to release
+ * // this data again when the last reference is given back.
+ * static void my_obj_free_data(struct nl_object *obj)
+ * {
+ * struct my_obj *my_obj = nl_object_priv(obj);
+ *
+ * free(my_obj->ptr);
+ * }
+ *
+ * // Also when the object is cloned, you must ensure for your pointer
+ * // stay valid even if one of the clones is freed by either making
+ * // a clone as well or increase the reference count.
+ * static int my_obj_clone(struct nl_object *src, struct nl_object *dst)
+ * {
+ * struct my_obj *my_src = nl_object_priv(src);
+ * struct my_obj *my_dst = nl_object_priv(dst);
+ *
+ * if (src->ptr) {
+ * dst->ptr = calloc(1, ...);
+ * memcpy(dst->ptr, src->ptr, ...);
+ * }
+ * }
+ *
+ * struct nl_object_ops my_ops = {
+ * ...
+ * .oo_free_data = my_obj_free_data,
+ * .oo_clone = my_obj_clone,
+ * };
+ * @endcode
+ *
+ * @par 3) Object Dumping
+ * @code
+ * static int my_obj_dump_detailed(struct nl_object *obj,
+ * struct nl_dump_params *params)
+ * {
+ * struct my_obj *my_obj = nl_object_priv(obj);
+ *
+ * // It is absolutely essential to use nl_dump() when printing
+ * // any text to make sure the dumping parameters are respected.
+ * nl_dump(params, "Obj Integer: %d\n", my_obj->my_int);
+ *
+ * // Before we can dump the next line, make sure to prefix
+ * // this line correctly.
+ * nl_new_line(params);
+ *
+ * // You may also split a line into multiple nl_dump() calls.
+ * nl_dump(params, "String: %s ", my_obj->my_string);
+ * nl_dump(params, "String-2: %s\n", my_obj->another_string);
+ * }
+ *
+ * struct nl_object_ops my_ops = {
+ * ...
+ * .oo_dump[NL_DUMP_FULL] = my_obj_dump_detailed,
+ * };
+ * @endcode
+ *
+ * @par 4) Object Attributes
+ * @code
+ * // The concept of object attributes is optional but can ease the typical
+ * // case of objects that have optional attributes, e.g. a route may have a
+ * // nexthop assigned but it is not required to.
+ *
+ * // The first step to define your object specific bitmask listing all
+ * // attributes
+ * #define MY_ATTR_FOO (1<<0)
+ * #define MY_ATTR_BAR (1<<1)
+ *
+ * // When assigning an optional attribute to the object, make sure
+ * // to mark its availability.
+ * my_obj->foo = 123123;
+ * my_obj->ce_mask |= MY_ATTR_FOO;
+ *
+ * // At any time you may use this mask to check for the availability
+ * // of the attribute, e.g. while dumping
+ * if (my_obj->ce_mask & MY_ATTR_FOO)
+ * nl_dump(params, "foo %d ", my_obj->foo);
+ *
+ * // One of the big advantages of this concept is that it allows for
+ * // standardized comparisons which make it trivial for caches to
+ * // identify unique objects by use of unified comparison functions.
+ * // In order for it to work, your object implementation must provide
+ * // a comparison function and define a list of attributes which
+ * // combined together make an object unique.
+ *
+ * static int my_obj_compare(struct nl_object *_a, struct nl_object *_b,
+ * uint32_t attrs, int flags)
+ * {
+ * struct my_obj *a = nl_object_priv(_a):
+ * struct my_obj *b = nl_object_priv(_b):
+ * int diff = 0;
+ *
+ * // We help ourselves in defining our own DIFF macro which will
+ * // call ATTR_DIFF() on both objects which will make sure to only
+ * // compare the attributes if required.
+ * #define MY_DIFF(ATTR, EXPR) ATTR_DIFF(attrs, MY_ATTR_##ATTR, a, b, EXPR)
+ *
+ * // Call our own diff macro for each attribute to build a bitmask
+ * // representing the attributes which mismatch.
+ * diff |= MY_DIFF(FOO, a->foo != b->foo)
+ * diff |= MY_DIFF(BAR, strcmp(a->bar, b->bar))
+ *
+ * return diff;
+ * }
+ *
+ * // In order to identify identical objects with differing attributes
+ * // you must specify the attributes required to uniquely identify
+ * // your object. Make sure to not include too many attributes, this
+ * // list is used when caches look for an old version of an object.
+ * struct nl_object_ops my_ops = {
+ * ...
+ * .oo_id_attrs = MY_ATTR_FOO,
+ * .oo_compare = my_obj_compare,
+ * };
+ * @endcode
+ * @{
+ */
+
+/**
+ * Common Object Header
+ *
+ * This macro must be included as first member in every object
+ * definition to allow objects to be cached.
+ */
+#define NLHDR_COMMON \
+ int ce_refcnt; \
+ struct nl_object_ops * ce_ops; \
+ struct nl_cache * ce_cache; \
+ struct nl_list_head ce_list; \
+ int ce_msgtype; \
+ int ce_flags; \
+ uint32_t ce_mask;
+
+/**
+ * Return true if attribute is available in both objects
+ * @arg A an object
+ * @arg B another object
+ * @arg ATTR attribute bit
+ *
+ * @return True if the attribute is available, otherwise false is returned.
+ */
+#define AVAILABLE(A, B, ATTR) (((A)->ce_mask & (B)->ce_mask) & (ATTR))
+
+/**
+ * Return true if attribute is available in only one of both objects
+ * @arg A an object
+ * @arg B another object
+ * @arg ATTR attribute bit
+ *
+ * @return True if the attribute is available in only one of both objects,
+ * otherwise false is returned.
+ */
+#define AVAILABLE_MISMATCH(A, B, ATTR) (((A)->ce_mask ^ (B)->ce_mask) & (ATTR))
+
+/**
+ * Return true if attributes mismatch
+ * @arg A an object
+ * @arg B another object
+ * @arg ATTR attribute bit
+ * @arg EXPR Comparison expression
+ *
+ * This function will check if the attribute in question is available
+ * in both objects, if not this will count as a mismatch.
+ *
+ * If available the function will execute the expression which must
+ * return true if the attributes mismatch.
+ *
+ * @return True if the attribute mismatch, or false if they match.
+ */
+#define ATTR_MISMATCH(A, B, ATTR, EXPR) (AVAILABLE_MISMATCH(A, B, ATTR) || \
+ (AVAILABLE(A, B, ATTR) && (EXPR)))
+
+/**
+ * Return attribute bit if attribute does not match
+ * @arg LIST list of attributes to be compared
+ * @arg ATTR attribute bit
+ * @arg A an object
+ * @arg B another object
+ * @arg EXPR Comparison expression
+ *
+ * This function will check if the attribute in question is available
+ * in both objects, if not this will count as a mismatch.
+ *
+ * If available the function will execute the expression which must
+ * return true if the attributes mismatch.
+ *
+ * In case the attributes mismatch, the attribute is returned, otherwise
+ * 0 is returned.
+ *
+ * @code
+ * diff |= ATTR_DIFF(attrs, MY_ATTR_FOO, a, b, a->foo != b->foo);
+ * @endcode
+ */
+#define ATTR_DIFF(LIST, ATTR, A, B, EXPR) \
+({ int diff = 0; \
+ if (((LIST) & (ATTR)) && ATTR_MISMATCH(A, B, ATTR, EXPR)) \
+ diff = ATTR; \
+ diff; })
+
+/**
+ * Object Operations
+ */
+struct nl_object_ops
+{
+ /**
+ * Unique name of object type
+ *
+ * Must be in the form family/name, e.g. "route/addr"
+ */
+ char * oo_name;
+
+ /** Size of object including its header */
+ size_t oo_size;
+
+ /* List of attributes needed to uniquely identify the object */
+ uint32_t oo_id_attrs;
+
+ /**
+ * Constructor function
+ *
+ * Will be called when a new object of this type is allocated.
+ * Can be used to initialize members such as lists etc.
+ */
+ void (*oo_constructor)(struct nl_object *);
+
+ /**
+ * Destructor function
+ *
+ * Will be called when an object is freed. Must free all
+ * resources which may have been allocated as part of this
+ * object.
+ */
+ void (*oo_free_data)(struct nl_object *);
+
+ /**
+ * Cloning function
+ *
+ * Will be called when an object needs to be cloned. Please
+ * note that the generic object code will make an exact
+ * copy of the object first, therefore you only need to take
+ * care of members which require reference counting etc.
+ *
+ * May return a negative error code to abort cloning.
+ */
+ int (*oo_clone)(struct nl_object *, struct nl_object *);
+
+ /**
+ * Dumping functions
+ *
+ * Will be called when an object is dumped. The implementations
+ * have to use nl_dump(), nl_dump_line(), and nl_new_line() to
+ * dump objects.
+ *
+ * The functions must return the number of lines printed.
+ */
+ void (*oo_dump[NL_DUMP_MAX+1])(struct nl_object *,
+ struct nl_dump_params *);
+
+ /**
+ * Comparison function
+ *
+ * Will be called when two objects of the same type are
+ * compared. It takes the two objects in question, an object
+ * specific bitmask defining which attributes should be
+ * compared and flags to control the behaviour.
+ *
+ * The function must return a bitmask with the relevant bit
+ * set for each attribute that mismatches.
+ */
+ int (*oo_compare)(struct nl_object *, struct nl_object *,
+ uint32_t, int);
+
+
+ char *(*oo_attrs2str)(int, char *, size_t);
+};
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/object.h b/netlink/object.h
new file mode 100644
index 0000000..ef1ed9f
--- /dev/null
+++ b/netlink/object.h
@@ -0,0 +1,69 @@
+/*
+ * netlink/object.c Generic Cacheable Object
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_OBJECT_H_
+#define NETLINK_OBJECT_H_
+
+#include <netlink/netlink.h>
+#include <netlink/utils.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct nl_cache;
+struct nl_object;
+struct nl_object_ops;
+
+#define OBJ_CAST(ptr) ((struct nl_object *) (ptr))
+
+/* General */
+extern struct nl_object * nl_object_alloc(struct nl_object_ops *);
+extern int nl_object_alloc_name(const char *,
+ struct nl_object **);
+extern void nl_object_free(struct nl_object *);
+extern struct nl_object * nl_object_clone(struct nl_object *obj);
+extern void nl_object_get(struct nl_object *);
+extern void nl_object_put(struct nl_object *);
+extern int nl_object_shared(struct nl_object *);
+extern void nl_object_dump(struct nl_object *,
+ struct nl_dump_params *);
+extern int nl_object_identical(struct nl_object *,
+ struct nl_object *);
+extern uint32_t nl_object_diff(struct nl_object *,
+ struct nl_object *);
+extern int nl_object_match_filter(struct nl_object *,
+ struct nl_object *);
+extern char * nl_object_attrs2str(struct nl_object *,
+ uint32_t attrs, char *buf,
+ size_t);
+extern char * nl_object_attr_list(struct nl_object *,
+ char *, size_t);
+
+/* Marks */
+extern void nl_object_mark(struct nl_object *);
+extern void nl_object_unmark(struct nl_object *);
+extern int nl_object_is_marked(struct nl_object *);
+
+/* Access Functions */
+extern int nl_object_get_refcnt(struct nl_object *);
+extern struct nl_cache * nl_object_get_cache(struct nl_object *);
+static inline void * nl_object_priv(struct nl_object *obj)
+{
+ return obj;
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/route/addr.h b/netlink/route/addr.h
new file mode 100644
index 0000000..1381486
--- /dev/null
+++ b/netlink/route/addr.h
@@ -0,0 +1,91 @@
+/*
+ * netlink/route/addr.c rtnetlink addr layer
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2003-2006 Baruch Even <baruch@ev-en.org>,
+ * Mediatrix Telecom, inc. <ericb@mediatrix.com>
+ */
+
+#ifndef NETADDR_ADDR_H_
+#define NETADDR_ADDR_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/addr.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct rtnl_addr;
+
+/* General */
+extern struct rtnl_addr *rtnl_addr_alloc(void);
+extern void rtnl_addr_put(struct rtnl_addr *);
+
+extern int rtnl_addr_alloc_cache(struct nl_sock *, struct nl_cache **);
+
+extern int rtnl_addr_build_add_request(struct rtnl_addr *, int,
+ struct nl_msg **);
+extern int rtnl_addr_add(struct nl_sock *, struct rtnl_addr *, int);
+
+extern int rtnl_addr_build_delete_request(struct rtnl_addr *, int,
+ struct nl_msg **);
+extern int rtnl_addr_delete(struct nl_sock *,
+ struct rtnl_addr *, int);
+
+extern char * rtnl_addr_flags2str(int, char *, size_t);
+extern int rtnl_addr_str2flags(const char *);
+
+extern int rtnl_addr_set_label(struct rtnl_addr *, const char *);
+extern char * rtnl_addr_get_label(struct rtnl_addr *);
+
+extern void rtnl_addr_set_ifindex(struct rtnl_addr *, int);
+extern int rtnl_addr_get_ifindex(struct rtnl_addr *);
+
+extern void rtnl_addr_set_family(struct rtnl_addr *, int);
+extern int rtnl_addr_get_family(struct rtnl_addr *);
+
+extern void rtnl_addr_set_prefixlen(struct rtnl_addr *, int);
+extern int rtnl_addr_get_prefixlen(struct rtnl_addr *);
+
+extern void rtnl_addr_set_scope(struct rtnl_addr *, int);
+extern int rtnl_addr_get_scope(struct rtnl_addr *);
+
+extern void rtnl_addr_set_flags(struct rtnl_addr *, unsigned int);
+extern void rtnl_addr_unset_flags(struct rtnl_addr *, unsigned int);
+extern unsigned int rtnl_addr_get_flags(struct rtnl_addr *);
+
+extern int rtnl_addr_set_local(struct rtnl_addr *,
+ struct nl_addr *);
+extern struct nl_addr *rtnl_addr_get_local(struct rtnl_addr *);
+
+extern int rtnl_addr_set_peer(struct rtnl_addr *, struct nl_addr *);
+extern struct nl_addr *rtnl_addr_get_peer(struct rtnl_addr *);
+
+extern int rtnl_addr_set_broadcast(struct rtnl_addr *, struct nl_addr *);
+extern struct nl_addr *rtnl_addr_get_broadcast(struct rtnl_addr *);
+
+extern int rtnl_addr_set_multicast(struct rtnl_addr *, struct nl_addr *);
+extern struct nl_addr *rtnl_addr_get_multicast(struct rtnl_addr *);
+
+extern int rtnl_addr_set_anycast(struct rtnl_addr *, struct nl_addr *);
+extern struct nl_addr *rtnl_addr_get_anycast(struct rtnl_addr *);
+
+extern uint32_t rtnl_addr_get_valid_lifetime(struct rtnl_addr *);
+extern void rtnl_addr_set_valid_lifetime(struct rtnl_addr *, uint32_t);
+extern uint32_t rtnl_addr_get_preferred_lifetime(struct rtnl_addr *);
+extern void rtnl_addr_set_preferred_lifetime(struct rtnl_addr *, uint32_t);
+extern uint32_t rtnl_addr_get_create_time(struct rtnl_addr *);
+extern uint32_t rtnl_addr_get_last_update_time(struct rtnl_addr *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/route/class.h b/netlink/route/class.h
new file mode 100644
index 0000000..480095e
--- /dev/null
+++ b/netlink/route/class.h
@@ -0,0 +1,73 @@
+/*
+ * netlink/route/class.h Classes
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_CLASS_H_
+#define NETLINK_CLASS_H_
+
+#include <netlink/netlink.h>
+#include <netlink/route/tc.h>
+#include <netlink/route/qdisc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct rtnl_class;
+
+extern struct nl_object_ops class_obj_ops;
+
+extern struct rtnl_class * rtnl_class_alloc(void);
+extern void rtnl_class_put(struct rtnl_class *);
+extern int rtnl_class_alloc_cache(struct nl_sock *, int,
+ struct nl_cache **);
+extern struct rtnl_class *rtnl_class_get(struct nl_cache *, int, uint32_t);
+
+/* leaf qdisc access */
+extern struct rtnl_qdisc * rtnl_class_leaf_qdisc(struct rtnl_class *,
+ struct nl_cache *);
+
+extern int rtnl_class_build_add_request(struct rtnl_class *, int,
+ struct nl_msg **);
+extern int rtnl_class_add(struct nl_sock *, struct rtnl_class *,
+ int);
+
+extern int rtnl_class_build_delete_request(struct rtnl_class *,
+ struct nl_msg **);
+extern int rtnl_class_delete(struct nl_sock *, struct rtnl_class *);
+
+extern void rtnl_class_set_ifindex(struct rtnl_class *, int);
+extern int rtnl_class_get_ifindex(struct rtnl_class *);
+extern void rtnl_class_set_handle(struct rtnl_class *, uint32_t);
+extern uint32_t rtnl_class_get_handle(struct rtnl_class *);
+extern void rtnl_class_set_parent(struct rtnl_class *, uint32_t);
+extern uint32_t rtnl_class_get_parent(struct rtnl_class *);
+extern void rtnl_class_set_kind(struct rtnl_class *, const char *);
+extern char * rtnl_class_get_kind(struct rtnl_class *);
+extern uint64_t rtnl_class_get_stat(struct rtnl_class *,
+ enum rtnl_tc_stats_id);
+
+/* iterators */
+extern void rtnl_class_foreach_child(struct rtnl_class *,
+ struct nl_cache *,
+ void (*cb)(struct nl_object *,
+ void *),
+ void *);
+extern void rtnl_class_foreach_cls(struct rtnl_class *,
+ struct nl_cache *,
+ void (*cb)(struct nl_object *,
+ void *),
+ void *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/route/classifier.h b/netlink/route/classifier.h
new file mode 100644
index 0000000..d9c3d21
--- /dev/null
+++ b/netlink/route/classifier.h
@@ -0,0 +1,62 @@
+/*
+ * netlink/route/classifier.h Classifiers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_CLASSIFIER_H_
+#define NETLINK_CLASSIFIER_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/route/tc.h>
+#include <netlink/utils.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern struct nl_object_ops cls_obj_ops;
+
+extern struct rtnl_cls *rtnl_cls_alloc(void);
+extern void rtnl_cls_put(struct rtnl_cls *);
+
+extern int rtnl_cls_alloc_cache(struct nl_sock *, int, uint32_t,
+ struct nl_cache **);
+
+extern int rtnl_cls_build_add_request(struct rtnl_cls *, int,
+ struct nl_msg **);
+extern int rtnl_cls_add(struct nl_sock *, struct rtnl_cls *, int);
+
+extern int rtnl_cls_build_change_request(struct rtnl_cls *, int,
+ struct nl_msg **);
+extern int rtnl_cls_build_delete_request(struct rtnl_cls *, int,
+ struct nl_msg **);
+extern int rtnl_cls_delete(struct nl_sock *, struct rtnl_cls *, int);
+
+extern void rtnl_cls_set_ifindex(struct rtnl_cls *, int);
+extern int rtnl_cls_get_ifindex(struct rtnl_cls *);
+extern void rtnl_cls_set_handle(struct rtnl_cls *, uint32_t);
+extern void rtnl_cls_set_parent(struct rtnl_cls *, uint32_t);
+extern uint32_t rtnl_cls_get_parent(struct rtnl_cls *);
+extern int rtnl_cls_set_kind(struct rtnl_cls *, const char *);
+extern struct rtnl_cls_ops *rtnl_cls_get_ops(struct rtnl_cls *);
+
+extern void rtnl_cls_set_prio(struct rtnl_cls *, uint16_t);
+extern uint16_t rtnl_cls_get_prio(struct rtnl_cls *);
+
+extern void rtnl_cls_set_protocol(struct rtnl_cls *, uint16_t);
+extern uint16_t rtnl_cls_get_protocol(struct rtnl_cls *);
+
+extern void *rtnl_cls_data(struct rtnl_cls *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/route/cls/ematch.h b/netlink/route/cls/ematch.h
new file mode 100644
index 0000000..c4292bf
--- /dev/null
+++ b/netlink/route/cls/ematch.h
@@ -0,0 +1,73 @@
+/*
+ * netlink/route/cls/ematch.h Extended Matches
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_CLS_EMATCH_H_
+#define NETLINK_CLS_EMATCH_H_
+
+#include <netlink/netlink.h>
+#include <netlink/route/classifier.h>
+#include <linux/pkt_cls.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct rtnl_ematch;
+struct rtnl_ematch_tree;
+
+struct rtnl_ematch_ops
+{
+ int eo_kind;
+ const char * eo_name;
+ size_t eo_datalen;
+
+ int (*eo_parse)(struct rtnl_ematch *,
+ void *, size_t);
+ void (*eo_dump)(struct rtnl_ematch *,
+ struct nl_dump_params *);
+ struct nl_list_head eo_list;
+};
+
+extern int rtnl_ematch_register(struct rtnl_ematch_ops *);
+extern int rtnl_ematch_unregister(struct rtnl_ematch_ops *);
+
+extern struct rtnl_ematch_ops *
+ rtnl_ematch_lookup_ops(int);
+extern struct rtnl_ematch_ops *
+ rtnl_ematch_lookup_ops_name(const char *);
+
+extern struct rtnl_ematch *
+ rtnl_ematch_alloc(struct rtnl_ematch_ops *);
+extern void rtnl_ematch_add_child(struct rtnl_ematch *,
+ struct rtnl_ematch *);
+extern void rtnl_ematch_unlink(struct rtnl_ematch *);
+extern void rtnl_ematch_free(struct rtnl_ematch *);
+
+extern void * rtnl_ematch_data(struct rtnl_ematch *);
+extern void rtnl_ematch_set_flags(struct rtnl_ematch *, uint16_t);
+extern void rtnl_ematch_unset_flags(struct rtnl_ematch *, uint16_t);
+extern uint16_t rtnl_ematch_get_flags(struct rtnl_ematch *);
+
+extern struct rtnl_ematch_tree *
+ rtnl_ematch_tree_alloc(uint16_t);
+extern void rtnl_ematch_tree_free(struct rtnl_ematch_tree *);
+
+extern int rtnl_ematch_parse(struct nlattr *, struct rtnl_ematch_tree **);
+extern void rtnl_ematch_tree_add_tail(struct rtnl_ematch_tree *,
+ struct rtnl_ematch *);
+extern void rtnl_ematch_tree_dump(struct rtnl_ematch_tree *,
+ struct nl_dump_params *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/route/link.h b/netlink/route/link.h
new file mode 100644
index 0000000..4b630f7
--- /dev/null
+++ b/netlink/route/link.h
@@ -0,0 +1,145 @@
+/*
+ * netlink/route/link.h Links (Interfaces)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_LINK_H_
+#define NETLINK_LINK_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/addr.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct rtnl_link;
+
+enum rtnl_link_st {
+ RTNL_LINK_RX_PACKETS,
+ RTNL_LINK_TX_PACKETS,
+ RTNL_LINK_RX_BYTES,
+ RTNL_LINK_TX_BYTES,
+ RTNL_LINK_RX_ERRORS,
+ RTNL_LINK_TX_ERRORS,
+ RTNL_LINK_RX_DROPPED,
+ RTNL_LINK_TX_DROPPED,
+ RTNL_LINK_RX_COMPRESSED,
+ RTNL_LINK_TX_COMPRESSED,
+ RTNL_LINK_RX_FIFO_ERR,
+ RTNL_LINK_TX_FIFO_ERR,
+ RTNL_LINK_RX_LEN_ERR,
+ RTNL_LINK_RX_OVER_ERR,
+ RTNL_LINK_RX_CRC_ERR,
+ RTNL_LINK_RX_FRAME_ERR,
+ RTNL_LINK_RX_MISSED_ERR,
+ RTNL_LINK_TX_ABORT_ERR,
+ RTNL_LINK_TX_CARRIER_ERR,
+ RTNL_LINK_TX_HBEAT_ERR,
+ RTNL_LINK_TX_WIN_ERR,
+ RTNL_LINK_TX_COLLISIONS,
+ RTNL_LINK_MULTICAST,
+ __RTNL_LINK_STATS_MAX,
+};
+
+#define RTNL_LINK_STATS_MAX (__RTNL_LINK_STATS_MAX - 1)
+
+/* link object allocation/freeage */
+extern struct rtnl_link *rtnl_link_alloc(void);
+extern void rtnl_link_put(struct rtnl_link *);
+extern void rtnl_link_free(struct rtnl_link *);
+
+/* link cache management */
+extern int rtnl_link_alloc_cache(struct nl_sock *, struct nl_cache **);
+extern struct rtnl_link *rtnl_link_get(struct nl_cache *, int);
+extern struct rtnl_link *rtnl_link_get_by_name(struct nl_cache *, const char *);
+
+
+extern int rtnl_link_build_change_request(struct rtnl_link *,
+ struct rtnl_link *, int,
+ struct nl_msg **);
+extern int rtnl_link_change(struct nl_sock *, struct rtnl_link *,
+ struct rtnl_link *, int);
+
+/* Name <-> Index Translations */
+extern char * rtnl_link_i2name(struct nl_cache *, int, char *, size_t);
+extern int rtnl_link_name2i(struct nl_cache *, const char *);
+
+/* Name <-> Statistic Translations */
+extern char * rtnl_link_stat2str(int, char *, size_t);
+extern int rtnl_link_str2stat(const char *);
+
+/* Link Flags Translations */
+extern char * rtnl_link_flags2str(int, char *, size_t);
+extern int rtnl_link_str2flags(const char *);
+
+extern char * rtnl_link_operstate2str(int, char *, size_t);
+extern int rtnl_link_str2operstate(const char *);
+
+extern char * rtnl_link_mode2str(int, char *, size_t);
+extern int rtnl_link_str2mode(const char *);
+
+/* Access Functions */
+extern void rtnl_link_set_qdisc(struct rtnl_link *, const char *);
+extern char * rtnl_link_get_qdisc(struct rtnl_link *);
+
+extern void rtnl_link_set_name(struct rtnl_link *, const char *);
+extern char * rtnl_link_get_name(struct rtnl_link *);
+
+extern void rtnl_link_set_flags(struct rtnl_link *, unsigned int);
+extern void rtnl_link_unset_flags(struct rtnl_link *, unsigned int);
+extern unsigned int rtnl_link_get_flags(struct rtnl_link *);
+
+extern void rtnl_link_set_mtu(struct rtnl_link *, unsigned int);
+extern unsigned int rtnl_link_get_mtu(struct rtnl_link *);
+
+extern void rtnl_link_set_txqlen(struct rtnl_link *, unsigned int);
+extern unsigned int rtnl_link_get_txqlen(struct rtnl_link *);
+
+extern void rtnl_link_set_weight(struct rtnl_link *, unsigned int);
+extern unsigned int rtnl_link_get_weight(struct rtnl_link *);
+
+extern void rtnl_link_set_ifindex(struct rtnl_link *, int);
+extern int rtnl_link_get_ifindex(struct rtnl_link *);
+
+extern void rtnl_link_set_family(struct rtnl_link *, int);
+extern int rtnl_link_get_family(struct rtnl_link *);
+
+extern void rtnl_link_set_arptype(struct rtnl_link *, unsigned int);
+extern unsigned int rtnl_link_get_arptype(struct rtnl_link *);
+
+extern void rtnl_link_set_addr(struct rtnl_link *, struct nl_addr *);
+extern struct nl_addr *rtnl_link_get_addr(struct rtnl_link *);
+
+extern void rtnl_link_set_broadcast(struct rtnl_link *, struct nl_addr *);
+extern struct nl_addr *rtnl_link_get_broadcast(struct rtnl_link *);
+
+extern void rtnl_link_set_link(struct rtnl_link *, int);
+extern int rtnl_link_get_link(struct rtnl_link *);
+
+extern void rtnl_link_set_master(struct rtnl_link *, int);
+extern int rtnl_link_get_master(struct rtnl_link *);
+
+extern void rtnl_link_set_operstate(struct rtnl_link *, uint8_t);
+extern uint8_t rtnl_link_get_operstate(struct rtnl_link *);
+
+extern void rtnl_link_set_linkmode(struct rtnl_link *, uint8_t);
+extern uint8_t rtnl_link_get_linkmode(struct rtnl_link *);
+
+extern uint64_t rtnl_link_get_stat(struct rtnl_link *, int);
+
+extern int rtnl_link_set_info_type(struct rtnl_link *, const char *);
+extern char * rtnl_link_get_info_type(struct rtnl_link *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/route/neighbour.h b/netlink/route/neighbour.h
new file mode 100644
index 0000000..698539a
--- /dev/null
+++ b/netlink/route/neighbour.h
@@ -0,0 +1,79 @@
+/*
+ * netlink/route/neighbour.h Neighbours
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_NEIGHBOUR_H_
+#define NETLINK_NEIGHBOUR_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/addr.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct rtnl_neigh;
+
+extern struct rtnl_neigh *rtnl_neigh_alloc(void);
+extern void rtnl_neigh_put(struct rtnl_neigh *);
+
+extern int rtnl_neigh_alloc_cache(struct nl_sock *, struct nl_cache **);
+extern struct rtnl_neigh *rtnl_neigh_get(struct nl_cache *, int,
+ struct nl_addr *);
+
+extern char * rtnl_neigh_state2str(int, char *, size_t);
+extern int rtnl_neigh_str2state(const char *);
+
+extern char * rtnl_neigh_flags2str(int, char *, size_t);
+extern int rtnl_neigh_str2flag(const char *);
+
+extern int rtnl_neigh_add(struct nl_sock *, struct rtnl_neigh *, int);
+extern int rtnl_neigh_build_add_request(struct rtnl_neigh *, int,
+ struct nl_msg **);
+
+extern int rtnl_neigh_delete(struct nl_sock *, struct rtnl_neigh *, int);
+extern int rtnl_neigh_build_delete_request(struct rtnl_neigh *, int,
+ struct nl_msg **);
+
+extern void rtnl_neigh_set_state(struct rtnl_neigh *, int);
+extern int rtnl_neigh_get_state(struct rtnl_neigh *);
+extern void rtnl_neigh_unset_state(struct rtnl_neigh *,
+ int);
+
+extern void rtnl_neigh_set_flags(struct rtnl_neigh *,
+ unsigned int);
+extern void rtnl_neigh_unset_flags(struct rtnl_neigh *,
+ unsigned int);
+extern unsigned int rtnl_neigh_get_flags(struct rtnl_neigh *);
+
+extern void rtnl_neigh_set_ifindex(struct rtnl_neigh *,
+ int);
+extern int rtnl_neigh_get_ifindex(struct rtnl_neigh *);
+
+extern void rtnl_neigh_set_lladdr(struct rtnl_neigh *,
+ struct nl_addr *);
+extern struct nl_addr * rtnl_neigh_get_lladdr(struct rtnl_neigh *);
+
+extern int rtnl_neigh_set_dst(struct rtnl_neigh *,
+ struct nl_addr *);
+extern struct nl_addr * rtnl_neigh_get_dst(struct rtnl_neigh *);
+
+extern void rtnl_neigh_set_type(struct rtnl_neigh *, int);
+extern int rtnl_neigh_get_type(struct rtnl_neigh *);
+
+extern void rtnl_neigh_set_family(struct rtnl_neigh *, int);
+extern int rtnl_neigh_get_family(struct rtnl_neigh *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/route/neightbl.h b/netlink/route/neightbl.h
new file mode 100644
index 0000000..412c3e9
--- /dev/null
+++ b/netlink/route/neightbl.h
@@ -0,0 +1,65 @@
+/*
+ * netlink/route/neightbl.h Neighbour Tables
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_NEIGHTBL_H_
+#define NETLINK_NEIGHTBL_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/addr.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct rtnl_neightbl;
+
+extern struct rtnl_neightbl *rtnl_neightbl_alloc(void);
+extern void rtnl_neightbl_put(struct rtnl_neightbl *);
+extern void rtnl_neightbl_free(struct rtnl_neightbl *);
+extern int rtnl_neightbl_alloc_cache(struct nl_sock *, struct nl_cache **);
+extern struct rtnl_neightbl *rtnl_neightbl_get(struct nl_cache *,
+ const char *, int);
+extern void rtnl_neightbl_dump(struct rtnl_neightbl *, FILE *,
+ struct nl_dump_params *);
+
+extern int rtnl_neightbl_build_change_request(struct rtnl_neightbl *,
+ struct rtnl_neightbl *,
+ struct nl_msg **);
+extern int rtnl_neightbl_change(struct nl_sock *, struct rtnl_neightbl *,
+ struct rtnl_neightbl *);
+
+extern void rtnl_neightbl_set_family(struct rtnl_neightbl *, int);
+extern void rtnl_neightbl_set_gc_tresh1(struct rtnl_neightbl *, int);
+extern void rtnl_neightbl_set_gc_tresh2(struct rtnl_neightbl *, int);
+extern void rtnl_neightbl_set_gc_tresh3(struct rtnl_neightbl *, int);
+extern void rtnl_neightbl_set_name(struct rtnl_neightbl *, const char *);
+extern void rtnl_neightbl_set_dev(struct rtnl_neightbl *, int);
+extern void rtnl_neightbl_set_queue_len(struct rtnl_neightbl *, int);
+extern void rtnl_neightbl_set_proxy_queue_len(struct rtnl_neightbl *, int);
+extern void rtnl_neightbl_set_app_probes(struct rtnl_neightbl *, int);
+extern void rtnl_neightbl_set_ucast_probes(struct rtnl_neightbl *, int);
+extern void rtnl_neightbl_set_mcast_probes(struct rtnl_neightbl *, int);
+extern void rtnl_neightbl_set_base_reachable_time(struct rtnl_neightbl *,
+ uint64_t);
+extern void rtnl_neightbl_set_retrans_time(struct rtnl_neightbl *, uint64_t);
+extern void rtnl_neightbl_set_gc_stale_time(struct rtnl_neightbl *, uint64_t);
+extern void rtnl_neightbl_set_delay_probe_time(struct rtnl_neightbl *,
+ uint64_t);
+extern void rtnl_neightbl_set_anycast_delay(struct rtnl_neightbl *, uint64_t);
+extern void rtnl_neightbl_set_proxy_delay(struct rtnl_neightbl *, uint64_t);
+extern void rtnl_neightbl_set_locktime(struct rtnl_neightbl *, uint64_t);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/route/nexthop.h b/netlink/route/nexthop.h
new file mode 100644
index 0000000..2aa44dc
--- /dev/null
+++ b/netlink/route/nexthop.h
@@ -0,0 +1,65 @@
+/*
+ * netlink/route/nexthop.h Routing Nexthop
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_ROUTE_NEXTHOP_H_
+#define NETLINK_ROUTE_NEXTHOP_H_
+
+#include <netlink/netlink.h>
+#include <netlink/addr.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct rtnl_nexthop;
+
+enum {
+ NH_DUMP_FROM_ONELINE = -2,
+ NH_DUMP_FROM_DETAILS = -1,
+ NH_DUMP_FROM_ENV = 0,
+ /* > 0 reserved for nexthop index */
+};
+
+extern struct rtnl_nexthop * rtnl_route_nh_alloc(void);
+extern struct rtnl_nexthop * rtnl_route_nh_clone(struct rtnl_nexthop *);
+extern void rtnl_route_nh_free(struct rtnl_nexthop *);
+
+extern int rtnl_route_nh_compare(struct rtnl_nexthop *,
+ struct rtnl_nexthop *,
+ uint32_t, int);
+
+extern void rtnl_route_nh_dump(struct rtnl_nexthop *,
+ struct nl_dump_params *);
+
+extern void rtnl_route_nh_set_weight(struct rtnl_nexthop *, uint8_t);
+extern uint8_t rtnl_route_nh_get_weight(struct rtnl_nexthop *);
+extern void rtnl_route_nh_set_ifindex(struct rtnl_nexthop *, int);
+extern int rtnl_route_nh_get_ifindex(struct rtnl_nexthop *);
+extern void rtnl_route_nh_set_gateway(struct rtnl_nexthop *,
+ struct nl_addr *);
+extern struct nl_addr * rtnl_route_nh_get_gateway(struct rtnl_nexthop *);
+extern void rtnl_route_nh_set_flags(struct rtnl_nexthop *,
+ unsigned int);
+extern void rtnl_route_nh_unset_flags(struct rtnl_nexthop *,
+ unsigned int);
+extern unsigned int rtnl_route_nh_get_flags(struct rtnl_nexthop *);
+extern void rtnl_route_nh_set_realms(struct rtnl_nexthop *,
+ uint32_t);
+extern uint32_t rtnl_route_nh_get_realms(struct rtnl_nexthop *);
+
+extern char * rtnl_route_nh_flags2str(int, char *, size_t);
+extern int rtnl_route_nh_str2flags(const char *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/route/qdisc.h b/netlink/route/qdisc.h
new file mode 100644
index 0000000..5acd6e1
--- /dev/null
+++ b/netlink/route/qdisc.h
@@ -0,0 +1,73 @@
+/*
+ * netlink/route/qdisc.h Queueing Disciplines
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_QDISC_H_
+#define NETLINK_QDISC_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/route/tc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct rtnl_qdisc;
+
+extern struct nl_object_ops qdisc_obj_ops;
+
+extern struct rtnl_qdisc *rtnl_qdisc_alloc(void);
+extern void rtnl_qdisc_put(struct rtnl_qdisc *);
+
+extern int rtnl_qdisc_alloc_cache(struct nl_sock *, struct nl_cache **);
+extern struct rtnl_qdisc *rtnl_qdisc_get(struct nl_cache *, int, uint32_t);
+extern struct rtnl_qdisc *rtnl_qdisc_get_by_parent(struct nl_cache *,
+ int, uint32_t);
+
+extern int rtnl_qdisc_build_add_request(struct rtnl_qdisc *, int,
+ struct nl_msg **);
+extern int rtnl_qdisc_add(struct nl_sock *, struct rtnl_qdisc *, int);
+
+extern int rtnl_qdisc_build_change_request(struct rtnl_qdisc *,
+ struct rtnl_qdisc *,
+ struct nl_msg **);
+extern int rtnl_qdisc_change(struct nl_sock *, struct rtnl_qdisc *,
+ struct rtnl_qdisc *);
+
+extern int rtnl_qdisc_build_delete_request(struct rtnl_qdisc *,
+ struct nl_msg **);
+extern int rtnl_qdisc_delete(struct nl_sock *, struct rtnl_qdisc *);
+
+extern void rtnl_qdisc_set_ifindex(struct rtnl_qdisc *, int);
+extern int rtnl_qdisc_get_ifindex(struct rtnl_qdisc *);
+extern void rtnl_qdisc_set_handle(struct rtnl_qdisc *, uint32_t);
+extern uint32_t rtnl_qdisc_get_handle(struct rtnl_qdisc *);
+extern void rtnl_qdisc_set_parent(struct rtnl_qdisc *, uint32_t);
+extern uint32_t rtnl_qdisc_get_parent(struct rtnl_qdisc *);
+extern void rtnl_qdisc_set_kind(struct rtnl_qdisc *, const char *);
+extern char * rtnl_qdisc_get_kind(struct rtnl_qdisc *);
+extern uint64_t rtnl_qdisc_get_stat(struct rtnl_qdisc *, enum rtnl_tc_stats_id);
+
+extern void rtnl_qdisc_foreach_child(struct rtnl_qdisc *, struct nl_cache *,
+ void (*cb)(struct nl_object *, void *),
+ void *);
+
+extern void rtnl_qdisc_foreach_cls(struct rtnl_qdisc *, struct nl_cache *,
+ void (*cb)(struct nl_object *, void *),
+ void *);
+
+extern struct nl_msg * rtnl_qdisc_get_opts(struct rtnl_qdisc *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/route/route.h b/netlink/route/route.h
new file mode 100644
index 0000000..5729cd7
--- /dev/null
+++ b/netlink/route/route.h
@@ -0,0 +1,124 @@
+/*
+ * netlink/route/route.h Routes
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_ROUTE_H_
+#define NETLINK_ROUTE_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/addr.h>
+#include <netlink/data.h>
+#include <netlink/route/nexthop.h>
+#include <netlink/route/rtnl.h>
+#include <linux/in_route.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* flags */
+#define ROUTE_CACHE_CONTENT 1
+
+struct rtnl_route;
+
+struct rtnl_rtcacheinfo
+{
+ uint32_t rtci_clntref;
+ uint32_t rtci_last_use;
+ uint32_t rtci_expires;
+ int32_t rtci_error;
+ uint32_t rtci_used;
+ uint32_t rtci_id;
+ uint32_t rtci_ts;
+ uint32_t rtci_tsage;
+};
+
+extern struct nl_object_ops route_obj_ops;
+
+extern struct rtnl_route * rtnl_route_alloc(void);
+extern void rtnl_route_put(struct rtnl_route *);
+extern int rtnl_route_alloc_cache(struct nl_sock *, int, int,
+ struct nl_cache **);
+
+extern void rtnl_route_get(struct rtnl_route *);
+extern void rtnl_route_put(struct rtnl_route *);
+
+extern int rtnl_route_parse(struct nlmsghdr *, struct rtnl_route **);
+extern int rtnl_route_build_msg(struct nl_msg *, struct rtnl_route *);
+
+extern int rtnl_route_build_add_request(struct rtnl_route *, int,
+ struct nl_msg **);
+extern int rtnl_route_add(struct nl_sock *, struct rtnl_route *, int);
+extern int rtnl_route_build_del_request(struct rtnl_route *, int,
+ struct nl_msg **);
+extern int rtnl_route_delete(struct nl_sock *, struct rtnl_route *, int);
+
+extern void rtnl_route_set_table(struct rtnl_route *, uint32_t);
+extern uint32_t rtnl_route_get_table(struct rtnl_route *);
+extern void rtnl_route_set_scope(struct rtnl_route *, uint8_t);
+extern uint8_t rtnl_route_get_scope(struct rtnl_route *);
+extern void rtnl_route_set_tos(struct rtnl_route *, uint8_t);
+extern uint8_t rtnl_route_get_tos(struct rtnl_route *);
+extern void rtnl_route_set_protocol(struct rtnl_route *, uint8_t);
+extern uint8_t rtnl_route_get_protocol(struct rtnl_route *);
+extern void rtnl_route_set_priority(struct rtnl_route *, uint32_t);
+extern uint32_t rtnl_route_get_priority(struct rtnl_route *);
+extern int rtnl_route_set_family(struct rtnl_route *, uint8_t);
+extern uint8_t rtnl_route_get_family(struct rtnl_route *);
+extern int rtnl_route_set_type(struct rtnl_route *, uint8_t);
+extern uint8_t rtnl_route_get_type(struct rtnl_route *);
+extern void rtnl_route_set_flags(struct rtnl_route *, uint32_t);
+extern void rtnl_route_unset_flags(struct rtnl_route *, uint32_t);
+extern uint32_t rtnl_route_get_flags(struct rtnl_route *);
+extern int rtnl_route_set_metric(struct rtnl_route *, int, unsigned int);
+extern int rtnl_route_unset_metric(struct rtnl_route *, int);
+extern int rtnl_route_get_metric(struct rtnl_route *, int, uint32_t *);
+extern int rtnl_route_set_dst(struct rtnl_route *, struct nl_addr *);
+extern struct nl_addr *rtnl_route_get_dst(struct rtnl_route *);
+extern int rtnl_route_set_src(struct rtnl_route *, struct nl_addr *);
+extern struct nl_addr *rtnl_route_get_src(struct rtnl_route *);
+extern int rtnl_route_set_pref_src(struct rtnl_route *, struct nl_addr *);
+extern struct nl_addr *rtnl_route_get_pref_src(struct rtnl_route *);
+extern void rtnl_route_set_iif(struct rtnl_route *, int);
+extern int rtnl_route_get_iif(struct rtnl_route *);
+extern int rtnl_route_get_src_len(struct rtnl_route *);
+
+extern void rtnl_route_add_nexthop(struct rtnl_route *,
+ struct rtnl_nexthop *);
+extern void rtnl_route_remove_nexthop(struct rtnl_route *,
+ struct rtnl_nexthop *);
+extern struct nl_list_head *rtnl_route_get_nexthops(struct rtnl_route *);
+extern int rtnl_route_get_nnexthops(struct rtnl_route *);
+
+extern void rtnl_route_foreach_nexthop(struct rtnl_route *r,
+ void (*cb)(struct rtnl_nexthop *, void *),
+ void *arg);
+
+extern struct rtnl_nexthop * rtnl_route_nexthop_n(struct rtnl_route *r, int n);
+
+extern int rtnl_route_guess_scope(struct rtnl_route *);
+
+extern char * rtnl_route_table2str(int, char *, size_t);
+extern int rtnl_route_str2table(const char *);
+extern int rtnl_route_read_table_names(const char *);
+
+extern char * rtnl_route_proto2str(int, char *, size_t);
+extern int rtnl_route_str2proto(const char *);
+extern int rtnl_route_read_protocol_names(const char *);
+
+extern char * rtnl_route_metric2str(int, char *, size_t);
+extern int rtnl_route_str2metric(const char *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/route/rtnl.h b/netlink/route/rtnl.h
new file mode 100644
index 0000000..f551a5d
--- /dev/null
+++ b/netlink/route/rtnl.h
@@ -0,0 +1,69 @@
+/*
+ * netlink/route/rtnl.h Routing Netlink
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_RTNL_H_
+#define NETLINK_RTNL_H_
+
+#include <netlink/netlink.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @name Realms
+ * @{
+ */
+
+/**
+ * Mask specying the size of each realm part
+ * @ingroup rtnl
+ */
+#define RTNL_REALM_MASK (0xFFFF)
+
+/**
+ * Extract FROM realm from a realms field
+ */
+#define RTNL_REALM_FROM(realm) ((realm) >> 16)
+
+/**
+ * Extract TO realm from a realms field
+ */
+#define RTNL_REALM_TO(realm) ((realm) & RTNL_REALM_MASK)
+
+/**
+ * Build a realms field
+ */
+#define RTNL_MAKE_REALM(from, to) \
+ ((RTNL_REALM_TO(from) << 16) & RTNL_REALM_TO(to))
+
+/** @} */
+
+
+/* General */
+extern int nl_rtgen_request(struct nl_sock *, int, int, int);
+
+/* Routing Type Translations */
+extern char * nl_rtntype2str(int, char *, size_t);
+extern int nl_str2rtntype(const char *);
+
+/* Scope Translations */
+extern char * rtnl_scope2str(int, char *, size_t);
+extern int rtnl_str2scope(const char *);
+
+/* Realms Translations */
+extern char * rtnl_realms2str(uint32_t, char *, size_t);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/route/rule.h b/netlink/route/rule.h
new file mode 100644
index 0000000..928dc0f
--- /dev/null
+++ b/netlink/route/rule.h
@@ -0,0 +1,78 @@
+/*
+ * netlink/route/rule.h Rules
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_RULE_H_
+#define NETLINK_RULE_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/addr.h>
+#include <netlink/route/route.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct rtnl_rule;
+
+/* General */
+extern struct rtnl_rule * rtnl_rule_alloc(void);
+extern void rtnl_rule_put(struct rtnl_rule *);
+
+extern int rtnl_rule_alloc_cache(struct nl_sock *, int,
+ struct nl_cache **);
+extern void rtnl_rule_dump(struct rtnl_rule *, FILE *, struct nl_dump_params *);
+
+extern int rtnl_rule_build_add_request(struct rtnl_rule *, int,
+ struct nl_msg **);
+extern int rtnl_rule_add(struct nl_sock *, struct rtnl_rule *, int);
+extern int rtnl_rule_build_delete_request(struct rtnl_rule *, int,
+ struct nl_msg **);
+extern int rtnl_rule_delete(struct nl_sock *, struct rtnl_rule *, int);
+
+
+/* attribute modification */
+extern void rtnl_rule_set_family(struct rtnl_rule *, int);
+extern int rtnl_rule_get_family(struct rtnl_rule *);
+extern void rtnl_rule_set_prio(struct rtnl_rule *, int);
+extern int rtnl_rule_get_prio(struct rtnl_rule *);
+extern void rtnl_rule_set_mark(struct rtnl_rule *, uint64_t);
+extern uint64_t rtnl_rule_get_mark(struct rtnl_rule *);
+extern void rtnl_rule_set_table(struct rtnl_rule *, int);
+extern int rtnl_rule_get_table(struct rtnl_rule *);
+extern void rtnl_rule_set_dsfield(struct rtnl_rule *, int);
+extern int rtnl_rule_get_dsfield(struct rtnl_rule *);
+extern int rtnl_rule_set_src(struct rtnl_rule *, struct nl_addr *);
+extern struct nl_addr * rtnl_rule_get_src(struct rtnl_rule *);
+extern int rtnl_rule_set_dst(struct rtnl_rule *, struct nl_addr *);
+extern struct nl_addr * rtnl_rule_get_dst(struct rtnl_rule *);
+extern void rtnl_rule_set_src_len(struct rtnl_rule *, int);
+extern int rtnl_rule_get_src_len(struct rtnl_rule *);
+extern void rtnl_rule_set_dst_len(struct rtnl_rule *, int);
+extern int rtnl_rule_get_dst_len(struct rtnl_rule *);
+
+extern void rtnl_rule_set_action(struct rtnl_rule *, int);
+extern int rtnl_rule_get_action(struct rtnl_rule *);
+
+extern int rtnl_rule_set_iif(struct rtnl_rule *, const char *);
+extern char * rtnl_rule_get_iif(struct rtnl_rule *);
+
+extern void rtnl_rule_set_classid(struct rtnl_rule *, uint32_t);
+extern uint32_t rtnl_rule_get_classid(struct rtnl_rule *);
+
+extern void rtnl_rule_set_realms(struct rtnl_rule *, uint32_t);
+extern uint32_t rtnl_rule_get_realms(struct rtnl_rule *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/route/tc.h b/netlink/route/tc.h
new file mode 100644
index 0000000..3cb876f
--- /dev/null
+++ b/netlink/route/tc.h
@@ -0,0 +1,63 @@
+/*
+ * netlink/route/tc.h Traffic Control
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_TC_H_
+#define NETLINK_TC_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/data.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * TC statistics identifiers
+ * @ingroup tc
+ */
+enum rtnl_tc_stats_id {
+ RTNL_TC_PACKETS, /**< Packets seen */
+ RTNL_TC_BYTES, /**< Bytes seen */
+ RTNL_TC_RATE_BPS, /**< Current bits/s (rate estimator) */
+ RTNL_TC_RATE_PPS, /**< Current packet/s (rate estimator) */
+ RTNL_TC_QLEN, /**< Queue length */
+ RTNL_TC_BACKLOG, /**< Backlog length */
+ RTNL_TC_DROPS, /**< Packets dropped */
+ RTNL_TC_REQUEUES, /**< Number of requeues */
+ RTNL_TC_OVERLIMITS, /**< Number of overlimits */
+ __RTNL_TC_STATS_MAX,
+};
+
+#define RTNL_TC_STATS_MAX (__RTNL_TC_STATS_MAX - 1)
+
+extern int rtnl_tc_calc_txtime(int, int);
+extern int rtnl_tc_calc_bufsize(int, int);
+extern int rtnl_tc_calc_cell_log(int);
+
+/**
+ * Number of entries in a transmission time lookup table
+ * @ingroup tc
+ */
+#define RTNL_TC_RTABLE_SIZE 256
+
+extern int rtnl_tc_build_rate_table(uint32_t *, uint8_t, uint8_t, int, int);
+
+
+/* TC Handle Translations */
+extern char * rtnl_tc_handle2str(uint32_t, char *, size_t);
+extern int rtnl_tc_str2handle(const char *, uint32_t *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/socket.h b/netlink/socket.h
new file mode 100644
index 0000000..7e71aed
--- /dev/null
+++ b/netlink/socket.h
@@ -0,0 +1,66 @@
+/*
+ * netlink/socket.h Netlink Socket
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_SOCKET_H_
+#define NETLINK_SOCKET_H_
+
+#include <netlink/types.h>
+#include <netlink/handlers.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern struct nl_sock * nl_socket_alloc(void);
+extern struct nl_sock * nl_socket_alloc_cb(struct nl_cb *);
+extern void nl_socket_free(struct nl_sock *);
+
+extern uint32_t nl_socket_get_local_port(struct nl_sock *);
+extern void nl_socket_set_local_port(struct nl_sock *, uint32_t);
+
+extern int nl_socket_add_memberships(struct nl_sock *, int, ...);
+extern int nl_socket_add_membership(struct nl_sock *, int);
+extern int nl_socket_drop_memberships(struct nl_sock *, int, ...);
+extern int nl_socket_drop_membership(struct nl_sock *,
+ int);
+extern void nl_join_groups(struct nl_sock *, int);
+
+
+extern uint32_t nl_socket_get_peer_port(struct nl_sock *);
+extern void nl_socket_set_peer_port(struct nl_sock *,
+ uint32_t);
+
+extern struct nl_cb * nl_socket_get_cb(struct nl_sock *);
+extern void nl_socket_set_cb(struct nl_sock *,
+ struct nl_cb *);
+extern int nl_socket_modify_cb(struct nl_sock *, enum nl_cb_type,
+ enum nl_cb_kind,
+ nl_recvmsg_msg_cb_t, void *);
+
+extern int nl_socket_set_buffer_size(struct nl_sock *, int, int);
+extern int nl_socket_set_passcred(struct nl_sock *, int);
+extern int nl_socket_recv_pktinfo(struct nl_sock *, int);
+
+extern void nl_socket_disable_seq_check(struct nl_sock *);
+extern unsigned int nl_socket_use_seq(struct nl_sock *);
+extern void nl_socket_disable_auto_ack(struct nl_sock *);
+extern void nl_socket_enable_auto_ack(struct nl_sock *);
+
+extern int nl_socket_get_fd(struct nl_sock *);
+extern int nl_socket_set_nonblocking(struct nl_sock *);
+extern void nl_socket_enable_msg_peek(struct nl_sock *);
+extern void nl_socket_disable_msg_peek(struct nl_sock *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/types.h b/netlink/types.h
new file mode 100644
index 0000000..2e0b9c3
--- /dev/null
+++ b/netlink/types.h
@@ -0,0 +1,111 @@
+/*
+ * netlink/netlink-types.h Netlink Types
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef __NETLINK_TYPES_H_
+#define __NETLINK_TYPES_H_
+
+#include <stdio.h>
+
+/**
+ * Dumping types (dp_type)
+ * @ingroup utils
+ */
+enum nl_dump_type {
+ NL_DUMP_LINE, /**< Dump object briefly on one line */
+ NL_DUMP_DETAILS, /**< Dump all attributes but no statistics */
+ NL_DUMP_STATS, /**< Dump all attributes including statistics */
+ NL_DUMP_ENV, /**< Dump all attribtues as env variables */
+ __NL_DUMP_MAX,
+};
+#define NL_DUMP_MAX (__NL_DUMP_MAX - 1)
+
+/**
+ * Dumping parameters
+ * @ingroup utils
+ */
+struct nl_dump_params
+{
+ /**
+ * Specifies the type of dump that is requested.
+ */
+ enum nl_dump_type dp_type;
+
+ /**
+ * Specifies the number of whitespaces to be put in front
+ * of every new line (indentation).
+ */
+ int dp_prefix;
+
+ /**
+ * Causes the cache index to be printed for each element.
+ */
+ int dp_print_index;
+
+ /**
+ * Causes each element to be prefixed with the message type.
+ */
+ int dp_dump_msgtype;
+
+ /**
+ * A callback invoked for output
+ *
+ * Passed arguments are:
+ * - dumping parameters
+ * - string to append to the output
+ */
+ void (*dp_cb)(struct nl_dump_params *, char *);
+
+ /**
+ * A callback invoked for every new line, can be used to
+ * customize the indentation.
+ *
+ * Passed arguments are:
+ * - dumping parameters
+ * - line number starting from 0
+ */
+ void (*dp_nl_cb)(struct nl_dump_params *, int);
+
+ /**
+ * User data pointer, can be used to pass data to callbacks.
+ */
+ void *dp_data;
+
+ /**
+ * File descriptor the dumping output should go to
+ */
+ FILE * dp_fd;
+
+ /**
+ * Alternatively the output may be redirected into a buffer
+ */
+ char * dp_buf;
+
+ /**
+ * Length of the buffer dp_buf
+ */
+ size_t dp_buflen;
+
+ /**
+ * PRIVATE
+ * Set if a dump was performed prior to the actual dump handler.
+ */
+ int dp_pre_dump;
+
+ /**
+ * PRIVATE
+ * Owned by the current caller
+ */
+ int dp_ivar;
+
+ unsigned int dp_line;
+};
+
+#endif
diff --git a/netlink/utils.h b/netlink/utils.h
new file mode 100644
index 0000000..480bab6
--- /dev/null
+++ b/netlink/utils.h
@@ -0,0 +1,78 @@
+/*
+ * netlink/utils.h Utility Functions
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_UTILS_H_
+#define NETLINK_UTILS_H_
+
+#include <netlink/netlink.h>
+#include <netlink/list.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @name Probability Constants
+ * @{
+ */
+
+/**
+ * Lower probability limit
+ * @ingroup utils
+ */
+#define NL_PROB_MIN 0x0
+
+/**
+ * Upper probability limit
+ * @ingroup utils
+ */
+#define NL_PROB_MAX 0xffffffff
+
+/** @} */
+
+/* unit pretty-printing */
+extern double nl_cancel_down_bytes(unsigned long long, char **);
+extern double nl_cancel_down_bits(unsigned long long, char **);
+extern double nl_cancel_down_us(uint32_t, char **);
+
+/* generic unit translations */
+extern long nl_size2int(const char *);
+extern long nl_prob2int(const char *);
+
+/* time translations */
+extern int nl_get_hz(void);
+extern uint32_t nl_us2ticks(uint32_t);
+extern uint32_t nl_ticks2us(uint32_t);
+extern int nl_str2msec(const char *, uint64_t *);
+extern char * nl_msec2str(uint64_t, char *, size_t);
+
+/* link layer protocol translations */
+extern char * nl_llproto2str(int, char *, size_t);
+extern int nl_str2llproto(const char *);
+
+/* ethernet protocol translations */
+extern char * nl_ether_proto2str(int, char *, size_t);
+extern int nl_str2ether_proto(const char *);
+
+/* IP protocol translations */
+extern char * nl_ip_proto2str(int, char *, size_t);
+extern int nl_str2ip_proto(const char *);
+
+/* Dumping helpers */
+extern void nl_new_line(struct nl_dump_params *);
+extern void nl_dump(struct nl_dump_params *, const char *, ...);
+extern void nl_dump_line(struct nl_dump_params *, const char *, ...);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/netlink/version.h b/netlink/version.h
new file mode 100644
index 0000000..84af8f3
--- /dev/null
+++ b/netlink/version.h
@@ -0,0 +1,18 @@
+/*
+ * netlink/version.h Compile Time Versioning Information
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation version 2.1
+ * of the License.
+ *
+ * Copyright (c) 2008 Thomas Graf <tgraf@suug.ch>
+ */
+
+#ifndef NETLINK_VERSION_H_
+#define NETLINK_VERSION_H_
+
+#define LIBNL_STRING "libnl 2.0"
+#define LIBNL_VERSION "2.0"
+
+#endif